diff --git a/Documentation/devicetree/bindings/arm/apple.yaml b/Documentation/devicetree/bindings/arm/apple.yaml index 269909160867dd..7e082afdde82f4 100644 --- a/Documentation/devicetree/bindings/arm/apple.yaml +++ b/Documentation/devicetree/bindings/arm/apple.yaml @@ -360,6 +360,12 @@ properties: - const: apple,t8142 - const: apple,arm-platform + - description: Apple M5 Max SoC based platforms + items: + - const: apple,j714c # MacBook Pro (14-inch, M5 Max, 2026) + - const: apple,t6050 + - const: apple,arm-platform + - description: Apple M6 SoC based platforms items: - const: apple,j873g # Mac mini (M6) diff --git a/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml b/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml index c5fce7d78bfc62..d8938d70fc5208 100644 --- a/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml +++ b/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml @@ -40,6 +40,7 @@ properties: - apple,t6020-pmgr - apple,t6030-pmgr - apple,t6031-pmgr + - apple,t6050-pmgr - apple,t8122-pmgr - apple,t8132-pmgr - apple,t8140-pmgr diff --git a/Documentation/devicetree/bindings/arm/cpus.yaml b/Documentation/devicetree/bindings/arm/cpus.yaml index bf4142469cb09c..d3e8faf5710c19 100644 --- a/Documentation/devicetree/bindings/arm/cpus.yaml +++ b/Documentation/devicetree/bindings/arm/cpus.yaml @@ -95,6 +95,7 @@ properties: - apple,mistral - apple,monsoon - apple,sawtooth + - apple,sotra - apple,t8152-e - apple,t8152-m - apple,t8152-p diff --git a/Documentation/devicetree/bindings/cpufreq/apple,cluster-cpufreq.yaml b/Documentation/devicetree/bindings/cpufreq/apple,cluster-cpufreq.yaml index a27f4314e0387a..c7cc6f262eb699 100644 --- a/Documentation/devicetree/bindings/cpufreq/apple,cluster-cpufreq.yaml +++ b/Documentation/devicetree/bindings/cpufreq/apple,cluster-cpufreq.yaml @@ -37,6 +37,7 @@ properties: - const: apple,s5l8960x-cluster-cpufreq - const: apple,t8140-cluster-cpufreq - const: apple,t8142-cluster-cpufreq + - const: apple,t6050-cluster-cpufreq - const: apple,t8152-cluster-cpufreq - items: - const: apple,t6020-cluster-cpufreq diff --git a/Documentation/devicetree/bindings/display/simple-framebuffer.yaml b/Documentation/devicetree/bindings/display/simple-framebuffer.yaml index 45ffdebc9d86bf..1054c6f724b71f 100644 --- a/Documentation/devicetree/bindings/display/simple-framebuffer.yaml +++ b/Documentation/devicetree/bindings/display/simple-framebuffer.yaml @@ -142,6 +142,12 @@ properties: - mixer1-lcd1-hdmi - mixer1-lcd1-tve + apple,internal-panel: + type: boolean + description: + The framebuffer is the built-in panel of an Apple laptop, which the + boot loader hands over before the display coprocessor driver runs. + amlogic,pipeline: description: Pipeline used by the framebuffer on Amlogic SoCs enum: diff --git a/Documentation/devicetree/bindings/i2c/apple,i2c.yaml b/Documentation/devicetree/bindings/i2c/apple,i2c.yaml index ea4ddc838d8605..ae96a7ac908c70 100644 --- a/Documentation/devicetree/bindings/i2c/apple,i2c.yaml +++ b/Documentation/devicetree/bindings/i2c/apple,i2c.yaml @@ -26,6 +26,7 @@ properties: - apple,t6020-i2c - apple,t6030-i2c - apple,t6031-i2c + - apple,t6050-i2c - apple,t8122-i2c - apple,t8132-i2c - apple,t8140-i2c diff --git a/Documentation/devicetree/bindings/interrupt-controller/apple,aic2.yaml b/Documentation/devicetree/bindings/interrupt-controller/apple,aic2.yaml index 25f31c8fb452de..c00cba873d224c 100644 --- a/Documentation/devicetree/bindings/interrupt-controller/apple,aic2.yaml +++ b/Documentation/devicetree/bindings/interrupt-controller/apple,aic2.yaml @@ -50,6 +50,10 @@ properties: - apple,t8142-aic3 - apple,t8152-aic3 - const: apple,t8122-aic3 + - items: + - const: apple,t6050-aic3 + - const: apple,t8142-aic3 + - const: apple,t8122-aic3 - const: apple,t8122-aic3 interrupt-controller: true diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml index 44a0499ada2cbc..51a87422d65ae1 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -36,10 +36,15 @@ properties: - items: - enum: - apple,t6020-dart + - apple,t6050-dart - apple,t8122-dart - apple,t8140-dart - apple,t8142-dart - const: apple,t8110-dart + - items: + - const: apple,t6050-dart + - const: apple,t8142-dart + - const: apple,t8110-dart reg: maxItems: 1 diff --git a/Documentation/devicetree/bindings/iommu/apple,sart.yaml b/Documentation/devicetree/bindings/iommu/apple,sart.yaml index 472454c3d24d67..267bb580e998ef 100644 --- a/Documentation/devicetree/bindings/iommu/apple,sart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,sart.yaml @@ -38,6 +38,7 @@ properties: - const: apple,t6000-sart - enum: - apple,t6000-sart + - apple,t6050-sart - apple,t8015-sart - apple,t8103-sart diff --git a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml index 8d66dc77c0a54e..c9b022de25f6c5 100644 --- a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml +++ b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml @@ -35,6 +35,7 @@ properties: - apple,t8142-asc-mailbox - apple,t6000-asc-mailbox - apple,t6020-asc-mailbox + - apple,t6050-asc-mailbox - const: apple,asc-mailbox-v4 - description: diff --git a/Documentation/devicetree/bindings/mfd/apple,smc.yaml b/Documentation/devicetree/bindings/mfd/apple,smc.yaml index 31d1940f9d3dc0..0a3ab9d9473959 100644 --- a/Documentation/devicetree/bindings/mfd/apple,smc.yaml +++ b/Documentation/devicetree/bindings/mfd/apple,smc.yaml @@ -19,6 +19,7 @@ properties: - items: - enum: - apple,t6020-smc + - apple,t6050-smc - apple,t8122-smc - apple,t8140-smc - apple,t8142-smc diff --git a/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml b/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml index fc8a4afd5add47..20cb5703638572 100644 --- a/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml +++ b/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml @@ -22,6 +22,9 @@ properties: - items: - const: apple,t8140-nvme-ans2 - const: apple,t8132-nvme-ans2 + - items: + - const: apple,t6050-nvme-ans2 + - const: apple,t8140-nvme-ans2 - items: - enum: # Do not add additional SoC to this list. @@ -52,7 +55,7 @@ properties: SError, so it cannot be used to restart the co-processor there. power-domains: - # two domains for t8103, three for t6000, t6020 and t8140 + # two domains for t8103, three for t6000, t6020 and t8140, four for t6050 minItems: 2 items: - description: power domain for the NVMe controller. @@ -60,7 +63,10 @@ properties: controller to the storage modules. - description: optional power domain for the second PCIe bus connecting the NVMe controller to the storage modules (T6000, - T6020), or for the PCIe PHY of the link to the storage (T8140). + T6020), or for the PCIe PHY of the link to the storage (T8140, + T6050). + - description: power domain for the PCIe lane PHY of the link to the + storage (T6050). power-domain-names: minItems: 2 @@ -70,6 +76,7 @@ properties: - enum: - apcie1 - apcie_phy + - const: aphy_st0 mboxes: maxItems: 1 @@ -111,7 +118,9 @@ allOf: properties: compatible: contains: - const: apple,t8132-nvme-ans2 + enum: + - apple,t6050-nvme-ans2 + - apple,t8132-nvme-ans2 then: properties: reg: diff --git a/Documentation/devicetree/bindings/nvmem/apple,spmi-nvmem.yaml b/Documentation/devicetree/bindings/nvmem/apple,spmi-nvmem.yaml index 09cdd776f8d8bd..2eecc48c9b0616 100644 --- a/Documentation/devicetree/bindings/nvmem/apple,spmi-nvmem.yaml +++ b/Documentation/devicetree/bindings/nvmem/apple,spmi-nvmem.yaml @@ -18,6 +18,7 @@ properties: compatible: items: - enum: + - apple,abbey-pmic - apple,baku-pmic - apple,maverick-pmic - apple,sera-pmic diff --git a/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml b/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml index b8b4a24107cd1b..18face34bd2002 100644 --- a/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml +++ b/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml @@ -26,6 +26,9 @@ properties: - apple,t8132-pinctrl - apple,t8140-pinctrl - const: apple,t8103-pinctrl + - items: + - const: apple,t6050-pinctrl + - const: apple,t8140-pinctrl - items: # Do not add additional SoC to this list. - enum: diff --git a/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml b/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml index 7800f0f106f2cd..8d211b79538bd8 100644 --- a/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml +++ b/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml @@ -47,6 +47,7 @@ properties: - apple,t6020-pmgr-pwrstate - apple,t6030-pmgr-pwrstate - apple,t6031-pmgr-pwrstate + - apple,t6050-pmgr-pwrstate - apple,t8122-pmgr-pwrstate - apple,t8132-pmgr-pwrstate - apple,t8140-pmgr-pwrstate diff --git a/Documentation/devicetree/bindings/pwm/apple,s5l-fpwm.yaml b/Documentation/devicetree/bindings/pwm/apple,s5l-fpwm.yaml index 3b3cad92b601fa..5161591931df45 100644 --- a/Documentation/devicetree/bindings/pwm/apple,s5l-fpwm.yaml +++ b/Documentation/devicetree/bindings/pwm/apple,s5l-fpwm.yaml @@ -25,6 +25,7 @@ properties: - apple,t6020-fpwm - apple,t6030-fpwm - apple,t6031-fpwm + - apple,t6050-fpwm - const: apple,s5l-fpwm reg: diff --git a/Documentation/devicetree/bindings/soc/apple/apple,dockchannel.yaml b/Documentation/devicetree/bindings/soc/apple/apple,dockchannel.yaml index a3362df34e148b..7b715cb3a72f38 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,dockchannel.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,dockchannel.yaml @@ -25,6 +25,7 @@ properties: - apple,t6020-dockchannel - apple,t6030-dockchannel - apple,t6031-dockchannel + - apple,t6050-dockchannel - apple,t8112-dockchannel - apple,t8122-dockchannel - apple,t8140-dockchannel diff --git a/Documentation/devicetree/bindings/soc/apple/apple,rtk-helper-asc4.yaml b/Documentation/devicetree/bindings/soc/apple/apple,rtk-helper-asc4.yaml index da78694e374661..94605b2a122a40 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,rtk-helper-asc4.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,rtk-helper-asc4.yaml @@ -25,6 +25,7 @@ properties: - apple,t6020-mtp - apple,t6030-mtp - apple,t6031-mtp + - apple,t6050-mtp - apple,t8112-mtp - apple,t8122-mtp - apple,t8140-mtp diff --git a/Documentation/devicetree/bindings/spmi/apple,spmi.yaml b/Documentation/devicetree/bindings/spmi/apple,spmi.yaml index f88e21c348667b..99969dfa1ee0d8 100644 --- a/Documentation/devicetree/bindings/spmi/apple,spmi.yaml +++ b/Documentation/devicetree/bindings/spmi/apple,spmi.yaml @@ -35,6 +35,9 @@ properties: - apple,t8112-spmi - const: apple,spmi - const: apple,t8142-spmi + - items: + - const: apple,t6050-spmi + - const: apple,t8142-spmi reg: maxItems: 1 diff --git a/Documentation/devicetree/bindings/watchdog/apple,wdt.yaml b/Documentation/devicetree/bindings/watchdog/apple,wdt.yaml index 1af924157f7ca6..401ef0a17d7a26 100644 --- a/Documentation/devicetree/bindings/watchdog/apple,wdt.yaml +++ b/Documentation/devicetree/bindings/watchdog/apple,wdt.yaml @@ -20,6 +20,7 @@ properties: - apple,t6020-wdt - apple,t6030-wdt - apple,t6031-wdt + - apple,t6050-wdt - apple,t8122-wdt - apple,t8132-wdt - apple,t8140-wdt diff --git a/Documentation/driver-api/media/drivers/apple-isp-j616s.rst b/Documentation/driver-api/media/drivers/apple-isp-j616s.rst new file mode 100644 index 00000000000000..5b0ddf5fe4daf8 --- /dev/null +++ b/Documentation/driver-api/media/drivers/apple-isp-j616s.rst @@ -0,0 +1,412 @@ +.. SPDX-License-Identifier: GPL-2.0-only + +J616s ISP modes and capture protocol +================================== + +Sources and scope +----------------- + +The source reference is Ryan's m1n1 PR 20, branch ``j616s`` at +``9be380c8a5a94609fdbe62d693c7b2121478ad8f``: + +* ``proxyclient/m1n1/fw/isp/isp_sensor.py`` discovers IMX958 and queries + ``CH_CAMERA_CONFIG_GET`` for every configuration reported by ``CH_INFO_GET``. +* ``isp_capture.py:T6040PreviewConfiguration`` contains the successful + processed capture command sequence. ``isp_pixels.py`` decodes its P010 + output as video-range BT.709. +* ``docs/j616s-bringup.md`` records all 13 configuration queries, completed + 1280x720 P010 captures (including an 80-frame ring-wrap trial) and a later + single completed 1920x1080 P010 frame. Intermittent startup/streaming stalls + remain unresolved. Neither the requested AE limits nor the host capture + rate is a measured sensor FPS. + +Both processed output sizes use firmware configuration **5**, whose reported +input dimensions are 1920x2160. The branch does not establish that this input +height is an independently deliverable 2160-row colour image, nor that config +5 is the highest-resolution configuration the sensor offers. It contains no +completed colour result from another configuration. RAW trials produced +stable pixels after stop but no completed RAW report; combined RAW/YUV was +refused at the allocation limit. No sensor full-resolution claim follows. + +Linux PR 231, branch ``j616s/linux-integration-next`` at +``a4e7ee86bc5eed8ff9dab61ef9656adfe000b207``, has the corresponding +``isp-profile.[ch]`` and IPC/buffer preparation. Its T6040 profile is pinned +to **25G76** and remains gated. It is a protocol reference, not an admission +profile for the current firmware. + +This driver change builds on the working T6040 H17 implementation in Linux +PR 384, now in ``integration/aurora``. That PR reports 26.6.x firmware capture +at 1920x1080 NV12 and use of config-5 1080p/720p presets. P010 and additional +firmware-derived output modes still need capture validation on 26.6.2. +Only our source and synthetic protocol tests are included; no Apple binary, +setfile contents, calibration table or firmware image is added. + +Sensor tuning and noise reduction +--------------------------------- + +NV12 setup loads model-wide sensor tuning using ``CH_SET_FILE_LOAD`` +(0x0111). T8140/IMX558 selects ``apple/isp_1925_03XX.dat``; T6040/IMX958 +selects ``apple/isp_2224_01XX.dat``. The T6040 lens-shading fixup is applied +only to the copied firmware buffer. A missing file allows streaming with a +warning. An invalid file, interrupted read or failed firmware upload fails +stream setup instead of silently continuing. A debug message identifies a +successful upload without dumping its contents. +This confirms transport completion only: the NV12 path does not decode the +setfile reply fields, so it does not prove that every coefficient was applied. + +The NV12 command sequence already sends ``CH_CNR_START`` (0x0a2f), +``CH_MBNR_ENABLE`` (0x0a3a, use case 0, mode 1, chroma enabled), +``APPLE_CH_TEMPORAL_FILTER_START`` (0xc100), +``APPLE_CH_MOTION_HISTORY_START`` (0xc102) and +``APPLE_CH_TEMPORAL_FILTER_ENABLE`` (0xc113). The temporal-start record has +one fixed argument of 1 and another supplied by ``apple,temporal-filter`` +(default 0; J700 supplies 1). The latter's meaning is not established here; +it must not be treated as a boolean enable or an output-pool count. +Command submission alone does not establish equivalence to a host-side +motion-compensated filter or measure the firmware's resulting noise reduction. + +The P010 preview still uses its qualified minimal sequence, which skips +these explicit NR commands and setfile upload. An earlier NV12 stream may +have left tuning in the resident firmware. Compare cold-boot P010 with +NV12-to-P010 transitions when assessing image quality. + +Sensor setfiles are distinct from individual camera-module factory +calibration (iCCl). The driver has no iCCl parser, serial binding or upload +command. The installer preserves raw factory records in the local fallback +archive; this does not mean the ISP consumes them. No factory record or +vendor payload belongs in the kernel source or a distributed firmware package. + +The separate ANE video denoiser is not implemented. The board parameter facts +are auto mode 2, total-gain entry/exit thresholds 2304/1792 on J700 and +3584/2816 on J616s, an FPS threshold of 30 and a 30-frame ramp-down. The FPS +comparison direction, gain units and ANE/ISP interchange need a confirmed +interface before implementation. + +Public source audit +------------------- + +The pinned PR and its discussion were checked again for the RAW layout and +per-configuration timing. The reusable code establishes the processed path; +it does not contain a RAW Bayer packing/CFA contract or the 13 reply records: + +* ``isp_capture.py`` accepts only 1280x720 and 1920x1080 processed geometry. + Its generic pool-3 builder describes a single address, not the pixel packing, + CFA order or RAW receiver command sequence. The qualified preview uses pool 9. +* ``isp_pixels.py`` contains only an MSB-aligned P010 decoder, with no Bayer decoder. +* ``isp_sensor.py`` reads the sensor ID/count and queries an index at runtime. + It has neither saved per-index replies nor a frame-rate decoder. +* ``isp_profile.py`` and ``fixtures/isp_t6040_25g76.json`` describe boot segments, + allocation geometry and channels. The fixture has no camera-info or config replies. +* ``isp_vid.py`` and ``experiments/isp.py`` use the older fixed 720p NV12 receiver. + ``isp_cmd.py`` includes legacy sensor-0x248 examples and a temporary 3.75 FPS + AE request (0x3c0), alongside a comment describing the older 30 FPS request. + These are not IMX958 per-mode timing records. The qualified T6040 helper instead + requests 30/15 FPS AE limits; neither set supplies a measured nominal-rate table. +* ``isp_command.py`` implements ownership, command/reply and deadline handling. + ``src/isp.c`` prepares boot-time power and heap handoff, not a RAW capture client. +* ``docs/j616s-bringup.md`` lines 752-789 explicitly distinguish a stable RAW + snapshot after stop from a completed buffer report and say orchestration remains + private. Commit ``743e4e75`` adds that diagnostic RAW evidence as documentation; + it does not add a RAW receiver implementation. Lines 832-841 qualify one + completed 1080p P010 frame, with measured FPS still unqualified. + +These findings do not deny the recorded RAW snapshot. They mean a V4L2 Bayer +FOURCC, frame-completion contract and per-config rates cannot be derived from +these files without additional runtime replies or capture evidence. In particular, +the old 0x103 SIF example must not be treated as an IMX958 Bayer-format declaration. + +AOP endpoints and separate audio stream +----------------------------------------- + +The modern ``fw/aop/client.py`` map in PR 20 is 0x20 SPUApp, 0x21 wakehint, +0x22 audio, 0x23 voice trigger, 0x24 accelerometer, 0x25 gyroscope, 0x26 lid +angle, 0x27 ALS and four endpoints at 0x28-0x2b with unqualified roles. The +separate ENDPOINTS13 map assigns different roles and is not the T6040 map. + +The documented HQ audio sequence uses the advertised aop-audio service at +endpoint 0x22, EPIC version 2, checked attachment/property replies and owned +DART mappings. It first establishes LP readiness using adpx buffer property 300, +attachments lpai/pdm0/adpx, lpai pw1, lai attachment and lai/lpai runn. HQ then +attaches hpai, requests pw1, prepares stream-10 NS RX0 DMA and starts DMA before +requesting hpai pwrd. Matching reports and two full copies precede RX stop and +return through pw1 to idle. These are audio commands, not camera mode selectors. + +The qualified ISP preview helper contains no AOP command. This camera change +therefore does not replay the AOP audio stream or alter its Linux driver. The +ISP channel and command maps below describe the camera path independently. + +Mode and format selection +------------------------- + +On T6040/IMX958, probe queries every advertised configuration, bounded at 64, +using the 0x120-byte H17 ``CH_CAMERA_CONFIG_GET`` exchange. The complete list +is available through dynamic debug at probe and cached in full for +``VIDIOC_LOG_STATUS`` (``v4l2-ctl --log-status``), without sending firmware +commands. Collect this diagnostic dump before starting a stress run. It includes +input/output dimensions and the sensor clock word; that word is not FPS. + +The board's existing config-5 1920x1080 and 1280x720 presets stay first and +NV12 stays the default. Additional distinct output sizes are appended only +when the reply's 16-bit and repeated 32-bit dimensions agree, the dimensions +are nonzero, output is even and within input, and output is at most 16384 +in either dimension. The full reported output becomes the crop and output +size for its own config index. Input dimensions alone never add a mode. +Thus a larger consistent firmware output can be selected by ``S_FMT`` and +listed by ``ENUM_FRAMESIZES``; no invented full-resolution preset is added. +These consistency checks cannot establish image quality, supported FPS or +whether a configuration needs additional sensor-specific commands. + +``V4L2_PIX_FMT_P010`` is offered only for T6040/IMX958. The config-5 +1280x720 and 1920x1080 processed previews are enabled when +the runtime input geometry matches the source profile. An unspecified P010 +size selects 1280x720 first. Larger P010 modes require a consistent firmware +output reply. P010 uses two little-endian 16-bit component planes with ten useful +MSB-aligned bits, and equal 64-byte-aligned Y/UV strides. UV immediately +follows Y, as required for contiguous P010. Both NV12 and P010 use the +standard single-planar V4L2 API with one memory plane containing both +component planes. The firmware still receives two component addresses. + +At 1920x1080, stride is 3840, Y is 4147200 bytes, UV is 2073600 bytes and +``sizeimage`` is 6220800. At 1280x720, stride is 2560 and ``sizeimage`` is +2764800. The proxy's independently page-aligned plane extents were +0x3f8000/0x1fc000 at 1080p and 0x1c4000/0xe4000 at 720p; inserting those +inter-plane gaps into a V4L2 contiguous P010 buffer would misdescribe it. +Linux passes its actual contiguous extents to the rendered pool instead. + +P010 uses the proxy's eight metadata slots (0x8000 bytes each) and two +rendered slots. The queue limits userspace to two rendered buffers, matching +the pool capacity. Completion matches either both full submitted addresses +or both zero-extended low-32-bit plane addresses, plus plane count, pool 9 +and a fresh 64-bit submission tag; an old tag +cannot release a new lease. Buffer completion is published to videobuf2 +only after the firmware report ACK and doorbell have been published. +NV12 pool sizes and the T8140/Neo default formats, presets and command path +retain their existing behavior. + +The inherited ``multiplanar`` module parameter and its inconsistent queue-type +hooks are removed. All sensors use the shipped single-planar V4L2 API; the +non-contiguous NV12M alias is not advertised. No driver +module/kernel parameter, platform flag or per-platform Kconfig option selects +support. NV12 stays first and is the initial format because browsers/WebRTC +and many applications do not support P010 or simply choose the first format. +Applications can select P010 explicitly with ``VIDIOC_S_FMT``. + +Endpoints +--------- + +These are the seven shared-memory ISP channels, not AOP/RTKit endpoints. +The table records the 25G76 source fixture. The current driver negotiates +channel names, types, sources, counts and 64-bit addresses on each boot; +it does not impose the captured ring addresses or counts on 26.6.2. + +================= ==== ====== ===== ======================================= +Channel Type Source Slots Purpose +================= ==== ====== ===== ======================================= +TERMINAL 2 0 768 Firmware log reports / terminal ACKs +IO 0 1 8 Host commands and in-place replies +DEBUG 0 1 8 Discovered; no capture commands sent +BUF_H2T 0 2 64 Host metadata/output descriptor batches +BUF_T2H 1 3 64 Firmware buffer completion/return reports +SHAREDMALLOC 1 3 8 Firmware allocation/free requests +IO_T2H 1 3 8 Discovered; no capture handler installed +================= ==== ====== ===== ======================================= + +A source word selects a doorbell bit, so IO and DEBUG share bit 1; the +three reply channels share bit 3. Each channel descriptor is 0x100 bytes +with a u64 ring address at 0x50. Each slot is 0x40 bytes / eight u64 words. +Publish the payload before arg0, which transfers slot ownership. The +existing IPC parser bounds rings against the allocation, descriptor table, +boot/command storage and other rings. The threaded IRQ services allocations, +terminal messages and buffer reports while a command waits for its ACK. + +Command stream +-------------- + +IO commands have a zero/status u32 followed by the opcode u32, then the +parameters below. Sizes include that eight-byte header. ``ch`` is zero. + +================ =================================== ==== =================== +Opcode Command Size Parameters +================ =================================== ==== =================== +0x0003 CONFIG_GET 0x1c Camera channel count +0x3206 SET_DSID_CLR_MULTI_BC_REG_BASE 0x50 8 slots, range 0x2fc +0x0000 START 0x0c Proxy 0x11, Linux 0 +0x010d CH_INFO_GET 0x190 ch +0x0106 CH_CAMERA_CONFIG_GET 0x120 ch, index (all) +0x0024 FLICKER_SENSOR_SET 0x0c 0 +0x013b CH_SBS_ENABLE 0x10 ch, 1 +0x0107 CH_CAMERA_CONFIG_SELECT 0x10 ch, selected config +0x010e CH_BUFFER_RECYCLE_MODE_SET 0x10 ch, 1 (empty only) +0x010f CH_BUFFER_RECYCLE_START 0x0c ch +0x080c CH_CROP_SCL1_SET 0x1c ch, x, y, width, height +0x0b09 CH_OUTPUT_CONFIG_SCL1_SET 0x38 ch, output geometry +0x0208 CH_AE_FRAME_RATE_MAX_SET 0x10 ch, fps * 256 +0x020a CH_AE_FRAME_RATE_MIN_SET 0x10 ch, min_fps * 256 +0x0117 CH_BUFFER_POOL_CONFIG_SET (meta) 0x9c ch, pool 0, count 8 +0x0117 CH_BUFFER_POOL_CONFIG_SET (output) 0x9c ch, pool 9, count 2 +0x0125 CH_LOCAL_RAW_BUFFER_ENABLE 0x10 ch, 1 +0x0b0d CH_PREVIEW_STREAM_SET 0x10 ch, 1 +0x0138 CH_MASTER_SLAVE_SYNC_MODE_SET 0x10 ch, 0 +0x0100 CH_START 0x0c ch +0x0101 CH_STOP 0x0c ch +0x0104 CH_BUFFER_RETURN 0x0c ch +================ =================================== ==== =================== + +The DSID bases are 0x2201d4000, 0x2221d4000, 0x2241d4000, 0x2261d4000, +then four U64_MAX sentinels. Linux retains its existing boot-time PMP and +logging commands in addition to discovery; it does not replay the proxy's +boot allocations or private power orchestration. + +For config 5, crop is (0, 0, output width, output height). The output command +parameters after ch are width, height, Rec.709=1, **format=0x12**, Y stride, +UV stride, 0, 0, height, 0, width. NV12 continues to use format 0. +Metadata pool sizes/strides are 0x8000, one data block; the output pool +contains actual Y/UV sizes and strides, two data blocks, no compression. + +Before CH_START, BUF_H2T submits metadata and output buffers as a 16-byte +header (type 1, count) and 64-byte descriptors. Each descriptor contains +four u64 addresses, four u32 flags (0x40000000 for each used plane), +u32 plane count, u32 pool and u64 tag. BUF_T2H returns completion reports; +render status 0x10000000 means a completed frame. Submission status is +0x30000000 and return ACK status is 0x80000000. Requeue only a returned lease. +CH_STOP and CH_BUFFER_RETURN retire the stream; resident firmware remains +running for the existing reopen path. + +The proxy used AE max/min 7680/3840 (30/15 fps). Linux retains its V4L2 rate +and exposure-priority controls: the default holds 30/30, and enabling +``exposure_auto_priority`` allows 30/15. These are requested limits, not FPS +measurements. P010 follows the minimal proxy sequence without adding +setfile-load, CNR, MBNR, SIF-format or temporal-filter commands; NV12 keeps +its existing calibrated path. A previously loaded setfile may still be +resident when switching streams. + +26.6.2 comparison +----------------- + +The 25G76 firmware UUID differs from the 26.6.2 image. Matching struct sizes +is source-level ABI evidence, not a new live qualification of P010. + +* Boot block: both use 0x290 bytes, IPC address at 0x08, shared base/size at + 0x10/0x18, extra heap at 0x20/0x28, platform at 0x30, queue offset+1 at + 0x50, 0x40 at 0x68, camera scheme at 0xd0 and the no-optical-card flag + at 0x120. The current H17 path checks descriptor flag bit 1. +* Memory: 25G76 pinned TEXT/DATA sizes 0xca8000/0x1344000, remap 1<<40, + shared base 0x1fec000, and a 256 MiB shared aperture. Linux uses the + bootloader's current TEXT/DATA/main-memory reservations, backs the missing + main-memory tail, and retains T6040's **0xde600000** shared-size descriptor. + No pinned segment size, heap request, IOVA or firmware hash is ported. +* IPC: 0x100-byte descriptors, 0x40-byte slots, 64-bit addresses and the + seven names agree. Counts and addresses remain negotiated, with the + existing overlap checks retained. The driver uses its three-DART IOMMU + domain and bootloader address-filter setup, not proxy DART table writes. +* Commands: DSID's 0x50-byte eight-slot layout, + CH_INFO_GET's 0x190-byte record, scaler-1 crop/output, 0x9c-byte pools, + local RAW, preview, sync and channel start/stop layouts agree with the + current H17 builders. START is an important parameter difference: the + proxy sends 0x11, while the working Linux H17 boot path sends 0. Linux + retains its current boot command; issuing START a second time after + selecting P010 would violate the proxy's guarded startup lifecycle. The new config query explicitly exchanges 0x120, + rather than the unused legacy 0xdc current-config helper. Header/channel/ + index checks and duplicated geometry checks guard decoding. The H17 + appended bytes remain uninterpreted. +* Metadata: CH_INFO_GET reports 0x4d00 on both paths. The proxy rounds its + metadata backing/pool to 0x8000; P010 does the same even on a 4 KiB host. + NV12 retains the current driver's 0x4d00 pool and 16-buffer capacity. + Neither path configures a T6040 capture-metadata pool or capture watchdog. +* Startup: Linux retains its once-per-boot resident-firmware admission, + current reset-vector check and H17 handshake; the 25G76 SHA/UUID admission + and recovery model from PR 231 are not substituted. Linux's command + timeout/IRQ service remain in use; the proxy's 30-second inactivity / + 40-second wall startup budget is not copied. + +Validation on hardware must record the current config list first, then +exercise both P010 presets, requeue, stop/reopen and a longer run. If a larger +firmware output appears, test its format and command requirements separately. +Do not label input dimensions, a successful query, or a requested rate as a +completed full-resolution stream or measured FPS. + +Open qualification and performance checks +----------------------------------------- + +``tools/testing/selftests/media/apple-isp-stress.c`` exercises long runs, +repeated start/stop and format/size switches through MMAP. It logs completed +frames, delivered FPS, maximum inter-frame gap, sequence gaps and buffer errors. +Use the established nominal rate as its explicit rate argument. A driver-generated +sequence is not a firmware frame counter, so timing and sequence checks alone +cannot prove the sensor dropped no frames internally. + +The P010 path requeues even the last returned lease into an otherwise empty +queue, publishes completion ACKs before releasing output or metadata leases, +acquires message validity before reading payload and bounds each IRQ ring drain +to one ring traversal so terminal/allocation traffic cannot starve completions. +Command replies must match the requested reply length, zero status and original +header. A timeout or malformed ACK latches failure; no late ACK can authorize +another command. The existing forced coprocessor stop runs before uncertain +leases are released. Resident firmware then needs a reboot before another capture. +These corrections address source-visible stalls/races. They are not evidence +that the intermittent stalls observed by the USB proxy have been reproduced +or cured on the current firmware. + +No verified IMX958 RAW Bayer packing/order, RAW completion path or nominal FPS +for every configuration is present in the public source. The recorded RAW trial +reads stable memory after stop but receives no completed RAW report. A Bayer +FOURCC cannot be chosen from that evidence. The RAW format and an exhaustive +per-config FPS table remain open pending the original capture evidence and +runtime command replies; neither is inferred from the P010 output or input height. +The 30/15 values in the preview are AE requests, not per-mode nominal measurements. + +The T6040 device tree's current fixed TEXT/DATA reservations should eventually +come from a bootloader handoff describing the loaded image and mapping lifetimes. +They are firmware-build-specific. This change does not implement that handoff +or replace those reservations with 25G76 addresses. + +Capture size enumeration +------------------------ + +The shared driver preserves the order of its device-tree presets and any +validated firmware output modes. It then adds common video-call sizes that +fit within those presets' processed crop extents. The added preset retains +its source firmware configuration and pixel-format eligibility. Crops are +centred on even coordinates, have the exact output aspect ratio and never +require upscaling. Sensor input dimensions alone are not a processed output +capability: input rows can contain stacked exposures. + +The common sizes include 640x480, 1280x720, 1920x1080, 1080x1920, +1760x1328, 1328x1760, 1552x1552, 1280x960 and 960x1280. A sensor that +cannot provide the larger square also gets the largest even square that +fits its established crops. Existing sizes are not duplicated. This is a +shared output policy, not a list indexed by board or sensor model. + +Neither the crop nor output-configuration command reports scaler limits +or rotation support. The driver does not infer a larger processed image +from raw input dimensions, rotate a portrait image into a landscape one, +or advertise a size that requires enlargement. Consequently, an exact +macOS size may remain unavailable even though a smaller size with the +same aspect ratio can be offered. + +Read-only inspection on the running kernel:: + + v4l2-ctl -d /dev/video0 --list-formats-ext + v4l2-ctl -d /dev/video0 --log-status + dmesg | grep -A20 'sensor config' + +The status ioctl prints already cached firmware configuration replies; +it does not start capture or send additional firmware queries. The cache +is currently populated only on the existing supported P010 discovery path. +A missing cache is not evidence that the sensor has no other modes. + +After booting a test kernel, enumerate again and qualify each added size +that is actually offered. For example, for 640x480 NV12:: + + v4l2-ctl -d /dev/video0 \ + --set-fmt-video=width=640,height=480,pixelformat=NV12 \ + --get-fmt-video --stream-mmap=4 --stream-count=30 --stream-to=/dev/null + gst-launch-1.0 -v v4l2src device=/dev/video0 num-buffers=30 ! \ + video/x-raw,format=NV12,width=640,height=480,framerate=30/1 ! \ + fakesink sync=false + +Repeat with each added width and height and, when offered, P010. Check +that the negotiated dimensions equal the requested dimensions: S_FMT may +otherwise choose a nearby preset. Confirm 30 completed frames, correct +aspect ratio and chroma, and no new ISP or DART errors. Enumeration and unit tests do not establish successful capture at a +new size; capture qualification must be performed separately. diff --git a/Documentation/driver-api/media/drivers/index.rst b/Documentation/driver-api/media/drivers/index.rst index 7f6f3dcd5c90c1..f1ead3c9e389fd 100644 --- a/Documentation/driver-api/media/drivers/index.rst +++ b/Documentation/driver-api/media/drivers/index.rst @@ -12,6 +12,7 @@ Video4Linux (V4L) drivers .. toctree:: :maxdepth: 5 + apple-isp-j616s bttv-devel cx2341x-devel cx88-devel diff --git a/arch/arm64/boot/dts/apple/Makefile b/arch/arm64/boot/dts/apple/Makefile index d15eeeb9ece3f0..b59ae4f6a6c475 100644 --- a/arch/arm64/boot/dts/apple/Makefile +++ b/arch/arm64/boot/dts/apple/Makefile @@ -94,6 +94,7 @@ dtb-$(CONFIG_ARCH_APPLE) += t6031-j516c.dtb dtb-$(CONFIG_ARCH_APPLE) += t6032-j575d.dtb dtb-$(CONFIG_ARCH_APPLE) += t6034-j514m.dtb dtb-$(CONFIG_ARCH_APPLE) += t6034-j516m.dtb +dtb-$(CONFIG_ARCH_APPLE) += t6050-j714c.dtb dtb-$(CONFIG_ARCH_APPLE) += t8112-j413.dtb dtb-$(CONFIG_ARCH_APPLE) += t8112-j415.dtb dtb-$(CONFIG_ARCH_APPLE) += t8112-j473.dtb diff --git a/arch/arm64/boot/dts/apple/t6050-base.dtsi b/arch/arm64/boot/dts/apple/t6050-base.dtsi new file mode 100644 index 00000000000000..bbb02557345c64 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6050-base.dtsi @@ -0,0 +1,575 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Nodes common for T6050 family SoCs (M5 Max) + * + * Copyright The Asahi Linux Contributors + */ + +/ { + #address-cells = <2>; + #size-cells = <2>; + + clk_200m: clock-200m { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <200000000>; + clock-output-names = "clk_200m"; + }; + + clkref: clock-ref { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <24000000>; + clock-output-names = "clkref"; + }; + + // This is a fabulated representation of the input clock + // to NCO since we don't know the true clock tree. + nco_clkref: clock-ref-nco { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-output-names = "nco_ref"; + }; + + cpus { + // cpu reg is the MPIDR affinity. On T6050 the boot core reads + // MPIDR_EL1 0x80040000: Aff2 is 4, cluster in Aff1, core in Aff0. + // Clusters 1 and 2 follow that pattern; their cores do not start today. + #address-cells = <2>; + #size-cells = <0>; + + cpu-map { + cluster0 { + core0 { cpu = <&cpu_m00>; }; + core1 { cpu = <&cpu_m01>; }; + core2 { cpu = <&cpu_m02>; }; + core3 { cpu = <&cpu_m03>; }; + core4 { cpu = <&cpu_m04>; }; + core5 { cpu = <&cpu_m05>; }; + }; + + cluster1 { + core0 { cpu = <&cpu_m10>; }; + core1 { cpu = <&cpu_m11>; }; + core2 { cpu = <&cpu_m12>; }; + core3 { cpu = <&cpu_m13>; }; + core4 { cpu = <&cpu_m14>; }; + core5 { cpu = <&cpu_m15>; }; + }; + + cluster2 { + core0 { cpu = <&cpu_p00>; }; + core1 { cpu = <&cpu_p01>; }; + core2 { cpu = <&cpu_p02>; }; + core3 { cpu = <&cpu_p03>; }; + core4 { cpu = <&cpu_p04>; }; + core5 { cpu = <&cpu_p05>; }; + }; + }; + + // T6050 (J714c ADT): 18 CPUs, three 6-core clusters. Clusters 0 + // and 1 are cluster-type "M", cluster 2 is cluster-type "P". + // reg encodes cluster << 8 | core. MIDR part 0x68 ("Sotra C" + // family). + cpu_m00: cpu@0 { + compatible = "apple,sotra"; + reg = <0x0 0x40000>; + cpu-release-addr = <0 0>; /* to be filled by loader */ + device_type = "cpu"; + enable-method = "spin-table"; + next-level-cache = <&l2_cache_0>; + operating-points-v2 = <&mcluster0_opp>; + performance-domains = <&cpufreq_m0>; + }; + + cpu_m01: cpu@1 { + compatible = "apple,sotra"; + reg = <0x0 0x40001>; + cpu-release-addr = <0 0>; /* to be filled by loader */ + device_type = "cpu"; + enable-method = "spin-table"; + next-level-cache = <&l2_cache_0>; + operating-points-v2 = <&mcluster0_opp>; + performance-domains = <&cpufreq_m0>; + }; + + cpu_m02: cpu@2 { + compatible = "apple,sotra"; + reg = <0x0 0x40002>; + cpu-release-addr = <0 0>; /* to be filled by loader */ + device_type = "cpu"; + enable-method = "spin-table"; + next-level-cache = <&l2_cache_0>; + operating-points-v2 = <&mcluster0_opp>; + performance-domains = <&cpufreq_m0>; + }; + + cpu_m03: cpu@3 { + compatible = "apple,sotra"; + reg = <0x0 0x40003>; + cpu-release-addr = <0 0>; /* to be filled by loader */ + device_type = "cpu"; + enable-method = "spin-table"; + next-level-cache = <&l2_cache_0>; + operating-points-v2 = <&mcluster0_opp>; + performance-domains = <&cpufreq_m0>; + }; + + cpu_m04: cpu@4 { + compatible = "apple,sotra"; + reg = <0x0 0x40004>; + cpu-release-addr = <0 0>; /* to be filled by loader */ + device_type = "cpu"; + enable-method = "spin-table"; + next-level-cache = <&l2_cache_0>; + operating-points-v2 = <&mcluster0_opp>; + performance-domains = <&cpufreq_m0>; + }; + + cpu_m05: cpu@5 { + compatible = "apple,sotra"; + reg = <0x0 0x40005>; + cpu-release-addr = <0 0>; /* to be filled by loader */ + device_type = "cpu"; + enable-method = "spin-table"; + next-level-cache = <&l2_cache_0>; + operating-points-v2 = <&mcluster0_opp>; + performance-domains = <&cpufreq_m0>; + }; + + cpu_m10: cpu@100 { + compatible = "apple,sotra"; + reg = <0x0 0x40100>; + cpu-release-addr = <0 0>; /* to be filled by loader */ + device_type = "cpu"; + enable-method = "spin-table"; + next-level-cache = <&l2_cache_1>; + operating-points-v2 = <&mcluster1_opp>; + performance-domains = <&cpufreq_m1>; + }; + + cpu_m11: cpu@101 { + compatible = "apple,sotra"; + reg = <0x0 0x40101>; + cpu-release-addr = <0 0>; /* to be filled by loader */ + device_type = "cpu"; + enable-method = "spin-table"; + next-level-cache = <&l2_cache_1>; + operating-points-v2 = <&mcluster1_opp>; + performance-domains = <&cpufreq_m1>; + }; + + cpu_m12: cpu@102 { + compatible = "apple,sotra"; + reg = <0x0 0x40102>; + cpu-release-addr = <0 0>; /* to be filled by loader */ + device_type = "cpu"; + enable-method = "spin-table"; + next-level-cache = <&l2_cache_1>; + operating-points-v2 = <&mcluster1_opp>; + performance-domains = <&cpufreq_m1>; + }; + + cpu_m13: cpu@103 { + compatible = "apple,sotra"; + reg = <0x0 0x40103>; + cpu-release-addr = <0 0>; /* to be filled by loader */ + device_type = "cpu"; + enable-method = "spin-table"; + next-level-cache = <&l2_cache_1>; + operating-points-v2 = <&mcluster1_opp>; + performance-domains = <&cpufreq_m1>; + }; + + cpu_m14: cpu@104 { + compatible = "apple,sotra"; + reg = <0x0 0x40104>; + cpu-release-addr = <0 0>; /* to be filled by loader */ + device_type = "cpu"; + enable-method = "spin-table"; + next-level-cache = <&l2_cache_1>; + operating-points-v2 = <&mcluster1_opp>; + performance-domains = <&cpufreq_m1>; + }; + + cpu_m15: cpu@105 { + compatible = "apple,sotra"; + reg = <0x0 0x40105>; + cpu-release-addr = <0 0>; /* to be filled by loader */ + device_type = "cpu"; + enable-method = "spin-table"; + next-level-cache = <&l2_cache_1>; + operating-points-v2 = <&mcluster1_opp>; + performance-domains = <&cpufreq_m1>; + }; + + cpu_p00: cpu@200 { + compatible = "apple,sotra"; + reg = <0x0 0x10200>; + cpu-release-addr = <0 0>; /* to be filled by loader */ + device_type = "cpu"; + enable-method = "spin-table"; + next-level-cache = <&l2_cache_2>; + operating-points-v2 = <&pcluster0_opp>; + performance-domains = <&cpufreq_p0>; + }; + + cpu_p01: cpu@201 { + compatible = "apple,sotra"; + reg = <0x0 0x10201>; + cpu-release-addr = <0 0>; /* to be filled by loader */ + device_type = "cpu"; + enable-method = "spin-table"; + next-level-cache = <&l2_cache_2>; + operating-points-v2 = <&pcluster0_opp>; + performance-domains = <&cpufreq_p0>; + }; + + cpu_p02: cpu@202 { + compatible = "apple,sotra"; + reg = <0x0 0x10202>; + cpu-release-addr = <0 0>; /* to be filled by loader */ + device_type = "cpu"; + enable-method = "spin-table"; + next-level-cache = <&l2_cache_2>; + operating-points-v2 = <&pcluster0_opp>; + performance-domains = <&cpufreq_p0>; + }; + + cpu_p03: cpu@203 { + compatible = "apple,sotra"; + reg = <0x0 0x10203>; + cpu-release-addr = <0 0>; /* to be filled by loader */ + device_type = "cpu"; + enable-method = "spin-table"; + next-level-cache = <&l2_cache_2>; + operating-points-v2 = <&pcluster0_opp>; + performance-domains = <&cpufreq_p0>; + }; + + cpu_p04: cpu@204 { + compatible = "apple,sotra"; + reg = <0x0 0x10204>; + cpu-release-addr = <0 0>; /* to be filled by loader */ + device_type = "cpu"; + enable-method = "spin-table"; + next-level-cache = <&l2_cache_2>; + operating-points-v2 = <&pcluster0_opp>; + performance-domains = <&cpufreq_p0>; + }; + + cpu_p05: cpu@205 { + compatible = "apple,sotra"; + reg = <0x0 0x10205>; + cpu-release-addr = <0 0>; /* to be filled by loader */ + device_type = "cpu"; + enable-method = "spin-table"; + next-level-cache = <&l2_cache_2>; + operating-points-v2 = <&pcluster0_opp>; + performance-domains = <&cpufreq_p0>; + }; + + l2_cache_0: l2-cache-0 { + compatible = "cache"; + cache-level = <2>; + cache-unified; + }; + + l2_cache_1: l2-cache-1 { + compatible = "cache"; + cache-level = <2>; + cache-unified; + }; + + l2_cache_2: l2-cache-2 { + compatible = "cache"; + cache-level = <2>; + cache-unified; + }; + }; + + // Cluster P-states from the ADT: cluster 0 (M) voltage-states22-sram, + // cluster 1 (M) voltage-states23-sram, cluster 2 (P) + // voltage-states5-sram. The frequency in kHz per hardware P-state; + // opp-level is that P-state. No clock-latency-ns, not measured. + mcluster0_opp: opp-table-0 { + compatible = "operating-points-v2"; + opp-shared; + + opp01 { + opp-hz = /bits/ 64 <1344000000>; + opp-level = <1>; + }; + + opp02 { + opp-hz = /bits/ 64 <1644000000>; + opp-level = <2>; + }; + + opp03 { + opp-hz = /bits/ 64 <1992000000>; + opp-level = <3>; + }; + + opp04 { + opp-hz = /bits/ 64 <2304000000>; + opp-level = <4>; + }; + + opp05 { + opp-hz = /bits/ 64 <2652000000>; + opp-level = <5>; + }; + + opp06 { + opp-hz = /bits/ 64 <2964000000>; + opp-level = <6>; + }; + + opp07 { + opp-hz = /bits/ 64 <3240000000>; + opp-level = <7>; + }; + + opp08 { + opp-hz = /bits/ 64 <3504000000>; + opp-level = <8>; + }; + + opp09 { + opp-hz = /bits/ 64 <3696000000>; + opp-level = <9>; + }; + + opp10 { + opp-hz = /bits/ 64 <3876000000>; + opp-level = <10>; + }; + + opp11 { + opp-hz = /bits/ 64 <4044000000>; + opp-level = <11>; + }; + + opp12 { + opp-hz = /bits/ 64 <4176000000>; + opp-level = <12>; + }; + + opp13 { + opp-hz = /bits/ 64 <4284000000>; + opp-level = <13>; + }; + + opp14 { + opp-hz = /bits/ 64 <4308000000>; + opp-level = <14>; + }; + + opp15 { + opp-hz = /bits/ 64 <4380000000>; + opp-level = <15>; + }; + }; + + mcluster1_opp: opp-table-1 { + compatible = "operating-points-v2"; + opp-shared; + + opp01 { + opp-hz = /bits/ 64 <1344000000>; + opp-level = <1>; + }; + + opp02 { + opp-hz = /bits/ 64 <1644000000>; + opp-level = <2>; + }; + + opp03 { + opp-hz = /bits/ 64 <1992000000>; + opp-level = <3>; + }; + + opp04 { + opp-hz = /bits/ 64 <2304000000>; + opp-level = <4>; + }; + + opp05 { + opp-hz = /bits/ 64 <2652000000>; + opp-level = <5>; + }; + + opp06 { + opp-hz = /bits/ 64 <2964000000>; + opp-level = <6>; + }; + + opp07 { + opp-hz = /bits/ 64 <3240000000>; + opp-level = <7>; + }; + + opp08 { + opp-hz = /bits/ 64 <3504000000>; + opp-level = <8>; + }; + + opp09 { + opp-hz = /bits/ 64 <3696000000>; + opp-level = <9>; + }; + + opp10 { + opp-hz = /bits/ 64 <3876000000>; + opp-level = <10>; + }; + + opp11 { + opp-hz = /bits/ 64 <4044000000>; + opp-level = <11>; + }; + + opp12 { + opp-hz = /bits/ 64 <4176000000>; + opp-level = <12>; + }; + + opp13 { + opp-hz = /bits/ 64 <4284000000>; + opp-level = <13>; + }; + + opp14 { + opp-hz = /bits/ 64 <4308000000>; + opp-level = <14>; + }; + + opp15 { + opp-hz = /bits/ 64 <4380000000>; + opp-level = <15>; + }; + }; + + pcluster0_opp: opp-table-2 { + compatible = "operating-points-v2"; + opp-shared; + + opp01 { + opp-hz = /bits/ 64 <1308000000>; + opp-level = <1>; + }; + + opp02 { + opp-hz = /bits/ 64 <1620000000>; + opp-level = <2>; + }; + + opp03 { + opp-hz = /bits/ 64 <1980000000>; + opp-level = <3>; + }; + + opp04 { + opp-hz = /bits/ 64 <2292000000>; + opp-level = <4>; + }; + + opp05 { + opp-hz = /bits/ 64 <2580000000>; + opp-level = <5>; + }; + + opp06 { + opp-hz = /bits/ 64 <2880000000>; + opp-level = <6>; + }; + + opp07 { + opp-hz = /bits/ 64 <3180000000>; + opp-level = <7>; + }; + + opp08 { + opp-hz = /bits/ 64 <3432000000>; + opp-level = <8>; + }; + + opp09 { + opp-hz = /bits/ 64 <3648000000>; + opp-level = <9>; + }; + + opp10 { + opp-hz = /bits/ 64 <3828000000>; + opp-level = <10>; + }; + + opp11 { + opp-hz = /bits/ 64 <3984000000>; + opp-level = <11>; + }; + + opp12 { + opp-hz = /bits/ 64 <4104000000>; + opp-level = <12>; + }; + + opp13 { + opp-hz = /bits/ 64 <4188000000>; + opp-level = <13>; + }; + + opp14 { + opp-hz = /bits/ 64 <4236000000>; + opp-level = <14>; + }; + + opp15 { + opp-hz = /bits/ 64 <4284000000>; + opp-level = <15>; + }; + + opp16 { + opp-hz = /bits/ 64 <4308000000>; + opp-level = <16>; + }; + + opp17 { + opp-hz = /bits/ 64 <4332000000>; + opp-level = <17>; + }; + + opp18 { + opp-hz = /bits/ 64 <4428000000>; + opp-level = <18>; + }; + + opp19 { + opp-hz = /bits/ 64 <4512000000>; + opp-level = <19>; + }; + + opp20 { + opp-hz = /bits/ 64 <4608000000>; + opp-level = <20>; + }; + }; + + reserved-memory { + ranges; + #address-cells = <2>; + #size-cells = <2>; + }; + + timer { + compatible = "arm,armv8-timer"; + interrupt-parent = <&aic>; + interrupts = , + , + , + ; + interrupt-names = "phys", "virt", "hyp-phys", "hyp-virt"; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t6050-die0.dtsi b/arch/arm64/boot/dts/apple/t6050-die0.dtsi new file mode 100644 index 00000000000000..efb7e987e3f7b7 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6050-die0.dtsi @@ -0,0 +1,258 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Devices on the Apple T6050 "M5 Max" SoC (single die) + * + * Register windows from the J714c Apple Device Tree. + * The six pmgr register blocks are declared here; their power domains + * live in t6050-pmgr.dtsi. + * + * Copyright The Asahi Linux Contributors + */ + +&soc { + // J714c also has a dockchannel UART (aapl,dock-channels, + // 0x88e28000/0x10004 + 0x88e0c000/0x18, AIC IRQ 360). The in-tree + // apple,dockchannel-uart driver expects three named windows + // (data/config/irq) and its observability from this laptop without + // a debug cable is unverified, so it is left out of the first boot. + // Add it with the window layout resolved when it is needed. + + cpufreq_m0: cpufreq@210e20000 { + compatible = "apple,t6050-cluster-cpufreq"; + reg = <0x2 0x10e20000 0x0 0x1000>; + #performance-domain-cells = <0>; + }; + + cpufreq_m1: cpufreq@211e20000 { + compatible = "apple,t6050-cluster-cpufreq"; + reg = <0x2 0x11e20000 0x0 0x1000>; + #performance-domain-cells = <0>; + }; + + cpufreq_p0: cpufreq@212e20000 { + compatible = "apple,t6050-cluster-cpufreq"; + reg = <0x2 0x12e20000 0x0 0x1000>; + #performance-domain-cells = <0>; + }; + + aic: interrupt-controller@280400000 { + compatible = "apple,t6050-aic3", "apple,t8142-aic3", "apple,t8122-aic3"; + reg = <0x2 0x80400000 0x0 0x1cc000>, + <0x2 0x80440000 0x0 0x4000>; + reg-names = "core", "event"; + #interrupt-cells = <3>; + interrupt-controller; + }; + + pmgr: pmgr0: power-management@280600000 { + compatible = "apple,t6050-pmgr", "apple,t8103-pmgr", "syscon", "simple-mfd"; + reg = <0x2 0x80600000 0 0x4000>; + #address-cells = <1>; + #size-cells = <1>; + }; + + pmgr1: power-management@280900000 { + compatible = "apple,t6050-pmgr", "apple,t8103-pmgr", "syscon", "simple-mfd"; + reg = <0x2 0x80900000 0 0x4000>; + #address-cells = <1>; + #size-cells = <1>; + }; + + pmgr2: power-management@288300000 { + compatible = "apple,t6050-pmgr", "apple,t8103-pmgr", "syscon", "simple-mfd"; + reg = <0x2 0x88300000 0 0xc000>; + #address-cells = <1>; + #size-cells = <1>; + }; + + wdt: watchdog@28836c000 { + compatible = "apple,t6050-wdt", "apple,t8103-wdt"; + reg = <0x2 0x8836c000 0x0 0x4000>; + clocks = <&clkref>; + interrupt-parent = <&aic>; + interrupts = ; + }; + + // MTP coprocessor and dockchannel HID (keyboard, trackpad), on the + // t8142 J813 layout. Addresses from the J714c ADT: mtp 0x294600000, + // dart-mtp 0x294800000 (0xc000), dockchannel-mtp 0x294b14000 (irq) and + // 0x294b28000.. (data windows). The ADT lists no power or clock gates. + mtp: mtp@294600000 { + compatible = "apple,t6050-mtp", "apple,t8142-rtk-helper-asc4", + "apple,mtp", "apple,rtk-helper-asc4"; + /* The second region is firmware SRAM, not the ASC control window. */ + reg = <0x2 0x94600000 0x0 0x4000>, <0x2 0x94c00000 0x0 0x100000>; + reg-names = "asc", "sram"; + iommus = <&mtp_dart 0>; + mboxes = <&mtp_mbox>; + + status = "disabled"; + }; + + mtp_mbox: mailbox@294608000 { + compatible = "apple,t6050-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <0x2 0x94608000 0x0 0x4000>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + + status = "disabled"; + }; + + mtp_dart: iommu@294800000 { + compatible = "apple,t6050-dart", "apple,t8142-dart", "apple,t8110-dart"; + reg = <0x2 0x94800000 0x0 0xc000>; + interrupts = ; + #iommu-cells = <1>; + /* Keep host allocations clear of firmware's low IOVA mappings. */ + apple,dma-range = <0 0x02000000 0 0x10000000>; + + status = "disabled"; + }; + + mtp_dockchannel: fifo@294b14000 { + compatible = "apple,t6050-dockchannel", "apple,dockchannel"; + reg = <0x2 0x94b14000 0x0 0x1000>; + reg-names = "irq"; + ranges = <0 0x2 0x94b28000 0x20000>; + #address-cells = <1>; + #interrupt-cells = <2>; + interrupt-controller; + interrupts = ; + nonposted-mmio; + #size-cells = <1>; + + status = "disabled"; + + mtp_hid: input@8000 { + compatible = "apple,dockchannel-hid"; + reg = <0x8000 0x1000>, <0xc000 0x1000>, + <0x0000 0x1000>, <0x4000 0x1000>; + reg-names = "config", "data", "rmt-config", "rmt-data"; + interrupt-parent = <&mtp_dockchannel>; + interrupts = <2 IRQ_TYPE_LEVEL_HIGH>, <3 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "tx", "rx"; + iommus = <&mtp_dart 0>; + apple,fifo-size = <0x800>; + apple,helper-cpu = <&mtp>; + }; + }; + + // AP GPIO block. ADT /arm-io/gpio0: 0x9c000000 + 0x44000, 221 pins, + // seven AIC interrupts, no-restore-gpio-pins 5 6 7 112 141. The t8140 + // driver variant: slots in the block fault when read, so the regmap is + // not cache-initialised and stays inside the valid pins minus the + // reserved ranges (the firmware's no-restore pins, as t8140.dtsi). + // Enabled by the board DT together with its first users, the audio + // codec reset, shutdown and interrupt lines. + pinctrl_ap: pinctrl@29c000000 { + compatible = "apple,t6050-pinctrl", "apple,t8140-pinctrl"; + reg = <0x2 0x9c000000 0x0 0x44000>; + #gpio-cells = <2>; + gpio-controller; + gpio-ranges = <&pinctrl_ap 0 0 221>; + gpio-reserved-ranges = <5 3>, <112 1>, <141 1>; + #interrupt-cells = <2>; + interrupt-controller; + interrupt-parent = <&aic>; + interrupts = , + , + , + , + , + , + ; + power-domains = <&ps_gpio>; + apple,npins = <221>; + + status = "disabled"; + }; + + // I2C controllers. ADT /arm-io/i2c1..3: 0x305014000, 0x305018000, + // 0x30501c000 (+ 0x4000 each), AIC interrupts 1376-1378, pmgr I2C1-3. + // SCL/SDA are AP pins 60/61, 62/63 and 64/65; iBoot leaves them muxed + // (it drives the speaker amps for the boot chime), so no pin groups are + // set here. i2c1 and i2c3 carry the speaker amps, i2c2 the jack codec. + i2c1: i2c@505014000 { + compatible = "apple,t6050-i2c", "apple,t8103-i2c"; + reg = <0x5 0x05014000 0x0 0x4000>; + #address-cells = <1>; + clocks = <&clkref>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&ps_i2c1>; + #size-cells = <0>; + + status = "disabled"; + }; + + i2c2: i2c@505018000 { + compatible = "apple,t6050-i2c", "apple,t8103-i2c"; + reg = <0x5 0x05018000 0x0 0x4000>; + #address-cells = <1>; + clocks = <&clkref>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&ps_i2c2>; + #size-cells = <0>; + + status = "disabled"; + }; + + i2c3: i2c@50501c000 { + compatible = "apple,t6050-i2c", "apple,t8103-i2c"; + reg = <0x5 0x0501c000 0x0 0x4000>; + #address-cells = <1>; + clocks = <&clkref>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&ps_i2c3>; + #size-cells = <0>; + + status = "disabled"; + }; + + fpwm0: pwm@505040000 { + compatible = "apple,t6050-fpwm", "apple,s5l-fpwm"; + reg = <0x5 0x05040000 0x0 0x4000>; + clocks = <&clkref>; + power-domains = <&ps_fpwm0>; + #pwm-cells = <2>; + + status = "disabled"; + }; + + serial0: serial@505200000 { + compatible = "apple,s5l-uart"; + reg = <0x5 0x05200000 0x0 0x4000>; + clocks = <&clkref>, <&clkref>; + clock-names = "uart", "clk_uart_baud0"; + interrupt-parent = <&aic>; + interrupts = ; + reg-io-width = <4>; + }; + + pmgr3: power-management@2300e80000 { + compatible = "apple,t6050-pmgr", "apple,t8103-pmgr", "syscon", "simple-mfd"; + reg = <0x23 0xe80000 0 0x4000>; + #address-cells = <1>; + #size-cells = <1>; + }; + + pmgr4: power-management@2380600000 { + compatible = "apple,t6050-pmgr", "apple,t8103-pmgr", "syscon", "simple-mfd"; + reg = <0x23 0x80600000 0 0xc000>; + #address-cells = <1>; + #size-cells = <1>; + }; + + pmgr5: power-management@2388300000 { + compatible = "apple,t6050-pmgr", "apple,t8103-pmgr", "syscon", "simple-mfd"; + reg = <0x23 0x88300000 0 0x4000>; + #address-cells = <1>; + #size-cells = <1>; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t6050-j714c-isp.dtsi b/arch/arm64/boot/dts/apple/t6050-j714c-isp.dtsi new file mode 100644 index 00000000000000..4c4ced55abbf2e --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6050-j714c-isp.dtsi @@ -0,0 +1,202 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * J714c ISP: T6050's ISP17a (ASC version 0x110003), laid out and booted as + * aurora's T6040 (M4 Pro/Max) one, at the same addresses: isp0 0x580000000, + * dart-isp0 0x5828c0000/0x5828e0000/0x582900000 (+0xc000), the mailbox at + * +0x2924000. T8140's mailbox offset, +0x2920000, stalls the bus here. + * From the J714c ADT: IRQs [513 514 515 516 526] (513 carries the mailbox), + * dart-isp0 IRQ 531, remap streams 1 6 7 10 11 -> 0, sensor-type 0x73. + * + * The ADT marks the ISP sub-domains no_ps, but pmgr1's slots run by device id + * 8 bytes apart from ISP_SYS (218, +0x3a0): ISP_CPU 220 +0x3b0, ISP_FE 221 + * +0x3b8, DPRX 225 +0x3d8, ISP_SECURE 226 +0x3e0, ISP_BE 227 +0x3e8, ISP_CLR + * 228 +0x3f0, with the ADT's parents. All reach active from the AP. + * + * iBoot loads the firmware's __TEXT and __DATA (isp0 segment-ranges) into its + * 32 MiB main memory at 0x100_0000_0000; they end at 0x1fec000. The physical + * addresses are those of iBoot mBoot-20457.60.65.0.1 (macOS 27.3 beta 1) and + * move with it. No "isp" alias: the boot loader leaves this node as it is. + * + * The front camera is an IMX958 (sensor 0x958), as on the M4 Pro/Max. + */ + +&{/reserved-memory} { + isp_fw_text: isp-firmware-text@10001224000 { + reg = <0x100 0x01224000 0x0 0xc1c000>; + iommu-addresses = <&isp 0x100 0x0 0x0 0xc1c000>; + no-map; + }; + + isp_fw_data: isp-firmware-data@10002930000 { + reg = <0x100 0x02930000 0x0 0x13d0000>; + iommu-addresses = <&isp 0x100 0xc1c000 0x0 0x13d0000>; + no-map; + }; + + /* the firmware's main memory, the driver backs it above the data */ + isp_heap: isp-heap { + iommu-addresses = <&isp 0x100 0x0 0x0 0x2000000>; + }; +}; + +&pmgr1 { + ps_isp_cpu: power-controller@3b0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3b0 4>; + label = "isp_cpu"; + #power-domain-cells = <0>; + #reset-cells = <0>; + power-domains = <&ps_isp_sys>; + }; + + ps_isp_fe: power-controller@3b8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3b8 4>; + label = "isp_fe"; + #power-domain-cells = <0>; + #reset-cells = <0>; + power-domains = <&ps_isp_sys>; + }; + + ps_isp_dprx: power-controller@3d8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3d8 4>; + label = "isp_dprx"; + #power-domain-cells = <0>; + #reset-cells = <0>; + power-domains = <&ps_isp_fe>; + }; + + ps_isp_secure: power-controller@3e0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3e0 4>; + label = "isp_secure"; + #power-domain-cells = <0>; + #reset-cells = <0>; + power-domains = <&ps_isp_fe>; + }; + + ps_isp_be: power-controller@3e8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3e8 4>; + label = "isp_be"; + #power-domain-cells = <0>; + #reset-cells = <0>; + power-domains = <&ps_isp_fe>; + }; + + ps_isp_clr: power-controller@3f0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3f0 4>; + label = "isp_clr"; + #power-domain-cells = <0>; + #reset-cells = <0>; + power-domains = <&ps_isp_be>; + }; +}; + +&soc { + isp_dart0: iommu@5828c0000 { + compatible = "apple,t6050-dart", "apple,t8110-dart"; + /* ADT dart-isp0 reg[0] and reg[5], its address filter */ + reg = <0x5 0x828c0000 0x0 0xc000>, <0x5 0x828d0000 0x0 0x4000>; + reg-names = "dart", "dapf"; + #iommu-cells = <1>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&ps_isp_sys>; + apple,remap-streams = <1 0>, <6 0>, <7 0>, <10 0>, <11 0>; + }; + + isp_dart1: iommu@5828e0000 { + compatible = "apple,t6050-dart", "apple,t8110-dart"; + reg = <0x5 0x828e0000 0x0 0xc000>; + #iommu-cells = <1>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&ps_isp_sys>; + apple,remap-streams = <1 0>, <6 0>, <7 0>, <10 0>, <11 0>; + }; + + isp_dart2: iommu@582900000 { + compatible = "apple,t6050-dart", "apple,t8110-dart"; + reg = <0x5 0x82900000 0x0 0xc000>; + #iommu-cells = <1>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&ps_isp_sys>; + apple,remap-streams = <1 0>, <6 0>, <7 0>, <10 0>, <11 0>; + }; + + /* + * As on T6040: "coproc" up to its control block; "mbox", "gpio" and + * "mbox2" are the interrupt words, the firmware handshake words and + * the doorbell of the mailbox at +0x2924000. + */ + isp: isp@580000000 { + compatible = "apple,t6050-isp", "apple,isp"; + iommus = <&isp_dart0 0>, <&isp_dart1 0>, <&isp_dart2 0>; + reg-names = "coproc", "mbox", "gpio", "mbox2", "wdt", "cil"; + reg = <0x5 0x80000000 0x0 0x1604000>, + <0x5 0x82924000 0x0 0x40>, + <0x5 0x829241d0 0x0 0x20>, + <0x5 0x82924464 0x0 0x10>, + <0x5 0xc3b50000 0x0 0x8000>, + <0x2 0xdc000234 0x0 0x4>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&ps_isp_sys>, <&ps_isp_cpu>, <&ps_isp_fe>, + <&ps_isp_dprx>, <&ps_isp_secure>, <&ps_isp_be>, + <&ps_isp_clr>, <&ps_ispsens0>; + memory-region = <&isp_fw_text>, <&isp_fw_data>, <&isp_heap>; + memory-region-names = "text", "data", "heap"; + /* the shared memory window above the firmware's 32 MiB */ + apple,dart-vm-size = /bits/ 64 <0xde600000>; + /* the ADT isp0 sensor-type */ + apple,platform-id = <0x73>; + apple,temporal-filter = <1>; + /* ADT isp0 cam-connections-scheme, as on the M4 Pro/Max J614/J616 */ + apple,cam-connections-scheme = <0x10>; + /* + * The camera light: ADT eic cil-gpio-offset 141 in gpio0 + * (0x2dc000000), cil-gpio-config 0x474002. Active high: driven + * low it is off even while the sensor streams (measured). + * "wdt" is the eic's mmio-wd-isp: frames pass only while it is fed, + * which the driver does only while the light is on. + */ + apple,cil-config = <0x474002>; + apple,cil-active-high; + + /* + * The full IMX958, cropped to the centre: inside the lens circle and + * about the field of view macOS shows. 1920x1080 and 1280x720 scale + * a 2400x1350 window; 2560x1440 is the centre 1:1. 1920x1080 and + * 2560x1440 use firmware configuration 6, the one macOS streams (two + * exposures, 3040x5760, merged to 3040x2880); 1280x720 uses + * configuration 7 (3040x2880). + */ + sensor-presets { + /* 1920x1080 */ + preset0 { + apple,config-index = <6>; + apple,input-size = <3040 2880>; + apple,output-size = <1920 1080>; + apple,crop = <320 765 2400 1350>; + }; + /* 1280x720 */ + preset1 { + apple,config-index = <7>; + apple,input-size = <3040 2880>; + apple,output-size = <1280 720>; + apple,crop = <320 765 2400 1350>; + }; + /* 2560x1440 */ + preset2 { + apple,config-index = <6>; + apple,input-size = <3040 2880>; + apple,output-size = <2560 1440>; + apple,crop = <240 720 2560 1440>; + }; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t6050-j714c.dts b/arch/arm64/boot/dts/apple/t6050-j714c.dts new file mode 100644 index 00000000000000..d3ab5f1ea26da3 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6050-j714c.dts @@ -0,0 +1,129 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Apple MacBook Pro (14-inch, M5 Max, 18 CPU cores) + * + * target-type: J714c + * + * The loader supplies usable memory, CPU release addresses and + * framebuffer geometry. Peripheral power domains come from + * t6050-pmgr.dtsi; the framebuffer holds the display domain. + * + * Copyright The Asahi Linux Contributors + */ + +/dts-v1/; + +#include +#include +#include + +#include "t6050.dtsi" +#include "t6050-smc.dtsi" +#include "t6050-j714c-isp.dtsi" + +/ { + compatible = "apple,j714c", "apple,t6050", "apple,arm-platform"; + #address-cells = <2>; + interrupt-parent = <&aic>; + model = "Apple MacBook Pro (14-inch, M5 Max, 18 CPU cores)"; + #size-cells = <2>; + + aliases { + keyboard = &keyboard; + serial0 = &serial0; + }; + + chosen { + ranges; + #address-cells = <2>; + #size-cells = <2>; + stdout-path = "serial0:1500000n8"; + + framebuffer0: framebuffer@0 { + compatible = "apple,simple-framebuffer", "simple-framebuffer"; + reg = <0 0 0 0>; /* Filled by the loader. */ + power-domains = <&ps_disp_cpu>; + apple,internal-panel; /* simpledrm reports it as eDP */ + + status = "okay"; /* m1n1 only enables it on chips it knows. */ + }; + }; + + memory@10000000000 { + reg = <0x100 0 0 0>; /* Filled by the loader. */ + device_type = "memory"; + }; + + led-controller { + compatible = "pwm-leds"; + + led-0 { + color = ; + default-state = "keep"; + function = LED_FUNCTION_KBD_BACKLIGHT; + label = "kbd_backlight"; + max-brightness = <255>; + pwms = <&fpwm0 0 40000>; + }; + }; +}; + +&fpwm0 { + status = "okay"; +}; + +&mtp { + status = "okay"; +}; + +&mtp_mbox { + status = "okay"; +}; + +&mtp_dart { + status = "okay"; +}; + +&mtp_dockchannel { + status = "okay"; +}; + +&mtp_hid { + actuator { + }; + + keyboard: keyboard { + hid-country-code = <0>; + apple,keyboard-layout-id = <0>; + }; + + mtp_mt: multi-touch { + firmware-name = "apple/tpmtfw-j714c.bin"; + apple,firmware-managed-reset; + apple,power-method = <2>; + }; + + stm { + }; + + tp_accel { + }; +}; + +#include "hwmon-common.dtsi" +#include "hwmon-fan-dual.dtsi" +#include "hwmon-laptop.dtsi" + +/* + * The T6050 SMC spells the fan mode keys F0md/F1md; F0Md/F1Md from + * hwmon-fan*.dtsi do not exist. + */ +&smc_hwmon { + fan-F0Ac { + apple,fan-mode = "F0md"; + }; + + fan-F1Ac { + apple,fan-mode = "F1md"; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t6050-nvme.dtsi b/arch/arm64/boot/dts/apple/t6050-nvme.dtsi new file mode 100644 index 00000000000000..199f5fccb3f294 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6050-nvme.dtsi @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * NVMe related devices for the Apple T6050 "M5 Max" SoC + * + * Register windows from the J714c ADT (/arm-io/ans and /arm-io/sart-ans); + * node layout and the M4-generation driver variant follow t8140.dtsi. + * + * Copyright The Asahi Linux Contributors + */ + +&soc { + ans_mbox: mailbox@419608000 { + compatible = "apple,t6050-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <0x4 0x19608000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + power-domains = <&ps_ans>; + }; + + sart: iommu@41dc50000 { + compatible = "apple,t6050-sart"; /* SARTv4, its own register layout */ + reg = <0x4 0x1dc50000 0x0 0xc000>; + power-domains = <&ps_ans>; + }; + + nvme: nvme@45dcc0000 { + compatible = "apple,t6050-nvme-ans2", "apple,t8140-nvme-ans2"; + // The ADT sizes the controller window at 0x10000; the linear + // submission queue registers sit above that, as on T8140. + reg = <0x4 0x5dcc0000 0x0 0x30000>, + <0x4 0x19600000 0x0 0x4000>, + <0x4 0x1dcc0000 0x0 0x60010>; + reg-names = "nvme", "ans", "nvmmu"; + interrupt-parent = <&aic>; + interrupts = ; + mboxes = <&ans_mbox>; + // The port-0 lane PHY must stay on for the controller: with it + // powered down as unused, enable never reaches CSTS.RDY. + power-domains = <&ps_ans>, <&ps_apcie_sys_st0>, + <&ps_apcie_phy_sw>, <&ps_aphy_st0_aus5>; + power-domain-names = "ans", "apcie0", "apcie_phy", "aphy_st0"; + resets = <&ps_ans>; + apple,sart = <&sart>; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t6050-pmgr.dtsi b/arch/arm64/boot/dts/apple/t6050-pmgr.dtsi new file mode 100644 index 00000000000000..a692ab1e256646 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6050-pmgr.dtsi @@ -0,0 +1,2722 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * PMGR Power domains for Apple T6050 "M5 Max" SoC + * + * Generated from the J714c ADT with pmgr_adt2dt.py, then edited by hand. + * Regenerating loses the following: + * - the CPU core and cluster domains are left out, as in every other + * pmgr file; + * - parent references to register-less (no_ps) ADT domains point at the + * nearest real ancestor or are dropped; + * - apple,always-on is removed from the 25 domains the boot firmware + * leaves off (b2b fabric, nub SPMI, afr) and added to the core set + * aic, disp_sys, disp_fe, uart_p, spi_p, ans as in t8132-pmgr.dtsi; + * - apple,firmware-owned marks disp_cpu, dispext0-3_cpu (writing them + * raises an SError) and smc_i2cm0-5 (enabling auto-PM on one or more + * of them resets the machine a few seconds into the boot). + * + * Copyright The Asahi Linux Contributors + */ + +&pmgr0 { + ps_aic: power-controller@108 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x108 4>; + label = "aic"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_pmc: power-controller@110 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x110 4>; + label = "pmc"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_pms_c1ppt: power-controller@118 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x118 4>; + label = "pms_c1ppt"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_soc_dpe: power-controller@120 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x120 4>; + label = "soc_dpe"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_pmp: power-controller@128 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x128 4>; + label = "pmp"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_pms_sram: power-controller@130 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x130 4>; + label = "pms_sram"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_pmgr_soc_ocla: power-controller@138 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x138 4>; + label = "pmgr_soc_ocla"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2b_ctrl_nogate: power-controller@140 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x140 4>; + label = "b2b_ctrl_nogate"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab0_acc_0: power-controller@148 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x148 4>; + label = "fab0_acc_0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab0_acc_1: power-controller@150 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x150 4>; + label = "fab0_acc_1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab2_acc: power-controller@158 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x158 4>; + label = "fab2_acc"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab1_acc: power-controller@160 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x160 4>; + label = "fab1_acc"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_b2bc_afc_0: power-controller@168 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x168 4>; + label = "b2bc_afc_0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_b2bc_afc_0_dfx: power-controller@170 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x170 4>; + label = "b2bc_afc_0_dfx"; + #power-domain-cells = <0>; + power-domains = <&ps_b2bc_afc_0>; + #reset-cells = <0>; + }; + + ps_b2bc_afc_1: power-controller@178 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x178 4>; + label = "b2bc_afc_1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_b2bc_afc_1_dfx: power-controller@180 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x180 4>; + label = "b2bc_afc_1_dfx"; + #power-domain-cells = <0>; + power-domains = <&ps_b2bc_afc_1>; + #reset-cells = <0>; + }; + + ps_fab4_soc: power-controller@1e8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1e8 4>; + label = "fab4_soc"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab5_soc: power-controller@1f0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1f0 4>; + label = "fab5_soc"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_dispext0_sys: power-controller@200 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x200 4>; + label = "dispext0_sys"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc0_common: power-controller@208 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x208 4>; + label = "atc0_common"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc1_common: power-controller@210 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x210 4>; + label = "atc1_common"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_dispext2_sys: power-controller@220 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x220 4>; + label = "dispext2_sys"; + #power-domain-cells = <0>; + power-domains = <&ps_fab4_soc>; + #reset-cells = <0>; + }; + + ps_dispext3_sys: power-controller@228 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x228 4>; + label = "dispext3_sys"; + #power-domain-cells = <0>; + power-domains = <&ps_fab4_soc>; + #reset-cells = <0>; + }; + + ps_dispext1_sys: power-controller@230 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x230 4>; + label = "dispext1_sys"; + #power-domain-cells = <0>; + power-domains = <&ps_fab5_soc>; + #reset-cells = <0>; + }; + + ps_atc2_common: power-controller@238 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x238 4>; + label = "atc2_common"; + #power-domain-cells = <0>; + power-domains = <&ps_fab5_soc>; + #reset-cells = <0>; + }; + + ps_atc3_common: power-controller@240 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x240 4>; + label = "atc3_common"; + #power-domain-cells = <0>; + power-domains = <&ps_fab5_soc>; + #reset-cells = <0>; + apple,firmware-owned; + }; + + ps_auss: power-controller@248 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x248 4>; + label = "auss"; + #power-domain-cells = <0>; + power-domains = <&ps_fab5_soc>; + #reset-cells = <0>; + }; + + ps_gpio: power-controller@250 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x250 4>; + label = "gpio"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_msg: power-controller@258 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x258 4>; + label = "msg"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_ap_tmm: power-controller@260 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x260 4>; + label = "ap_tmm"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_dispext0_fe: power-controller@268 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x268 4>; + label = "dispext0_fe"; + #power-domain-cells = <0>; + power-domains = <&ps_dispext0_sys>; + #reset-cells = <0>; + }; + + ps_dispext0_adma: power-controller@270 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x270 4>; + label = "dispext0_adma"; + #power-domain-cells = <0>; + power-domains = <&ps_dispext0_sys>; + #reset-cells = <0>; + }; + + ps_dispext0_cpu: power-controller@278 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x278 4>; + label = "dispext0_cpu"; + #power-domain-cells = <0>; + power-domains = <&ps_dispext0_fe>; + #reset-cells = <0>; + /* The display coprocessor owns this state; writing it faults (SError). */ + apple,firmware-owned; + }; + +/* + * atc0-3_cio and atc3_common are left to the firmware for now: the kernel's + * boot-time power-on of these domains (J714c) breaks the USB 2.0 + * host on the parked Type-C PHY (the xHCI reset never completes). USB4 needs + * them driven in sequence with the PHY, by the PHY driver, later. + */ + ps_atc0_cio: power-controller@280 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x280 4>; + label = "atc0_cio"; + #power-domain-cells = <0>; + power-domains = <&ps_atc0_common>; + #reset-cells = <0>; + apple,firmware-owned; + }; + + ps_atc0_pcie: power-controller@288 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x288 4>; + label = "atc0_pcie"; + #power-domain-cells = <0>; + power-domains = <&ps_atc0_common>; + #reset-cells = <0>; + }; + + ps_atc1_cio: power-controller@290 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x290 4>; + label = "atc1_cio"; + #power-domain-cells = <0>; + power-domains = <&ps_atc1_common>; + #reset-cells = <0>; + apple,firmware-owned; + }; + + ps_atc1_pcie: power-controller@298 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x298 4>; + label = "atc1_pcie"; + #power-domain-cells = <0>; + power-domains = <&ps_atc1_common>; + #reset-cells = <0>; + }; + + ps_dispext2_fe: power-controller@2a0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2a0 4>; + label = "dispext2_fe"; + #power-domain-cells = <0>; + power-domains = <&ps_dispext2_sys>; + #reset-cells = <0>; + }; + + ps_dispext2_adma: power-controller@2a8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2a8 4>; + label = "dispext2_adma"; + #power-domain-cells = <0>; + power-domains = <&ps_dispext2_sys>; + #reset-cells = <0>; + }; + + ps_dispext2_cpu: power-controller@2b0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2b0 4>; + label = "dispext2_cpu"; + #power-domain-cells = <0>; + power-domains = <&ps_dispext2_fe>; + #reset-cells = <0>; + /* The display coprocessor owns this state; writing it faults (SError). */ + apple,firmware-owned; + }; + + ps_dispext3_fe: power-controller@2b8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2b8 4>; + label = "dispext3_fe"; + #power-domain-cells = <0>; + power-domains = <&ps_dispext3_sys>; + #reset-cells = <0>; + }; + + ps_dispext3_adma: power-controller@2c0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2c0 4>; + label = "dispext3_adma"; + #power-domain-cells = <0>; + power-domains = <&ps_dispext3_sys>; + #reset-cells = <0>; + }; + + ps_dispext3_cpu: power-controller@2c8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2c8 4>; + label = "dispext3_cpu"; + #power-domain-cells = <0>; + power-domains = <&ps_dispext3_fe>; + #reset-cells = <0>; + /* The display coprocessor owns this state; writing it faults (SError). */ + apple,firmware-owned; + }; + + ps_dispext1_fe: power-controller@2d0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2d0 4>; + label = "dispext1_fe"; + #power-domain-cells = <0>; + power-domains = <&ps_dispext1_sys>; + #reset-cells = <0>; + }; + + ps_dispext1_adma: power-controller@2d8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2d8 4>; + label = "dispext1_adma"; + #power-domain-cells = <0>; + power-domains = <&ps_dispext1_sys>; + #reset-cells = <0>; + }; + + ps_dispext1_cpu: power-controller@2e0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2e0 4>; + label = "dispext1_cpu"; + #power-domain-cells = <0>; + power-domains = <&ps_dispext1_fe>; + #reset-cells = <0>; + /* The display coprocessor owns this state; writing it faults (SError). */ + apple,firmware-owned; + }; + + ps_atc2_cio: power-controller@2e8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2e8 4>; + label = "atc2_cio"; + #power-domain-cells = <0>; + power-domains = <&ps_atc2_common>; + #reset-cells = <0>; + apple,firmware-owned; + }; + + ps_atc2_pcie: power-controller@2f0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2f0 4>; + label = "atc2_pcie"; + #power-domain-cells = <0>; + power-domains = <&ps_atc2_common>; + #reset-cells = <0>; + }; + + ps_atc3_cio: power-controller@2f8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2f8 4>; + label = "atc3_cio"; + #power-domain-cells = <0>; + power-domains = <&ps_atc3_common>; + #reset-cells = <0>; + apple,firmware-owned; + }; + + ps_atc3_pcie: power-controller@300 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x300 4>; + label = "atc3_pcie"; + #power-domain-cells = <0>; + power-domains = <&ps_atc3_common>; + #reset-cells = <0>; + }; + + ps_atc0_cio_pcie: power-controller@338 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x338 4>; + label = "atc0_cio_pcie"; + #power-domain-cells = <0>; + power-domains = <&ps_atc0_cio>; + #reset-cells = <0>; + }; + + ps_atc0_cio_usb: power-controller@340 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x340 4>; + label = "atc0_cio_usb"; + #power-domain-cells = <0>; + power-domains = <&ps_atc0_cio>; + #reset-cells = <0>; + }; + + ps_atc0_cio_auss: power-controller@348 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x348 4>; + label = "atc0_cio_auss"; + #power-domain-cells = <0>; + power-domains = <&ps_atc0_cio>, <&ps_auss>; + #reset-cells = <0>; + }; + + ps_atc1_cio_pcie: power-controller@350 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x350 4>; + label = "atc1_cio_pcie"; + #power-domain-cells = <0>; + power-domains = <&ps_atc1_cio>; + #reset-cells = <0>; + }; + + ps_atc1_cio_usb: power-controller@358 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x358 4>; + label = "atc1_cio_usb"; + #power-domain-cells = <0>; + power-domains = <&ps_atc1_cio>; + #reset-cells = <0>; + }; + + ps_atc1_cio_auss: power-controller@360 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x360 4>; + label = "atc1_cio_auss"; + #power-domain-cells = <0>; + power-domains = <&ps_atc1_cio>, <&ps_auss>; + #reset-cells = <0>; + }; + + ps_atc2_cio_pcie: power-controller@3f8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3f8 4>; + label = "atc2_cio_pcie"; + #power-domain-cells = <0>; + power-domains = <&ps_atc2_cio>; + #reset-cells = <0>; + }; + + ps_atc2_cio_usb: power-controller@400 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x400 4>; + label = "atc2_cio_usb"; + #power-domain-cells = <0>; + power-domains = <&ps_atc2_cio>; + #reset-cells = <0>; + }; + + ps_atc2_cio_auss: power-controller@408 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x408 4>; + label = "atc2_cio_auss"; + #power-domain-cells = <0>; + power-domains = <&ps_atc2_cio>, <&ps_auss>; + #reset-cells = <0>; + }; + + ps_atc3_cio_pcie: power-controller@410 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x410 4>; + label = "atc3_cio_pcie"; + #power-domain-cells = <0>; + power-domains = <&ps_atc3_cio>; + #reset-cells = <0>; + }; + + ps_atc3_cio_usb: power-controller@418 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x418 4>; + label = "atc3_cio_usb"; + #power-domain-cells = <0>; + power-domains = <&ps_atc3_cio>; + #reset-cells = <0>; + }; + + ps_atc3_cio_auss: power-controller@420 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x420 4>; + label = "atc3_cio_auss"; + #power-domain-cells = <0>; + power-domains = <&ps_atc3_cio>, <&ps_auss>; + #reset-cells = <0>; + }; + + ps_fppt: power-controller@450 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x450 4>; + label = "fppt"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bc_dft: power-controller@458 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x458 4>; + label = "b2bc_dft"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bc_cntl_dfx: power-controller@460 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x460 4>; + label = "b2bc_cntl_dfx"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bc_dbg_0: power-controller@468 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x468 4>; + label = "b2bc_dbg_0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bc_dbg_1: power-controller@470 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x470 4>; + label = "b2bc_dbg_1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bc_dbg_2: power-controller@478 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x478 4>; + label = "b2bc_dbg_2"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; +}; + +&pmgr1 { + ps_ispsens0: power-controller@100 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x100 4>; + label = "ispsens0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_global_aux_hpd_0: power-controller@108 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x108 4>; + label = "global_aux_hpd_0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_global_aux_hpd_1: power-controller@110 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x110 4>; + label = "global_aux_hpd_1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_apcie_gp: power-controller@118 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x118 4>; + label = "apcie_gp"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_apcie_st0: power-controller@128 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x128 4>; + label = "apcie_st0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_apcie_st1: power-controller@130 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x130 4>; + label = "apcie_st1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_fab6_soc: power-controller@138 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x138 4>; + label = "fab6_soc"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_ans: power-controller@140 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x140 4>; + label = "ans"; + #power-domain-cells = <0>; + power-domains = <&ps_fab6_soc>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_apcie_sys_gp: power-controller@148 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x148 4>; + label = "apcie_sys_gp"; + #power-domain-cells = <0>; + power-domains = <&ps_apcie_gp>, <&ps_fab6_soc>; + #reset-cells = <0>; + }; + + ps_apcie_sys_st0: power-controller@150 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x150 4>; + label = "apcie_sys_st0"; + #power-domain-cells = <0>; + power-domains = <&ps_apcie_st0>, <&ps_ans>; + #reset-cells = <0>; + }; + + ps_apcie_sys_st1: power-controller@158 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x158 4>; + label = "apcie_sys_st1"; + #power-domain-cells = <0>; + power-domains = <&ps_apcie_st1>, <&ps_ans>; + #reset-cells = <0>; + }; + + ps_apcie_sys_gp_oc: power-controller@160 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x160 4>; + label = "apcie_sys_gp_oc"; + #power-domain-cells = <0>; + power-domains = <&ps_apcie_sys_gp>; + #reset-cells = <0>; + }; + + ps_apcie_sys_st0_o: power-controller@168 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x168 4>; + label = "apcie_sys_st0_o"; + #power-domain-cells = <0>; + power-domains = <&ps_apcie_sys_st0>; + #reset-cells = <0>; + }; + + ps_apcie_sys_st1_o: power-controller@170 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x170 4>; + label = "apcie_sys_st1_o"; + #power-domain-cells = <0>; + power-domains = <&ps_apcie_sys_st1>; + #reset-cells = <0>; + }; + + ps_fab7_soc: power-controller@178 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x178 4>; + label = "fab7_soc"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_disp_sys: power-controller@180 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x180 4>; + label = "disp_sys"; + #power-domain-cells = <0>; + power-domains = <&ps_fab7_soc>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_scodec: power-controller@190 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x190 4>; + label = "scodec"; + #power-domain-cells = <0>; + power-domains = <&ps_fab7_soc>; + #reset-cells = <0>; + }; + + ps_disp_fe: power-controller@198 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x198 4>; + label = "disp_fe"; + #power-domain-cells = <0>; + power-domains = <&ps_disp_sys>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_disp_adma: power-controller@1a0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1a0 4>; + label = "disp_adma"; + #power-domain-cells = <0>; + power-domains = <&ps_disp_sys>; + #reset-cells = <0>; + }; + + ps_disp_cpu: power-controller@1a8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1a8 4>; + label = "disp_cpu"; + #power-domain-cells = <0>; + power-domains = <&ps_disp_fe>; + #reset-cells = <0>; + /* The display coprocessor owns this state; writing it faults (SError). */ + apple,firmware-owned; + }; + + ps_apcie_phy_sw: power-controller@1b0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1b0 4>; + label = "apcie_phy_sw"; + #power-domain-cells = <0>; + power-domains = <&ps_apcie_sys_gp>, <&ps_fab6_soc>; + #reset-cells = <0>; + }; + + ps_scodec_streaming: power-controller@1c0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1c0 4>; + label = "scodec_streaming"; + #power-domain-cells = <0>; + power-domains = <&ps_scodec>; + #reset-cells = <0>; + }; + + ps_aphy_st0_aus5_a: power-controller@240 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x240 4>; + label = "aphy_st0_aus5_a"; + #power-domain-cells = <0>; + power-domains = <&ps_apcie_phy_sw>; + #reset-cells = <0>; + }; + + ps_aphy_st1_aus5_a: power-controller@248 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x248 4>; + label = "aphy_st1_aus5_a"; + #power-domain-cells = <0>; + power-domains = <&ps_apcie_phy_sw>; + #reset-cells = <0>; + }; + + ps_aphy_gp_aus5_a: power-controller@258 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x258 4>; + label = "aphy_gp_aus5_a"; + #power-domain-cells = <0>; + power-domains = <&ps_apcie_phy_sw>; + #reset-cells = <0>; + }; + + ps_aphy_st0_aus5: power-controller@268 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x268 4>; + label = "aphy_st0_aus5"; + #power-domain-cells = <0>; + power-domains = <&ps_aphy_st0_aus5_a>; + #reset-cells = <0>; + }; + + ps_aphy_st1_aus5: power-controller@270 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x270 4>; + label = "aphy_st1_aus5"; + #power-domain-cells = <0>; + power-domains = <&ps_aphy_st1_aus5_a>; + #reset-cells = <0>; + }; + + ps_aphy_gp_aus5: power-controller@280 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x280 4>; + label = "aphy_gp_aus5"; + #power-domain-cells = <0>; + power-domains = <&ps_aphy_gp_aus5_a>; + #reset-cells = <0>; + }; + + ps_fab8_soc: power-controller@288 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x288 4>; + label = "fab8_soc"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_sio: power-controller@290 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x290 4>; + label = "sio"; + #power-domain-cells = <0>; + power-domains = <&ps_fab8_soc>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_sep: power-controller@298 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x298 4>; + label = "sep"; + #power-domain-cells = <0>; + power-domains = <&ps_fab8_soc>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_sio_cpu: power-controller@2a0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2a0 4>; + label = "sio_cpu"; + #power-domain-cells = <0>; + power-domains = <&ps_sio>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fpwm0: power-controller@2a8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2a8 4>; + label = "fpwm0"; + #power-domain-cells = <0>; + power-domains = <&ps_sio>; + #reset-cells = <0>; + }; + + ps_fpwm2: power-controller@2b8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2b8 4>; + label = "fpwm2"; + #power-domain-cells = <0>; + power-domains = <&ps_sio>; + #reset-cells = <0>; + }; + + ps_i2c0: power-controller@2c0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2c0 4>; + label = "i2c0"; + #power-domain-cells = <0>; + power-domains = <&ps_sio>; + #reset-cells = <0>; + }; + + ps_i2c1: power-controller@2c8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2c8 4>; + label = "i2c1"; + #power-domain-cells = <0>; + power-domains = <&ps_sio>; + #reset-cells = <0>; + }; + + ps_i2c2: power-controller@2d0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2d0 4>; + label = "i2c2"; + #power-domain-cells = <0>; + power-domains = <&ps_sio>; + #reset-cells = <0>; + }; + + ps_i2c3: power-controller@2d8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2d8 4>; + label = "i2c3"; + #power-domain-cells = <0>; + power-domains = <&ps_sio>; + #reset-cells = <0>; + }; + + ps_i2c4: power-controller@2e0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2e0 4>; + label = "i2c4"; + #power-domain-cells = <0>; + power-domains = <&ps_sio>; + #reset-cells = <0>; + }; + + ps_i2c5: power-controller@2e8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2e8 4>; + label = "i2c5"; + #power-domain-cells = <0>; + power-domains = <&ps_sio>; + #reset-cells = <0>; + }; + + ps_i2c6: power-controller@2f0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2f0 4>; + label = "i2c6"; + #power-domain-cells = <0>; + power-domains = <&ps_sio>; + #reset-cells = <0>; + }; + + ps_i2c7: power-controller@2f8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2f8 4>; + label = "i2c7"; + #power-domain-cells = <0>; + power-domains = <&ps_sio>; + #reset-cells = <0>; + }; + + ps_i2c8: power-controller@300 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x300 4>; + label = "i2c8"; + #power-domain-cells = <0>; + power-domains = <&ps_sio>; + #reset-cells = <0>; + }; + + ps_spi_p: power-controller@308 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x308 4>; + label = "spi_p"; + #power-domain-cells = <0>; + power-domains = <&ps_sio>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_uart_p: power-controller@310 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x310 4>; + label = "uart_p"; + #power-domain-cells = <0>; + power-domains = <&ps_sio>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_aes: power-controller@318 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x318 4>; + label = "aes"; + #power-domain-cells = <0>; + power-domains = <&ps_sio>; + #reset-cells = <0>; + }; + + ps_spi0: power-controller@320 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x320 4>; + label = "spi0"; + #power-domain-cells = <0>; + power-domains = <&ps_spi_p>; + #reset-cells = <0>; + }; + + ps_spi1: power-controller@328 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x328 4>; + label = "spi1"; + #power-domain-cells = <0>; + power-domains = <&ps_spi_p>; + #reset-cells = <0>; + }; + + ps_spi2: power-controller@330 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x330 4>; + label = "spi2"; + #power-domain-cells = <0>; + power-domains = <&ps_spi_p>; + #reset-cells = <0>; + }; + + ps_spi3: power-controller@338 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x338 4>; + label = "spi3"; + #power-domain-cells = <0>; + power-domains = <&ps_spi_p>; + #reset-cells = <0>; + }; + + ps_spi4: power-controller@340 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x340 4>; + label = "spi4"; + #power-domain-cells = <0>; + power-domains = <&ps_spi_p>; + #reset-cells = <0>; + }; + + ps_spi5: power-controller@348 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x348 4>; + label = "spi5"; + #power-domain-cells = <0>; + power-domains = <&ps_spi_p>; + #reset-cells = <0>; + }; + + ps_qspi: power-controller@350 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x350 4>; + label = "qspi"; + #power-domain-cells = <0>; + power-domains = <&ps_spi_p>; + #reset-cells = <0>; + }; + + ps_uart_n: power-controller@358 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x358 4>; + label = "uart_n"; + #power-domain-cells = <0>; + power-domains = <&ps_uart_p>; + #reset-cells = <0>; + }; + + ps_uart0: power-controller@360 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x360 4>; + label = "uart0"; + #power-domain-cells = <0>; + power-domains = <&ps_uart_p>; + #reset-cells = <0>; + }; + + ps_uart1: power-controller@368 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x368 4>; + label = "uart1"; + #power-domain-cells = <0>; + power-domains = <&ps_uart_p>; + #reset-cells = <0>; + }; + + ps_uart2: power-controller@370 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x370 4>; + label = "uart2"; + #power-domain-cells = <0>; + power-domains = <&ps_uart_p>; + #reset-cells = <0>; + }; + + ps_uart3: power-controller@378 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x378 4>; + label = "uart3"; + #power-domain-cells = <0>; + power-domains = <&ps_uart_p>; + #reset-cells = <0>; + }; + + ps_uart4: power-controller@380 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x380 4>; + label = "uart4"; + #power-domain-cells = <0>; + power-domains = <&ps_uart_p>; + #reset-cells = <0>; + }; + + ps_uart5: power-controller@388 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x388 4>; + label = "uart5"; + #power-domain-cells = <0>; + power-domains = <&ps_uart_p>; + #reset-cells = <0>; + }; + + ps_uart6: power-controller@390 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x390 4>; + label = "uart6"; + #power-domain-cells = <0>; + power-domains = <&ps_uart_p>; + #reset-cells = <0>; + }; + + ps_fab9_soc: power-controller@398 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x398 4>; + label = "fab9_soc"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_isp_sys: power-controller@3a0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3a0 4>; + label = "isp_sys"; + #power-domain-cells = <0>; + power-domains = <&ps_fab9_soc>; + #reset-cells = <0>; + }; + + ps_ane_sys: power-controller@3a8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3a8 4>; + label = "ane_sys"; + #power-domain-cells = <0>; + power-domains = <&ps_fab8_soc>, <&ps_fab9_soc>; + #reset-cells = <0>; + }; + + ps_ane_mpm: power-controller@3c0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3c0 4>; + label = "ane_mpm"; + #power-domain-cells = <0>; + power-domains = <&ps_ane_sys>; + #reset-cells = <0>; + }; + + ps_ane_cpu: power-controller@3c8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3c8 4>; + label = "ane_cpu"; + #power-domain-cells = <0>; + power-domains = <&ps_ane_sys>; + #reset-cells = <0>; + }; + + ps_ane_tdbase: power-controller@3d0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3d0 4>; + label = "ane_tdbase"; + #power-domain-cells = <0>; + power-domains = <&ps_ane_sys>; + #reset-cells = <0>; + }; +}; + +&pmgr2 { + ps_debug_gated: power-controller@58 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x58 4>; + label = "debug_gated"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_nub_spmi_a0: power-controller@60 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x60 4>; + label = "nub_spmi_a0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_nub_spmi_a1: power-controller@68 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x68 4>; + label = "nub_spmi_a1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_nub_spmi_a2: power-controller@70 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x70 4>; + label = "nub_spmi_a2"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_nub_dock_channel: power-controller@80 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x80 4>; + label = "nub_dock_channel"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_nub_gpio: power-controller@88 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x88 4>; + label = "nub_gpio"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_atc0_common_dp_0: power-controller@98 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x98 4>; + label = "atc0_common_dp_0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc0_common_dp_1: power-controller@a0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xa0 4>; + label = "atc0_common_dp_1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc0_common_dp_2: power-controller@a8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xa8 4>; + label = "atc0_common_dp_2"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc0_common_dp_3: power-controller@b0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xb0 4>; + label = "atc0_common_dp_3"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc1_common_dp_0: power-controller@b8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xb8 4>; + label = "atc1_common_dp_0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc1_common_dp_1: power-controller@c0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xc0 4>; + label = "atc1_common_dp_1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc1_common_dp_2: power-controller@c8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xc8 4>; + label = "atc1_common_dp_2"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc1_common_dp_3: power-controller@d0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xd0 4>; + label = "atc1_common_dp_3"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc2_common_dp_0: power-controller@d8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xd8 4>; + label = "atc2_common_dp_0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc2_common_dp_1: power-controller@e0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xe0 4>; + label = "atc2_common_dp_1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc2_common_dp_2: power-controller@e8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xe8 4>; + label = "atc2_common_dp_2"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc2_common_dp_3: power-controller@f0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xf0 4>; + label = "atc2_common_dp_3"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc3_common_dp_0: power-controller@f8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xf8 4>; + label = "atc3_common_dp_0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc3_common_dp_1: power-controller@100 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x100 4>; + label = "atc3_common_dp_1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc3_common_dp_2: power-controller@108 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x108 4>; + label = "atc3_common_dp_2"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc3_common_dp_3: power-controller@110 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x110 4>; + label = "atc3_common_dp_3"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_nub_spmi_ahb: power-controller@118 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x118 4>; + label = "nub_spmi_ahb"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_nub_spmi0: power-controller@120 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x120 4>; + label = "nub_spmi0"; + #power-domain-cells = <0>; + power-domains = <&ps_nub_spmi_ahb>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_nub_spmi1: power-controller@128 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x128 4>; + label = "nub_spmi1"; + #power-domain-cells = <0>; + power-domains = <&ps_nub_spmi_ahb>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_nub_spmi2: power-controller@130 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x130 4>; + label = "nub_spmi2"; + #power-domain-cells = <0>; + power-domains = <&ps_nub_spmi_ahb>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_nub_spmi3: power-controller@138 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x138 4>; + label = "nub_spmi3"; + #power-domain-cells = <0>; + power-domains = <&ps_nub_spmi_ahb>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_nub_spmi4: power-controller@140 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x140 4>; + label = "nub_spmi4"; + #power-domain-cells = <0>; + power-domains = <&ps_nub_spmi_ahb>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_atc0_usb_aon: power-controller@148 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x148 4>; + label = "atc0_usb_aon"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc0_usb: power-controller@150 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x150 4>; + label = "atc0_usb"; + #power-domain-cells = <0>; + power-domains = <&ps_atc0_common>, <&ps_atc0_usb_aon>; + #reset-cells = <0>; + }; + + ps_atc0_phymxwrap: power-controller@158 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x158 4>; + label = "atc0_phymxwrap"; + #power-domain-cells = <0>; + power-domains = <&ps_atc0_common>, <&ps_atc0_usb_aon>; + #reset-cells = <0>; + }; + + ps_atc1_usb_aon: power-controller@160 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x160 4>; + label = "atc1_usb_aon"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc1_usb: power-controller@168 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x168 4>; + label = "atc1_usb"; + #power-domain-cells = <0>; + power-domains = <&ps_atc1_common>, <&ps_atc1_usb_aon>; + #reset-cells = <0>; + }; + + ps_atc1_phymxwrap: power-controller@170 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x170 4>; + label = "atc1_phymxwrap"; + #power-domain-cells = <0>; + power-domains = <&ps_atc1_common>, <&ps_atc1_usb_aon>; + #reset-cells = <0>; + }; + + ps_atc2_usb_aon: power-controller@178 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x178 4>; + label = "atc2_usb_aon"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc2_usb: power-controller@180 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x180 4>; + label = "atc2_usb"; + #power-domain-cells = <0>; + power-domains = <&ps_atc2_common>, <&ps_atc2_usb_aon>; + #reset-cells = <0>; + }; + + ps_atc2_phymxwrap: power-controller@188 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x188 4>; + label = "atc2_phymxwrap"; + #power-domain-cells = <0>; + power-domains = <&ps_atc2_common>, <&ps_atc2_usb_aon>; + #reset-cells = <0>; + }; + + ps_atc3_usb_aon: power-controller@190 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x190 4>; + label = "atc3_usb_aon"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_atc3_usb: power-controller@198 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x198 4>; + label = "atc3_usb"; + #power-domain-cells = <0>; + power-domains = <&ps_atc3_common>, <&ps_atc3_usb_aon>; + #reset-cells = <0>; + }; + + ps_atc3_phymxwrap: power-controller@1a0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1a0 4>; + label = "atc3_phymxwrap"; + #power-domain-cells = <0>; + power-domains = <&ps_atc3_common>, <&ps_atc3_usb_aon>; + #reset-cells = <0>; + }; + + ps_smc_i2cm0: power-controller@8028 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8028 4>; + label = "smc_i2cm0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + /* The SMC owns its I2C masters; enabling auto-PM on them resets the machine. */ + apple,firmware-owned; + }; + + ps_smc_i2cm1: power-controller@8030 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8030 4>; + label = "smc_i2cm1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + /* The SMC owns its I2C masters; enabling auto-PM on them resets the machine. */ + apple,firmware-owned; + }; + + ps_smc_i2cm2: power-controller@8038 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8038 4>; + label = "smc_i2cm2"; + #power-domain-cells = <0>; + #reset-cells = <0>; + /* The SMC owns its I2C masters; enabling auto-PM on them resets the machine. */ + apple,firmware-owned; + }; + + ps_smc_i2cm3: power-controller@8040 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8040 4>; + label = "smc_i2cm3"; + #power-domain-cells = <0>; + #reset-cells = <0>; + /* The SMC owns its I2C masters; enabling auto-PM on them resets the machine. */ + apple,firmware-owned; + }; + + ps_smc_i2cm4: power-controller@8048 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8048 4>; + label = "smc_i2cm4"; + #power-domain-cells = <0>; + #reset-cells = <0>; + /* The SMC owns its I2C masters; enabling auto-PM on them resets the machine. */ + apple,firmware-owned; + }; + + ps_smc_i2cm5: power-controller@8050 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8050 4>; + label = "smc_i2cm5"; + #power-domain-cells = <0>; + #reset-cells = <0>; + /* The SMC owns its I2C masters; enabling auto-PM on them resets the machine. */ + apple,firmware-owned; + }; + + ps_smc_i2cm6: power-controller@8058 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8058 4>; + label = "smc_i2cm6"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; +}; + +&pmgr3 { + ps_gpx: power-controller@0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x0 4>; + label = "gpx"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_afr: power-controller@100 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x100 4>; + label = "afr"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_cs: power-controller@108 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x108 4>; + label = "cs"; + #power-domain-cells = <0>; + power-domains = <&ps_afr>; + #reset-cells = <0>; + }; + + ps_gfx: power-controller@110 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x110 4>; + label = "gfx"; + #power-domain-cells = <0>; + power-domains = <&ps_afr>, <&ps_gpx>; + #reset-cells = <0>; + }; +}; + +&pmgr4 { + ps_aic_gfx: power-controller@108 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x108 4>; + label = "aic_gfx"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_pms_gfx_c1ppt: power-controller@110 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x110 4>; + label = "pms_gfx_c1ppt"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_soc_dpe_gfx: power-controller@118 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x118 4>; + label = "soc_dpe_gfx"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_pmgr_soc_ocla_g: power-controller@120 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x120 4>; + label = "pmgr_soc_ocla_g"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2b_ctrl_gfx: power-controller@128 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x128 4>; + label = "b2b_ctrl_gfx"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bg_afc_0: power-controller@130 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x130 4>; + label = "b2bg_afc_0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_b2bg_afc_0_dfx: power-controller@138 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x138 4>; + label = "b2bg_afc_0_dfx"; + #power-domain-cells = <0>; + power-domains = <&ps_b2bg_afc_0>; + #reset-cells = <0>; + }; + + ps_b2bg_afc_1: power-controller@140 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x140 4>; + label = "b2bg_afc_1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_b2bg_afc_1_dfx: power-controller@148 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x148 4>; + label = "b2bg_afc_1_dfx"; + #power-domain-cells = <0>; + power-domains = <&ps_b2bg_afc_1>; + #reset-cells = <0>; + }; + + ps_b2bg_afi_1_dfx: power-controller@188 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x188 4>; + label = "b2bg_afi_1_dfx"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_fppt_gfx: power-controller@198 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x198 4>; + label = "fppt_gfx"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_fab0_soc: power-controller@1a8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1a8 4>; + label = "fab0_soc"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab1_soc: power-controller@1b0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1b0 4>; + label = "fab1_soc"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_venc0_sys: power-controller@1c0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1c0 4>; + label = "venc0_sys"; + #power-domain-cells = <0>; + power-domains = <&ps_fab0_soc>; + #reset-cells = <0>; + }; + + ps_msr0: power-controller@1c8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1c8 4>; + label = "msr0"; + #power-domain-cells = <0>; + power-domains = <&ps_fab0_soc>; + #reset-cells = <0>; + }; + + ps_jpg: power-controller@1d0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1d0 4>; + label = "jpg"; + #power-domain-cells = <0>; + power-domains = <&ps_fab0_soc>; + #reset-cells = <0>; + }; + + ps_avd_sys: power-controller@1d8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1d8 4>; + label = "avd_sys"; + #power-domain-cells = <0>; + power-domains = <&ps_fab1_soc>; + #reset-cells = <0>; + }; + + ps_prores: power-controller@1e0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1e0 4>; + label = "prores"; + #power-domain-cells = <0>; + power-domains = <&ps_fab1_soc>; + #reset-cells = <0>; + }; + + ps_venc1_sys: power-controller@1f0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1f0 4>; + label = "venc1_sys"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_msr1: power-controller@1f8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1f8 4>; + label = "msr1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_msr0_ase_core: power-controller@200 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x200 4>; + label = "msr0_ase_core"; + #power-domain-cells = <0>; + power-domains = <&ps_msr0>; + #reset-cells = <0>; + }; + + ps_msr1_ase_core: power-controller@208 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x208 4>; + label = "msr1_ase_core"; + #power-domain-cells = <0>; + power-domains = <&ps_msr1>; + #reset-cells = <0>; + }; + + ps_amcc0: power-controller@218 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x218 4>; + label = "amcc0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc1: power-controller@220 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x220 4>; + label = "amcc1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc2: power-controller@228 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x228 4>; + label = "amcc2"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc3: power-controller@230 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x230 4>; + label = "amcc3"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afr_amcc_0: power-controller@238 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x238 4>; + label = "fab_afr_amcc_0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afr_amcc_1: power-controller@240 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x240 4>; + label = "fab_afr_amcc_1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afc_amcc_0: power-controller@288 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x288 4>; + label = "fab_afc_amcc_0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc4: power-controller@298 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x298 4>; + label = "amcc4"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc5: power-controller@2a0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2a0 4>; + label = "amcc5"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc6: power-controller@2a8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2a8 4>; + label = "amcc6"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc7: power-controller@2b0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2b0 4>; + label = "amcc7"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afr_amcc_2: power-controller@2b8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2b8 4>; + label = "fab_afr_amcc_2"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afr_amcc_3: power-controller@2c0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2c0 4>; + label = "fab_afr_amcc_3"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afc_amcc_1: power-controller@308 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x308 4>; + label = "fab_afc_amcc_1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc8: power-controller@318 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x318 4>; + label = "amcc8"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc9: power-controller@320 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x320 4>; + label = "amcc9"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc10: power-controller@328 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x328 4>; + label = "amcc10"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc11: power-controller@330 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x330 4>; + label = "amcc11"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afr_amcc_4: power-controller@338 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x338 4>; + label = "fab_afr_amcc_4"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afr_amcc_5: power-controller@340 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x340 4>; + label = "fab_afr_amcc_5"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afc_amcc_2: power-controller@388 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x388 4>; + label = "fab_afc_amcc_2"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc12: power-controller@398 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x398 4>; + label = "amcc12"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc13: power-controller@3a0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3a0 4>; + label = "amcc13"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc14: power-controller@3a8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3a8 4>; + label = "amcc14"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc15: power-controller@3b0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3b0 4>; + label = "amcc15"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afr_amcc_6: power-controller@3b8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3b8 4>; + label = "fab_afr_amcc_6"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afr_amcc_7: power-controller@3c0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3c0 4>; + label = "fab_afr_amcc_7"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afc_amcc_3: power-controller@408 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x408 4>; + label = "fab_afc_amcc_3"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc16: power-controller@418 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x418 4>; + label = "amcc16"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc17: power-controller@420 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x420 4>; + label = "amcc17"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc18: power-controller@428 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x428 4>; + label = "amcc18"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc19: power-controller@430 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x430 4>; + label = "amcc19"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afr_amcc_8: power-controller@438 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x438 4>; + label = "fab_afr_amcc_8"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afr_amcc_9: power-controller@440 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x440 4>; + label = "fab_afr_amcc_9"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afc_amcc_4: power-controller@488 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x488 4>; + label = "fab_afc_amcc_4"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc20: power-controller@498 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x498 4>; + label = "amcc20"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc21: power-controller@4a0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x4a0 4>; + label = "amcc21"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc22: power-controller@4a8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x4a8 4>; + label = "amcc22"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc23: power-controller@4b0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x4b0 4>; + label = "amcc23"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afr_amcc_10: power-controller@4b8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x4b8 4>; + label = "fab_afr_amcc_10"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afr_amcc_11: power-controller@4c0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x4c0 4>; + label = "fab_afr_amcc_11"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afc_amcc_5: power-controller@508 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x508 4>; + label = "fab_afc_amcc_5"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc24: power-controller@518 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x518 4>; + label = "amcc24"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc25: power-controller@520 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x520 4>; + label = "amcc25"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc26: power-controller@528 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x528 4>; + label = "amcc26"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc27: power-controller@530 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x530 4>; + label = "amcc27"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afr_amcc_12: power-controller@538 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x538 4>; + label = "fab_afr_amcc_12"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afr_amcc_13: power-controller@540 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x540 4>; + label = "fab_afr_amcc_13"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afc_amcc_6: power-controller@588 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x588 4>; + label = "fab_afc_amcc_6"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc28: power-controller@598 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x598 4>; + label = "amcc28"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc29: power-controller@5a0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x5a0 4>; + label = "amcc29"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc30: power-controller@5a8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x5a8 4>; + label = "amcc30"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_amcc31: power-controller@5b0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x5b0 4>; + label = "amcc31"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afr_amcc_14: power-controller@5b8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x5b8 4>; + label = "fab_afr_amcc_14"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afr_amcc_15: power-controller@5c0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x5c0 4>; + label = "fab_afr_amcc_15"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_afc_amcc_7: power-controller@610 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x610 4>; + label = "fab_afc_amcc_7"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_fab_b2bd_afc_0: power-controller@648 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x648 4>; + label = "fab_b2bd_afc_0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_fab_b2bd_afc_1: power-controller@650 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x650 4>; + label = "fab_b2bd_afc_1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bd_afc_0: power-controller@658 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x658 4>; + label = "b2bd_afc_0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bd_afc_0_dfx: power-controller@660 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x660 4>; + label = "b2bd_afc_0_dfx"; + #power-domain-cells = <0>; + power-domains = <&ps_b2bd_afc_0>; + #reset-cells = <0>; + }; + + ps_b2bd_afc_1: power-controller@668 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x668 4>; + label = "b2bd_afc_1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bd_afc_1_dfx: power-controller@670 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x670 4>; + label = "b2bd_afc_1_dfx"; + #power-domain-cells = <0>; + power-domains = <&ps_b2bd_afc_1>; + #reset-cells = <0>; + }; + + ps_b2bd_afr_0: power-controller@678 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x678 4>; + label = "b2bd_afr_0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bd_afr_1: power-controller@680 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x680 4>; + label = "b2bd_afr_1"; + #power-domain-cells = <0>; + power-domains = <&ps_b2bd_afr_0>; + #reset-cells = <0>; + }; + + ps_b2bd_afr_dfx_0: power-controller@688 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x688 4>; + label = "b2bd_afr_dfx_0"; + #power-domain-cells = <0>; + power-domains = <&ps_b2bd_afr_0>; + #reset-cells = <0>; + }; + + ps_b2bd_afr_dfx_1: power-controller@690 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x690 4>; + label = "b2bd_afr_dfx_1"; + #power-domain-cells = <0>; + power-domains = <&ps_b2bd_afr_1>; + #reset-cells = <0>; + }; + + ps_b2bd_afr_3: power-controller@698 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x698 4>; + label = "b2bd_afr_3"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bd_afr_2: power-controller@6a0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x6a0 4>; + label = "b2bd_afr_2"; + #power-domain-cells = <0>; + power-domains = <&ps_b2bd_afr_3>; + #reset-cells = <0>; + }; + + ps_b2bd_afr_dfx_3: power-controller@6a8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x6a8 4>; + label = "b2bd_afr_dfx_3"; + #power-domain-cells = <0>; + power-domains = <&ps_b2bd_afr_3>; + #reset-cells = <0>; + }; + + ps_b2bd_afr_dfx_2: power-controller@6b0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x6b0 4>; + label = "b2bd_afr_dfx_2"; + #power-domain-cells = <0>; + power-domains = <&ps_b2bd_afr_2>; + #reset-cells = <0>; + }; + + ps_b2bg_dft: power-controller@6b8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x6b8 4>; + label = "b2bg_dft"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bg_cntl_dfx: power-controller@6c0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x6c0 4>; + label = "b2bg_cntl_dfx"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bg_dbg_0: power-controller@6c8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x6c8 4>; + label = "b2bg_dbg_0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bg_dbg_1: power-controller@6d0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x6d0 4>; + label = "b2bg_dbg_1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bg_dbg_2: power-controller@6d8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x6d8 4>; + label = "b2bg_dbg_2"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bd_cntl_dfx_0: power-controller@6e0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x6e0 4>; + label = "b2bd_cntl_dfx_0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bd_cntl_dfx_1: power-controller@6e8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x6e8 4>; + label = "b2bd_cntl_dfx_1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bd_dbg_0: power-controller@6f0 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x6f0 4>; + label = "b2bd_dbg_0"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bd_dbg_1: power-controller@6f8 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x6f8 4>; + label = "b2bd_dbg_1"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bd_dbg_2: power-controller@700 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x700 4>; + label = "b2bd_dbg_2"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bd_dbg_3: power-controller@708 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x708 4>; + label = "b2bd_dbg_3"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_b2bd_dbg_4: power-controller@710 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x710 4>; + label = "b2bd_dbg_4"; + #power-domain-cells = <0>; + #reset-cells = <0>; + }; + + ps_venc0_dma: power-controller@8000 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8000 4>; + label = "venc0_dma"; + #power-domain-cells = <0>; + power-domains = <&ps_venc0_sys>; + #reset-cells = <0>; + }; + + ps_venc0_pipe4: power-controller@8008 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8008 4>; + label = "venc0_pipe4"; + #power-domain-cells = <0>; + power-domains = <&ps_venc0_dma>; + #reset-cells = <0>; + }; + + ps_venc0_pipe5: power-controller@8010 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8010 4>; + label = "venc0_pipe5"; + #power-domain-cells = <0>; + power-domains = <&ps_venc0_dma>; + #reset-cells = <0>; + }; + + ps_venc0_me0: power-controller@8018 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8018 4>; + label = "venc0_me0"; + #power-domain-cells = <0>; + power-domains = <&ps_venc0_dma>; + #reset-cells = <0>; + }; + + ps_venc0_me1: power-controller@8020 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8020 4>; + label = "venc0_me1"; + #power-domain-cells = <0>; + power-domains = <&ps_venc0_me0>; + #reset-cells = <0>; + }; + + ps_venc1_dma: power-controller@8028 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8028 4>; + label = "venc1_dma"; + #power-domain-cells = <0>; + power-domains = <&ps_venc1_sys>; + #reset-cells = <0>; + }; + + ps_venc1_pipe4: power-controller@8030 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8030 4>; + label = "venc1_pipe4"; + #power-domain-cells = <0>; + power-domains = <&ps_venc1_dma>; + #reset-cells = <0>; + }; + + ps_venc1_pipe5: power-controller@8038 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8038 4>; + label = "venc1_pipe5"; + #power-domain-cells = <0>; + power-domains = <&ps_venc1_dma>; + #reset-cells = <0>; + }; + + ps_venc1_me0: power-controller@8040 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8040 4>; + label = "venc1_me0"; + #power-domain-cells = <0>; + power-domains = <&ps_venc1_dma>; + #reset-cells = <0>; + }; + + ps_venc1_me1: power-controller@8048 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8048 4>; + label = "venc1_me1"; + #power-domain-cells = <0>; + power-domains = <&ps_venc1_me0>; + #reset-cells = <0>; + }; +}; + +&pmgr5 { + ps_debug_gfx_gated: power-controller@58 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x58 4>; + label = "debug_gfx_gated"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; + + ps_nub_gfx_gpio: power-controller@68 { + compatible = "apple,t6050-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x68 4>; + label = "nub_gfx_gpio"; + #power-domain-cells = <0>; + #reset-cells = <0>; + apple,always-on; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t6050-smc.dtsi b/arch/arm64/boot/dts/apple/t6050-smc.dtsi new file mode 100644 index 00000000000000..eb1b94b01a1414 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6050-smc.dtsi @@ -0,0 +1,175 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * T6050 SMC (System Management Controller) and the SPMI PMIC NVMEM cells + * its reboot and RTC children need, from the J714c ADT. Based on + * omarchy-m5's dt/t6050-smc.dtsi (github.com/betizzel/omarchy-m5); the + * structure follows t6031-die0.dtsi and t8122.dtsi. + * + * Board files add hwmon sensors (hwmon-*.dtsi) on top of &smc_hwmon. The + * T6050 SMC has no F0Md/F1Md: its fan mode keys are F0md/F1md (ui8, + * writable), so every T6050 board overrides apple,fan-mode after including + * hwmon-fan*.dtsi. + */ + +#include + +&soc { + // ADT /arm-io/nub-spmi0: compatible "aapl,spmi", gen = 4, + // reg[0] = 0x8a014000 (-> 0x28a014000), ADT size 0x4000. The full + // ADT size is used: the gen 4 FIFO registers below sit at 0x200-0x220, + // outside the 0x100 window t6031 maps for its gen 1 layout (a 0x100 + // resource only worked because ioremap maps a whole 16K page). + // interrupts = [256, 726, 281, ...]: 256 is the controller-internal + // SPMI_IRQ_NOTIFY hwirq (identical in all five SPMI nodes), 726 is the + // AIC line (same index convention as wdt: ADT interrupts[0] = 721). + // This is a gen 4 controller (ADT "gen" = 4): STATUS/CMD/REPLY sit at + // 0x200/0x210/0x220 and RX-empty is bit 30 (as in m1n1). The + // gen 1 layout (t8103) does not apply, so there is no fallback + // compatible. Linux runs gen 4 polled: its IRQ registers are + // undocumented. + // + // No power-domains: the ADT node has no power-gates, and ps_nub_spmi0 + // (pmgr 0x120, boot value 0x1400024f = auto-PM + clock-gated) is + // apple,always-on in t6050-pmgr.dtsi. t6031's equivalent node also has + // none. Referencing it would only add a genpd dependency. + nub_spmi0: spmi@28a014000 { + /* Polled: this tree's gen 4 SPMI driver has no interrupt support. */ + compatible = "apple,t6050-spmi", "apple,t8142-spmi"; + reg = <0x2 0x8a014000 0x0 0x4000>; + #address-cells = <2>; + #size-cells = <0>; + + // ADT /arm-io/nub-spmi0/spmi-abbeyL1: compatible + // "pmu,spmi","pmu,abbey", reg[0] = 0xe -> USID 14, is-primary. + // (spmi-mosquitoM0 = USID 9, btm = USID 0xb on the same bus.) + // + // Cell offsets are the Asahi "chapel" layout (t6031-die0.dtsi); + // the ADT abbey properties confirm the ones it lists: + // info-pm_setting = 0x2001 + // info-clock_offset = {0x2100, 6} (info-rtc_scrpad + // 0x2100) + // info-fault_shadow = {0x867b, 0x10} + // info-scrpad_socd = {0x8b00, 0x1800} + // info-leg_scrpad = 0xf800 -> boot_stage 0xf801 etc. + // are + // base+1/+2/+3/+0xf as on chapel/stowe + // (the +N offsets are not in the ADT) + pmic1: pmic@e { + compatible = "apple,abbey-pmic", "apple,spmi-nvmem"; + reg = <0xe SPMI_USID>; + + nvmem-layout { + compatible = "fixed-layout"; + #address-cells = <1>; + #size-cells = <1>; + + pm_setting: pm-setting@2001 { + reg = <0x2001 0x1>; + }; + + rtc_offset: rtc-offset@2100 { + reg = <0x2100 0x6>; + }; + + fault_shadow: fault-shadow@867b { + reg = <0x867b 0x10>; + }; + + socd: socd@8b00 { + reg = <0x8b00 0x1800>; + }; + + boot_stage: boot-stage@f801 { + reg = <0xf801 0x1>; + }; + + boot_error_count: boot-error-count@f802,0 { + reg = <0xf802 0x1>; + bits = <0 4>; + }; + + panic_count: panic-count@f802,4 { + reg = <0xf802 0x1>; + bits = <4 4>; + }; + + boot_error_stage: boot-error-stage@f803 { + reg = <0xf803 0x1>; + }; + + shutdown_flag: shutdown-flag@f80f,3 { + reg = <0xf80f 0x1>; + bits = <3 1>; + }; + }; + }; + }; + + // "smc" reg: ASC wrapper (driver does not map it; only index 1 is + // ioremapped). "sram" reg: ADT iop-smc-nub region-base = 0x28de00000, + // region-size = 0x140000 (Asahi uses 0x100000 on M1-M4; the T6050 + // firmware region is 0x140000, and the driver rejects any shmem buffer + // outside this window). smc_gpio is deliberately defined here although + // nothing consumes it yet. + smc: smc@28c600000 { + compatible = "apple,t6050-smc", "apple,t8103-smc"; + reg = <0x2 0x8c600000 0x0 0x4000>, + <0x2 0x8de00000 0x0 0x140000>; + reg-names = "smc", "sram"; + mboxes = <&smc_mbox>; + + smc_gpio: gpio { + compatible = "apple,smc-gpio"; + #gpio-cells = <2>; + gpio-controller; + }; + + smc_hwmon: hwmon { + compatible = "apple,smc-hwmon"; + }; + + // Registers SYS_OFF_PRIO_HIGH (192) restart + power-off + // handlers; the apple,t6050-wdt restart handler is priority + // 128 (apple_wdt.c), so once this probes, + // `reboot` goes through SMC 'phra' instead of the wdt. + // Kept disabled until an SMC 'phra' restart is shown to land + // in stage-1 m1n1 like the wdt reset does (remote reboots + // depend on that). It also writes boot_stage/shutdown_flag in + // the PMIC scratchpad, whose offsets are not yet verified. + smc_reboot: reboot { + compatible = "apple,smc-reboot"; + nvmem-cells = <&shutdown_flag>, <&boot_stage>, + <&boot_error_count>, <&panic_count>; + nvmem-cell-names = "shutdown_flag", "boot_stage", + "boot_error_count", "panic_count"; + + status = "disabled"; + }; + + smc_rtc: rtc { + compatible = "apple,smc-rtc"; + nvmem-cells = <&rtc_offset>; + nvmem-cell-names = "rtc_offset"; + }; + }; + + // ADT /arm-io/smc: compatible "iop,ascwrap-v6" (same as ans/mtp), + // reg[0] = 0x8c600000 (ASC wrapper, size 0x88000), mailbox at + // reg[0] + 0x8000 exactly like ans_mbox/mtp_mbox (as in m1n1), + // interrupts = [900, 899, 902, 901] = [n+1, n, n+3, n+2] with n = 899, + // so send-empty = 899 ... recv-not-empty = 902 (same reordering as + // ANS 1348,1347,1350,1349 -> 1347..1350 and MTP 677,676,679,678). + // No power-gates / clock-gates in the ADT node -> no power-domains. + smc_mbox: mbox@28c608000 { + compatible = "apple,t6050-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <0x2 0x8c608000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = , + , + , + ; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t6050.dtsi b/arch/arm64/boot/dts/apple/t6050.dtsi new file mode 100644 index 00000000000000..70ba4e4d37106d --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6050.dtsi @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Apple T6050 "M5 Max" SoC + * + * Copyright The Asahi Linux Contributors + */ + +#include +#include + +#include "t6050-base.dtsi" + +/ { + compatible = "apple,t6050", "apple,arm-platform"; + #address-cells = <2>; + #size-cells = <2>; + + soc: soc { + compatible = "simple-bus"; + ranges; + #address-cells = <2>; + /* Required to get >32-bit DMA via DARTs */ + dma-ranges = <0 0 0 0 0xffffffff 0xffffc000>; + nonposted-mmio; + #size-cells = <2>; + }; +}; + +/* T6050 is a single die: no multi-die templating. */ +#include "t6050-die0.dtsi" +#include "t6050-pmgr.dtsi" +#include "t6050-nvme.dtsi" diff --git a/drivers/cpufreq/apple-soc-cpufreq.c b/drivers/cpufreq/apple-soc-cpufreq.c index b0080dbdaeac74..234818235c9429 100644 --- a/drivers/cpufreq/apple-soc-cpufreq.c +++ b/drivers/cpufreq/apple-soc-cpufreq.c @@ -353,6 +353,11 @@ static const struct of_device_id apple_soc_cpufreq_of_match[] __maybe_unused = { .compatible = "apple,t8142-cluster-cpufreq", .data = &soc_t8142_info, }, + { + /* T6050: same command/readback model as T8142, CLPC/PMP keep the rest. */ + .compatible = "apple,t6050-cluster-cpufreq", + .data = &soc_t8142_info, + }, { .compatible = "apple,t8152-cluster-cpufreq", .data = &soc_t8152_info, diff --git a/drivers/gpu/drm/sysfb/simpledrm.c b/drivers/gpu/drm/sysfb/simpledrm.c index bb32b258a9b5f8..27208f700de457 100644 --- a/drivers/gpu/drm/sysfb/simpledrm.c +++ b/drivers/gpu/drm/sysfb/simpledrm.c @@ -839,8 +839,10 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv, /* Connector */ connector = &sdev->connector; + /* A built-in laptop panel the loader hands over (Apple, before DCP). */ ret = drm_connector_init(dev, connector, &simpledrm_connector_funcs, - DRM_MODE_CONNECTOR_Unknown); + of_property_read_bool(dev->dev->of_node, "apple,internal-panel") ? + DRM_MODE_CONNECTOR_eDP : DRM_MODE_CONNECTOR_Unknown); if (ret) return ERR_PTR(ret); drm_connector_helper_add(connector, &simpledrm_connector_helper_funcs); diff --git a/drivers/media/platform/apple/isp/Kconfig b/drivers/media/platform/apple/isp/Kconfig index b51d19ee115ded..3967e51d472cf9 100644 --- a/drivers/media/platform/apple/isp/Kconfig +++ b/drivers/media/platform/apple/isp/Kconfig @@ -8,15 +8,18 @@ config VIDEO_APPLE_ISP select APPLE_PMP_REPORT depends on ARCH_APPLE || COMPILE_TEST depends on OF_ADDRESS + depends on PM depends on V4L_PLATFORM_DRIVERS depends on VIDEO_DEV help Driver for the image signal processor that runs the built-in camera of Apple silicon machines. The ISP firmware is loaded by the bootloader. When a stream starts, the driver loads the - calibration file for the detected camera module, + sensor tuning file for the detected camera model, apple/isp__XX.dat, from the firmware search - path; if it is missing, the stream runs without calibration. + path; if it is missing, the stream runs without sensor tuning. + Invalid files and firmware upload errors fail the stream setup. + These setfiles do not contain per-module factory calibration. config VIDEO_APPLE_ISP_KUNIT_TEST bool "KUnit tests for the Apple ISP driver" if !KUNIT_ALL_TESTS @@ -24,9 +27,10 @@ config VIDEO_APPLE_ISP_KUNIT_TEST depends on KUNIT=y || VIDEO_APPLE_ISP=m default KUNIT_ALL_TESTS help - Builds unit tests for the videobuf2 queue set-up and for the - shared memory the firmware frees into the Apple ISP driver. They - need no hardware. Only useful for kernel developers running KUnit. + Builds unit tests for queue setup, P010 layouts and buffer identity, + firmware sensor geometry, the capture command stream, shared memory + retirement and the per-SoC DART address filter windows. The command + tests stub the IPC transport and need no hardware. Only useful for kernel developers running KUnit. If unsure, say N. diff --git a/drivers/media/platform/apple/isp/isp-cam-test.c b/drivers/media/platform/apple/isp/isp-cam-test.c new file mode 100644 index 00000000000000..191d8ada0d2654 --- /dev/null +++ b/drivers/media/platform/apple/isp/isp-cam-test.c @@ -0,0 +1,680 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Synthetic geometry checks: no camera firmware or setfile data. */ +#include +#include +#include +#include "isp-ipc.h" + +static void isp_test_sensor_geometry(struct kunit *test) +{ + struct cmd_ch_camera_config config = { + .in_width = 1920, .in_height = 2160, + .out_width = 1920, .out_height = 1080, + .in_width2 = 1920, .in_height2 = 2160, + .out_width2 = 1920, .out_height2 = 1080, + }; + + KUNIT_EXPECT_TRUE(test, isp_sensor_config_usable(&config)); + /* A future larger output is accepted only when both descriptions agree. */ + config.in_width = 4096; + config.in_width2 = 4096; + config.in_height = 3072; + config.in_height2 = 3072; + config.out_width = 4096; + config.out_width2 = 4096; + config.out_height = 3072; + config.out_height2 = 3072; + KUNIT_EXPECT_TRUE(test, isp_sensor_config_usable(&config)); + config.out_height2 = 2160; + KUNIT_EXPECT_FALSE(test, isp_sensor_config_usable(&config)); + config.out_height2 = 3072; + config.in_height2 = 2160; + KUNIT_EXPECT_FALSE(test, isp_sensor_config_usable(&config)); + config.in_height2 = 3072; + config.out_width = 4097; + config.out_width2 = 4097; + KUNIT_EXPECT_FALSE(test, isp_sensor_config_usable(&config)); + config.out_width = 0; + config.out_width2 = 0; + KUNIT_EXPECT_FALSE(test, isp_sensor_config_usable(&config)); + config.out_width = 8192; + config.out_width2 = 8192; + KUNIT_EXPECT_FALSE(test, isp_sensor_config_usable(&config)); +} + +struct isp_test_command { + u32 words[39]; + u32 size; +}; + +/* Derived from the proxy command fixture, with contiguous V4L2 plane sizes. */ +static const struct isp_test_command isp_test_preview_commands[] = { + {{0, 0x24, 0}, 0xc}, + {{0, 0x13b, 0, 1}, 0x10}, + {{0, 0x107, 0, 5}, 0x10}, + {{0, 0x10e, 0, 1}, 0x10}, + {{0, 0x10f, 0}, 0xc}, + {{0, 0x80c, 0, 0, 0, 1280, 720}, 0x1c}, + {{0, 0xb09, 0, 1280, 720, 1, 0x12, 2560, 2560, 0, 0, 720, 0, 1280}, 0x38}, + {{0, 0x208, 0, 7680}, 0x10}, + {{0, 0x20a, 0, 3840}, 0x10}, + {{[1] = 0x117, [3] = 8 << 16, [4] = 0x8000, [5] = 0x8000, [37] = 1}, 0x9c}, + {{[1] = 0x117, [3] = 9 | 2 << 16, [4] = 1843200, [5] = 2560, + [12] = 921600, [13] = 2560, [37] = 2}, 0x9c}, + {{0, 0x125, 0, 1}, 0x10}, + {{0, 0xb0d, 0, 1}, 0x10}, + {{0, 0x138, 0, 0}, 0x10}, +}; + +struct isp_test_command_trace { + unsigned int count; + unsigned int fail_at; + int setfile_error; + unsigned int setfile_calls; + u32 last_opcode; +}; + +static int isp_test_send(struct apple_isp *isp, void *args, u32 insize, + u32 outsize, int timeout) +{ + struct kunit *test = kunit_get_current_test(); + struct isp_test_command_trace *trace = test->priv; + const struct isp_test_command *expected; + u32 expected_outsize; + + if (trace->count >= ARRAY_SIZE(isp_test_preview_commands)) { + KUNIT_FAIL(test, "unexpected extra command"); + return -EIO; + } + expected = &isp_test_preview_commands[trace->count++]; + KUNIT_EXPECT_EQ(test, insize, expected->size); + expected_outsize = expected->words[1] == 0x117 || + (expected->words[1] == 0x24 && !isp_is_p010(isp)) ? insize : 0; + KUNIT_EXPECT_EQ(test, outsize, expected_outsize); + if (insize == expected->size) + KUNIT_EXPECT_MEMEQ(test, args, expected->words, insize); + if (trace->count == trace->fail_at) + return -ETIME; + return 0; +} + +static void isp_test_free_controls(void *ptr) +{ + v4l2_ctrl_handler_free(ptr); +} + +static struct apple_isp *isp_test_capture_alloc(struct kunit *test) +{ + static const struct apple_isp_hw hw = { + .gen = ISP_GEN_T6040, .fw_abi = ISP_FW_ABI_H17, + .scl1 = true, .meta_size = ISP_META_SIZE_T8140, + }; + static struct isp_preset preset = { + .index = 5, .input_dim = {1920, 2160}, + .output_dim = {1280, 720}, .crop_size = {1280, 720}, + }; + struct apple_isp *isp = kunit_kzalloc(test, sizeof(*isp), GFP_KERNEL); + struct isp_format *fmt; + int err; + + KUNIT_ASSERT_NOT_NULL(test, isp); + isp->dev = kunit_device_register(test, "apple-isp-camera-test"); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, isp->dev); + isp->hw = &hw; + isp->frame_rate = 30; + fmt = isp_get_current_format(isp); + fmt->version = 0x958; + fmt->pixelformat = V4L2_PIX_FMT_P010; + fmt->preset = &preset; + fmt->strides[0] = 2560; + fmt->strides[1] = 2560; + fmt->plane_size[0] = 1843200; + fmt->plane_size[1] = 921600; + v4l2_ctrl_handler_init(&isp->ctrl_handler, 1); + err = kunit_add_action_or_reset(test, isp_test_free_controls, &isp->ctrl_handler); + KUNIT_ASSERT_EQ(test, err, 0); + isp->exposure_priority = + v4l2_ctrl_new_std(&isp->ctrl_handler, NULL, + V4L2_CID_EXPOSURE_AUTO_PRIORITY, 0, 1, 1, 1); + KUNIT_ASSERT_EQ(test, isp->ctrl_handler.error, 0); + kunit_activate_static_stub(test, isp_cmd_send, isp_test_send); + return isp; +} + +static void isp_test_preview_stream(struct kunit *test) +{ + struct apple_isp *isp = isp_test_capture_alloc(test); + struct isp_test_command_trace trace = {}; + + test->priv = &trace; + KUNIT_EXPECT_EQ(test, isp_ch_configure_capture(isp, 0), 0); + KUNIT_EXPECT_EQ(test, trace.count, ARRAY_SIZE(isp_test_preview_commands)); +} + +static void isp_test_preview_command_failures(struct kunit *test) +{ + struct apple_isp *isp = isp_test_capture_alloc(test); + struct isp_test_command_trace trace; + + test->priv = &trace; + for (unsigned int i = 1; i <= ARRAY_SIZE(isp_test_preview_commands); i++) { + trace = (struct isp_test_command_trace){ .fail_at = i }; + KUNIT_EXPECT_EQ(test, isp_ch_configure_capture(isp, 0), -ETIME); + KUNIT_EXPECT_EQ(test, trace.count, i); + } +} + +static int isp_test_load_setfile(struct apple_isp *isp, u32 ch) +{ + struct kunit *test = kunit_get_current_test(); + struct isp_test_command_trace *trace = test->priv; + + trace->setfile_calls++; + return trace->setfile_error; +} + +static void isp_test_setfile_failure_stops_setup(struct kunit *test) +{ + static const int errors[] = { -EINVAL, -EIO, -ETIME, -EINTR, -ENOMEM }; + struct apple_isp *isp = isp_test_capture_alloc(test); + struct isp_test_command_trace trace; + + isp_get_current_format(isp)->pixelformat = V4L2_PIX_FMT_NV12; + kunit_activate_static_stub(test, isp_ch_load_setfile, isp_test_load_setfile); + test->priv = &trace; + for (unsigned int i = 0; i < ARRAY_SIZE(errors); i++) { + trace = (struct isp_test_command_trace){ .setfile_error = errors[i] }; + KUNIT_EXPECT_EQ(test, isp_ch_configure_capture(isp, 0), errors[i]); + /* Only the flicker command preceded the rejected tuning. */ + KUNIT_EXPECT_EQ(test, trace.count, 1); + KUNIT_EXPECT_EQ(test, trace.setfile_calls, 1); + } +} + +/* Count NV12 setup commands and fail the chosen one, without a fixture. */ +static int isp_test_count_send(struct apple_isp *isp, void *args, u32 insize, + u32 outsize, int timeout) +{ + struct kunit *test = kunit_get_current_test(); + struct isp_test_command_trace *trace = test->priv; + + trace->last_opcode = ((const u32 *)args)[1]; + if (++trace->count == trace->fail_at) + return -ETIME; + return 0; +} + +static void isp_test_optional_setfile_continues_setup(struct kunit *test) +{ + static const int results[] = { 0, -ENOENT }; + struct apple_isp *isp = isp_test_capture_alloc(test); + struct isp_test_command_trace trace; + + isp_get_current_format(isp)->pixelformat = V4L2_PIX_FMT_NV12; + kunit_activate_static_stub(test, isp_ch_load_setfile, isp_test_load_setfile); + kunit_activate_static_stub(test, isp_cmd_send, isp_test_count_send); + test->priv = &trace; + for (unsigned int i = 0; i < ARRAY_SIZE(results); i++) { + trace = (struct isp_test_command_trace){ + .setfile_error = results[i], .fail_at = 2, + }; + /* The mains frequency after tuning, rather than tuning, fails. */ + KUNIT_EXPECT_EQ(test, isp_ch_configure_capture(isp, 0), -ETIME); + KUNIT_EXPECT_EQ(test, trace.count, 2); + KUNIT_EXPECT_EQ(test, trace.last_opcode, 0x8212); + KUNIT_EXPECT_EQ(test, trace.setfile_calls, 1); + } +} + +struct isp_test_nv12_trace { + unsigned int count; + u32 opcode[64]; + u32 size[64]; + u32 word[64][3]; +}; + +/* Accept every NV12 setup command and record its opcode and first fields. */ +static int isp_test_record(struct apple_isp *isp, void *args, u32 insize, + u32 outsize, int timeout) +{ + struct kunit *test = kunit_get_current_test(); + struct isp_test_nv12_trace *trace = test->priv; + const u32 *words = args; + unsigned int i = trace->count; + + if (i >= ARRAY_SIZE(trace->opcode)) { + KUNIT_FAIL(test, "unexpected extra command"); + return -EIO; + } + trace->opcode[i] = words[1]; + trace->size[i] = insize; + for (unsigned int j = 0; j < 3 && 12 + 4 * j < insize; j++) + trace->word[i][j] = words[3 + j]; + trace->count++; + return 0; +} + +static int isp_test_find(const struct isp_test_nv12_trace *trace, u32 opcode) +{ + for (unsigned int i = 0; i < trace->count; i++) + if (trace->opcode[i] == opcode) + return i; + return -1; +} + +static int isp_test_no_setfile(struct apple_isp *isp, u32 ch) +{ + return 0; +} + +static struct apple_isp *isp_test_nv12_alloc(struct kunit *test, + enum isp_sensor_id id) +{ + struct apple_isp *isp = isp_test_capture_alloc(test); + struct isp_format *fmt = isp_get_current_format(isp); + + fmt->pixelformat = V4L2_PIX_FMT_NV12; + fmt->id = id; + fmt->version = isp_setfiles[id].version; + isp->temporal_filter = 1; + kunit_activate_static_stub(test, isp_ch_load_setfile, isp_test_no_setfile); + kunit_activate_static_stub(test, isp_cmd_send, isp_test_record); + return isp; +} + +/* Expect exactly @n commands, in this order, from the first of them on. */ +static void isp_test_expect_run(struct kunit *test, + const struct isp_test_nv12_trace *trace, + const u32 (*run)[2], unsigned int n) +{ + int first = isp_test_find(trace, run[0][0]); + + KUNIT_ASSERT_GE(test, first, 0); + KUNIT_ASSERT_LE(test, first + n, trace->count); + for (unsigned int i = 0; i < n; i++) { + KUNIT_EXPECT_EQ(test, trace->opcode[first + i], run[i][0]); + KUNIT_EXPECT_EQ(test, trace->size[first + i], run[i][1]); + } +} + +static void isp_test_temporal_filter_band0(struct kunit *test) +{ + static const u32 run[][2] = { + { 0xc100, 0x18 }, { 0xc120, 0x10 }, { 0xc11c, 0x10 }, + { 0xc11d, 0x14 }, { 0xc102, 0x0c }, { 0xc113, 0x0c }, + }; + struct apple_isp *isp = isp_test_nv12_alloc(test, ISP_IMX958_2224_01); + struct isp_test_nv12_trace *trace; + int i; + + trace = kunit_kzalloc(test, sizeof(*trace), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, trace); + test->priv = trace; + KUNIT_EXPECT_EQ(test, isp_ch_configure_capture(isp, 0), 0); + isp_test_expect_run(test, trace, run, ARRAY_SIZE(run)); + /* The start record is (1, 0, 0) whatever the DT property says. */ + i = isp_test_find(trace, 0xc100); + KUNIT_EXPECT_EQ(test, trace->word[i][0], 1); + KUNIT_EXPECT_EQ(test, trace->word[i][1], 0); + KUNIT_EXPECT_EQ(test, trace->word[i][2], 0); + i = isp_test_find(trace, 0xc11d); + KUNIT_EXPECT_EQ(test, trace->word[i][0], 0x7800); + KUNIT_EXPECT_EQ(test, trace->word[i][1], 0x6400); + KUNIT_EXPECT_LT(test, isp_test_find(trace, 0xc114), 0); +} + +static void isp_test_temporal_filter_off(struct kunit *test) +{ + static const u32 run[][2] = { + { 0xc114, 0x0c }, { 0xc103, 0x0c }, { 0xc101, 0x0c }, + }; + struct apple_isp *isp = isp_test_nv12_alloc(test, ISP_IMX558_1925_03); + struct isp_test_nv12_trace *trace; + + trace = kunit_kzalloc(test, sizeof(*trace), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, trace); + test->priv = trace; + KUNIT_EXPECT_EQ(test, isp_ch_configure_capture(isp, 0), 0); + isp_test_expect_run(test, trace, run, ARRAY_SIZE(run)); + KUNIT_EXPECT_LT(test, isp_test_find(trace, 0xc100), 0); + KUNIT_EXPECT_LT(test, isp_test_find(trace, 0xc102), 0); + KUNIT_EXPECT_LT(test, isp_test_find(trace, 0xc113), 0); +} + +static void isp_test_power_line_frequency(struct kunit *test) +{ + struct apple_isp *isp = isp_test_nv12_alloc(test, ISP_IMX958_2224_01); + struct isp_test_nv12_trace *trace; + int i; + + trace = kunit_kzalloc(test, sizeof(*trace), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, trace); + test->priv = trace; + + /* No control: 50 Hz, in Hz 16.16 */ + KUNIT_EXPECT_EQ(test, isp_ch_configure_capture(isp, 0), 0); + i = isp_test_find(trace, 0x8212); + KUNIT_ASSERT_GE(test, i, 0); + KUNIT_EXPECT_EQ(test, trace->size[i], 0x10); + KUNIT_EXPECT_EQ(test, trace->word[i][0], 0x00320000); + /* After the tuning, before the sensor configuration is selected */ + KUNIT_EXPECT_LT(test, i, isp_test_find(trace, 0x107)); + + isp->power_line_frequency = + v4l2_ctrl_new_std_menu(&isp->ctrl_handler, NULL, + V4L2_CID_POWER_LINE_FREQUENCY, + V4L2_CID_POWER_LINE_FREQUENCY_60HZ, + BIT(V4L2_CID_POWER_LINE_FREQUENCY_DISABLED), + V4L2_CID_POWER_LINE_FREQUENCY_50HZ); + KUNIT_ASSERT_NOT_NULL(test, isp->power_line_frequency); + KUNIT_ASSERT_EQ(test, v4l2_ctrl_s_ctrl(isp->power_line_frequency, + V4L2_CID_POWER_LINE_FREQUENCY_60HZ), 0); + memset(trace, 0, sizeof(*trace)); + KUNIT_EXPECT_EQ(test, isp_ch_configure_capture(isp, 0), 0); + i = isp_test_find(trace, 0x8212); + KUNIT_ASSERT_GE(test, i, 0); + KUNIT_EXPECT_EQ(test, trace->word[i][0], 0x003c0000); +} + +static int isp_test_config_reply(struct apple_isp *isp, void *args, u32 insize, + u32 outsize, int timeout) +{ + struct kunit *test = kunit_get_current_test(); + u32 *count = test->priv; + struct cmd_ch_camera_config_h17 *reply = isp->cmd_virt; + struct cmd_ch_camera_config *config = &reply->config; + + KUNIT_EXPECT_EQ(test, insize, 0x120); + KUNIT_EXPECT_EQ(test, outsize, 0x120); + memcpy(reply, args, sizeof(*reply)); + KUNIT_EXPECT_EQ(test, config->preset, (*count)++); + config->in_width = 1920; + config->in_height = 2160; + config->out_width = 1920; + config->out_height = 1080; + if (config->preset == 1) { + config->in_width = 4096; + config->in_height = 3072; + config->out_width = 4096; + config->out_height = 3072; + } + config->in_width2 = config->in_width; + config->in_height2 = config->in_height; + config->out_width2 = config->out_width; + config->out_height2 = config->out_height; + if (config->preset == 2) + config->out_height2 = 2160; + reply->unknown[sizeof(reply->unknown) - 1] = 0x5a; + return 0; +} + +static void isp_test_free_configs(void *ptr) +{ + kfree(ptr); +} + +static void isp_test_sensor_config_list(struct kunit *test) +{ + struct apple_isp *isp = isp_test_capture_alloc(test); + struct isp_preset presets[] = { + { .index = 5, .input_dim = {1920, 2160}, + .output_dim = {1920, 1080}, .crop_size = {1920, 1080} }, + { .index = 5, .input_dim = {1920, 2160}, + .output_dim = {1280, 720}, .crop_size = {1280, 720} }, + }; + u32 count = 0; + int err; + + isp->cmd_virt = kunit_kzalloc(test, 0x120, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, isp->cmd_virt); + isp->presets = presets; + isp->num_presets = ARRAY_SIZE(presets); + test->priv = &count; + kunit_activate_static_stub(test, isp_cmd_send, isp_test_config_reply); + KUNIT_ASSERT_EQ(test, isp_ch_cache_sensor_configs(isp, 0, 6), 0); + err = kunit_add_action_or_reset(test, isp_test_free_configs, isp->sensor_configs); + KUNIT_ASSERT_EQ(test, err, 0); + KUNIT_EXPECT_EQ(test, get_unaligned_le32(isp->sensor_configs[5].reply + 0xc), 5); + KUNIT_EXPECT_EQ(test, isp->sensor_configs[5].reply[ISP_SENSOR_CONFIG_SIZE - 1], 0x5a); + KUNIT_EXPECT_EQ(test, count, 6); + KUNIT_EXPECT_EQ(test, isp->num_sensor_configs, 6); + KUNIT_EXPECT_EQ(test, isp->num_presets, 3); + KUNIT_EXPECT_EQ(test, isp->presets[0].index, 5); + KUNIT_EXPECT_EQ(test, isp->presets[0].output_dim.y, 1080); + KUNIT_EXPECT_TRUE(test, isp->presets[1].p010); + KUNIT_EXPECT_TRUE(test, isp->presets[2].p010); + KUNIT_EXPECT_EQ(test, isp->presets[2].index, 1); + KUNIT_EXPECT_EQ(test, isp->presets[2].output_dim.x, 4096); + KUNIT_EXPECT_EQ(test, isp->presets[2].crop_size.y, 3072); + KUNIT_EXPECT_FALSE(test, isp->sensor_configs[2].usable); + KUNIT_EXPECT_EQ(test, isp_ch_cache_sensor_configs(isp, 0, 0), -EINVAL); + KUNIT_EXPECT_EQ(test, isp_ch_cache_sensor_configs(isp, 0, 65), -EINVAL); + KUNIT_EXPECT_EQ(test, count, 6); +} + +static int isp_test_bad_config_reply(struct apple_isp *isp, void *args, u32 insize, + u32 outsize, int timeout) +{ + struct cmd_ch_camera_config_h17 *reply = isp->cmd_virt; + + isp_test_config_reply(isp, args, insize, outsize, timeout); + reply->config.preset = 65; + return 0; +} + +static void isp_test_sensor_config_failure(struct kunit *test) +{ + struct apple_isp *isp = isp_test_capture_alloc(test); + struct isp_preset preset = {}; + u32 count = 0; + + isp->cmd_virt = kunit_kzalloc(test, ISP_SENSOR_CONFIG_SIZE, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, isp->cmd_virt); + isp->presets = &preset; + isp->num_presets = 1; + test->priv = &count; + kunit_activate_static_stub(test, isp_cmd_send, isp_test_bad_config_reply); + KUNIT_EXPECT_EQ(test, isp_ch_cache_sensor_configs(isp, 0, 6), -EIO); + KUNIT_EXPECT_EQ(test, count, 1); + KUNIT_EXPECT_EQ(test, isp->num_sensor_configs, 0); + KUNIT_EXPECT_PTR_EQ(test, isp->sensor_configs, NULL); + KUNIT_EXPECT_PTR_EQ(test, isp->presets, &preset); +} + +struct isp_test_ack_state { + unsigned int fault, calls; +}; + +static int isp_test_ack_reply(struct apple_isp *isp, struct isp_channel *chan, + unsigned long timeout) +{ + struct kunit *test = kunit_get_current_test(); + struct isp_test_ack_state *state = test->priv; + + state->calls++; + chan->rsp = (struct isp_message){ .arg0 = chan->req.arg0 | ISP_IPC_FLAG_ACK, + .arg1 = chan->req.arg2 }; + switch (state->fault) { + case 1: + chan->rsp.arg2 = 1; + break; + case 2: + put_unaligned_le32(1, isp->cmd_virt); + break; + case 3: + chan->rsp.arg1 += 4; + break; + case 4: + return -ETIME; + } + return 0; +} + +static void isp_test_command_ack_failures(struct kunit *test) +{ + struct apple_isp *isp = isp_test_capture_alloc(test); + struct isp_test_ack_state state = {}; + + isp->cmd_virt = kunit_kzalloc(test, 0x400, GFP_KERNEL); + isp->chan_io = kunit_kzalloc(test, sizeof(*isp->chan_io), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, isp->cmd_virt); + KUNIT_ASSERT_NOT_NULL(test, isp->chan_io); + isp->chan_io->name = "IO"; + test->priv = &state; + kunit_deactivate_static_stub(test, isp_cmd_send); + kunit_activate_static_stub(test, ipc_chan_send, isp_test_ack_reply); + KUNIT_EXPECT_EQ(test, isp_cmd_ch_camera_config_select(isp, 0, 5), 0); + for (state.fault = 1; state.fault <= 4; state.fault++) { + unsigned int fault = state.fault; + + state.calls = 0; + KUNIT_EXPECT_EQ(test, isp_cmd_ch_camera_config_select(isp, 0, 5), + fault == 4 ? -ETIME : -EIO); + /* A failed command does not take the next one with it. */ + KUNIT_EXPECT_FALSE(test, isp->ipc_failed); + state.fault = 0; + KUNIT_EXPECT_EQ(test, isp_cmd_ch_camera_config_select(isp, 0, 5), 0); + KUNIT_EXPECT_EQ(test, state.calls, 2); + state.fault = fault; + } + + /* Firmware that never answered gets no further command. */ + isp->ipc_failed = true; + state.calls = 0; + KUNIT_EXPECT_EQ(test, isp_cmd_ch_camera_config_select(isp, 0, 5), -EIO); + KUNIT_EXPECT_EQ(test, state.calls, 0); +} + +static void isp_test_call_crop(struct kunit *test) +{ + struct isp_preset source = { + .index = 7, .input_dim = { 1936, 1096 }, + .output_dim = { 1920, 1080 }, .crop_offset = { 8, 8 }, + .crop_size = { 1920, 1080 }, .p010 = true, + }; + struct isp_preset result; + + KUNIT_ASSERT_TRUE(test, + isp_size_from_crop(&source, (struct coord){ 640, 480 }, &result)); + KUNIT_EXPECT_EQ(test, result.index, 7); + KUNIT_EXPECT_TRUE(test, result.p010); + KUNIT_EXPECT_EQ(test, result.crop_offset.x, 248); + KUNIT_EXPECT_EQ(test, result.crop_offset.y, 8); + KUNIT_EXPECT_EQ(test, result.crop_size.x, 1440); + KUNIT_EXPECT_EQ(test, result.crop_size.y, 1080); + KUNIT_EXPECT_EQ(test, result.output_dim.x, 640); + KUNIT_EXPECT_EQ(test, result.output_dim.y, 480); +} + +static void isp_test_call_crop_bounds(struct kunit *test) +{ + struct isp_preset source = { + .input_dim = { 1920, 2160 }, .output_dim = { 1920, 1080 }, + .crop_size = { 1920, 1080 }, + }; + struct isp_preset result; + static const struct coord rejected[] = { + { 1080, 1920 }, { 1760, 1328 }, { 1552, 1552 }, + { 1922, 1080 }, { 0, 480 }, { 641, 480 }, + }; + + /* Stacked input rows do not make a portrait or a larger square. */ + for (unsigned int i = 0; i < ARRAY_SIZE(rejected); i++) + KUNIT_EXPECT_FALSE(test, isp_size_from_crop(&source, rejected[i], &result)); + source.crop_offset.x = 2; + KUNIT_EXPECT_FALSE(test, + isp_size_from_crop(&source, (struct coord){ 640, 480 }, &result)); + source.crop_offset.x = U32_MAX; + KUNIT_EXPECT_FALSE(test, + isp_size_from_crop(&source, (struct coord){ 640, 480 }, &result)); +} + +static void isp_test_call_size_table(struct kunit *test) +{ + struct apple_isp *isp = isp_test_capture_alloc(test); + struct isp_preset source = { + .index = 7, .input_dim = { 1920, 1920 }, + .output_dim = { 1920, 1920 }, .crop_size = { 1920, 1920 }, + }; + + isp->presets = &source; + isp->num_presets = 1; + KUNIT_ASSERT_EQ(test, isp_add_call_sizes(isp), 0); + KUNIT_EXPECT_EQ(test, isp->num_presets, ARRAY_SIZE(isp_call_sizes) + 1); + KUNIT_EXPECT_EQ(test, isp->presets[0].output_dim.x, 1920); + KUNIT_EXPECT_EQ(test, isp->presets[0].output_dim.y, 1920); + for (unsigned int i = 0; i < ARRAY_SIZE(isp_call_sizes); i++) { + struct isp_preset *preset = &isp->presets[i + 1]; + + KUNIT_EXPECT_EQ(test, preset->output_dim.x, isp_call_sizes[i].x); + KUNIT_EXPECT_EQ(test, preset->output_dim.y, isp_call_sizes[i].y); + KUNIT_EXPECT_EQ(test, preset->index, 7); + KUNIT_EXPECT_FALSE(test, preset->p010); + KUNIT_EXPECT_EQ(test, preset->crop_size.x * preset->output_dim.y, + preset->crop_size.y * preset->output_dim.x); + KUNIT_EXPECT_EQ(test, (preset->crop_offset.x | preset->crop_offset.y | + preset->crop_size.x | preset->crop_size.y) & 1, 0); + KUNIT_EXPECT_LE(test, preset->crop_offset.x + preset->crop_size.x, 1920); + KUNIT_EXPECT_LE(test, preset->crop_offset.y + preset->crop_size.y, 1920); + } + /* Rebuilding preserves order and never duplicates an existing size. */ + KUNIT_ASSERT_EQ(test, isp_add_call_sizes(isp), 0); + KUNIT_EXPECT_EQ(test, isp->num_presets, ARRAY_SIZE(isp_call_sizes) + 1); +} + +static void isp_test_call_size_capabilities(struct kunit *test) +{ + struct apple_isp *isp = isp_test_capture_alloc(test); + struct isp_preset sources[] = { + { .index = 5, .input_dim = { 1920, 2160 }, + .output_dim = { 1920, 1080 }, .crop_size = { 1920, 1080 }, .p010 = true }, + { .index = 5, .input_dim = { 1920, 2160 }, + .output_dim = { 1280, 720 }, .crop_size = { 1280, 720 }, .p010 = true }, + { .index = 9, .input_dim = { 1536, 3024 }, + .output_dim = { 1536, 3024 }, .crop_size = { 1536, 3024 }, .p010 = true }, + }; + + isp->presets = sources; + isp->num_presets = ARRAY_SIZE(sources); + KUNIT_ASSERT_EQ(test, isp_add_call_sizes(isp), 0); + KUNIT_EXPECT_EQ(test, isp->num_presets, 9); + for (unsigned int i = 0; i < ARRAY_SIZE(sources); i++) + KUNIT_EXPECT_MEMEQ(test, &isp->presets[i], &sources[i], sizeof(sources[i])); + for (unsigned int i = ARRAY_SIZE(sources); i < isp->num_presets; i++) { + struct isp_preset *preset = &isp->presets[i]; + + KUNIT_EXPECT_TRUE(test, preset->p010); + KUNIT_EXPECT_FALSE(test, preset->output_dim.x == 1760 && + preset->output_dim.y == 1328); + KUNIT_EXPECT_FALSE(test, preset->output_dim.x == 1552 && + preset->output_dim.y == 1552); + } + KUNIT_EXPECT_EQ(test, isp->presets[8].output_dim.x, 1536); + KUNIT_EXPECT_EQ(test, isp->presets[8].output_dim.y, 1536); +} + +static struct kunit_case isp_cam_test_cases[] = { + KUNIT_CASE(isp_test_call_crop), + KUNIT_CASE(isp_test_call_crop_bounds), + KUNIT_CASE(isp_test_call_size_table), + KUNIT_CASE(isp_test_call_size_capabilities), + KUNIT_CASE(isp_test_setfile_failure_stops_setup), + KUNIT_CASE(isp_test_optional_setfile_continues_setup), + KUNIT_CASE(isp_test_command_ack_failures), + KUNIT_CASE(isp_test_sensor_geometry), + KUNIT_CASE(isp_test_sensor_config_list), + KUNIT_CASE(isp_test_sensor_config_failure), + KUNIT_CASE(isp_test_preview_stream), + KUNIT_CASE(isp_test_preview_command_failures), + KUNIT_CASE(isp_test_temporal_filter_band0), + KUNIT_CASE(isp_test_temporal_filter_off), + KUNIT_CASE(isp_test_power_line_frequency), + {} +}; + +static struct kunit_suite isp_cam_test_suite = { + .name = "apple-isp-camera", + .test_cases = isp_cam_test_cases, +}; + +kunit_test_suite(isp_cam_test_suite); diff --git a/drivers/media/platform/apple/isp/isp-cam.c b/drivers/media/platform/apple/isp/isp-cam.c index 5090ed2ed5b985..77c49312790740 100644 --- a/drivers/media/platform/apple/isp/isp-cam.c +++ b/drivers/media/platform/apple/isp/isp-cam.c @@ -1,16 +1,33 @@ // SPDX-License-Identifier: GPL-2.0-only /* Copyright 2023 Eileen Yoon */ +#include #include +#include +#include +#include +#include #include +#include #include "isp-cam.h" #include "isp-cmd.h" #include "isp-fw.h" #include "isp-iommu.h" +#include "isp-ipc.h" #include "isp-regs.h" -#define ISP_MAX_PRESETS 32 +/* + * How the ISP's own temporal noise filter is set up for a sensor. macOS + * picks this per sensor on the H17 interface: the IMX558 (J700) runs + * without it and the IMX958 (J616s) runs it with explicit strength + * controls. Everything else keeps the original start sequence. + */ +enum isp_temporal_filter { + ISP_TEMPORAL_FILTER_START, + ISP_TEMPORAL_FILTER_OFF, + ISP_TEMPORAL_FILTER_BAND0, +}; struct isp_setfile { u32 version; @@ -19,6 +36,7 @@ struct isp_setfile { size_t size; /* bytes present in the file if fewer than size; the rest is zero */ size_t file_size; + enum isp_temporal_filter temporal_filter; }; // clang-format off @@ -48,7 +66,8 @@ static const struct isp_setfile isp_setfiles[] = { [ISP_IMX514_2820_04] = {0x514, 0x28200405, "apple/isp_2820_04XX.dat", 0xa198}, [ISP_IMX558_1921_01] = {0x558, 0x19210106, "apple/isp_1921_01XX.dat", 0xad40}, [ISP_IMX558_1922_02] = {0x558, 0x19220201, "apple/isp_1922_02XX.dat", 0xad40}, - [ISP_IMX558_1925_03] = {0x558, 0x19250306, "apple/isp_1925_03XX.dat", 0xcbc0, 0xcba6}, + [ISP_IMX558_1925_03] = {0x558, 0x19250306, "apple/isp_1925_03XX.dat", 0xcbc0, 0xcba6, + ISP_TEMPORAL_FILTER_OFF}, [ISP_IMX603_7920_01] = {0x603, 0x79200109, "apple/isp_7920_01XX.dat", 0xad2c}, [ISP_IMX603_7920_02] = {0x603, 0x79200205, "apple/isp_7920_02XX.dat", 0xad2c}, [ISP_IMX603_7921_01] = {0x603, 0x79210104, "apple/isp_7921_01XX.dat", 0xad90}, @@ -70,6 +89,10 @@ static const struct isp_setfile isp_setfiles[] = { [ISP_IMX814_2123_01] = {0x814, 0x21230101, "apple/isp_2123_01XX.dat", 0xed54}, [ISP_IMX853_7622_01] = {0x853, 0x76220112, "apple/isp_7622_01XX.dat", 0x247f8}, [ISP_IMX913_7523_01] = {0x913, 0x75230107, "apple/isp_7523_01XX.dat", 0x247f8}, + [ISP_IMX958_2224_01] = {0x958, 0x22240106, "apple/isp_2224_01XX.dat", 0x6ff4, 0, + ISP_TEMPORAL_FILTER_BAND0}, + [ISP_IMX958_2226_02] = {0x958, 0x22260201, "apple/isp_2226_02XX.dat", 0x6ff4, 0, + ISP_TEMPORAL_FILTER_BAND0}, [ISP_VD56G0_6221_01] = {0xd56, 0x62210102, "apple/isp_6221_01XX.dat", 0x1b80}, [ISP_VD56G0_6222_01] = {0xd56, 0x62220102, "apple/isp_6222_01XX.dat", 0x1b80}, }; @@ -158,6 +181,13 @@ static int isp_ch_get_sensor_id(struct apple_isp *isp, u32 ch) case 0x913: id = ISP_IMX913_7523_01; break; + case 0x958: + /* + * Section 0x50f of 2224 and 2226 names sensor 0x958; 2924's + * names 0x614. + */ + id = isp->hw->imx958_2226 ? ISP_IMX958_2226_02 : ISP_IMX958_2224_01; + break; case 0xd56: id = ISP_VD56G0_6221_01; break; @@ -188,6 +218,23 @@ static int isp_check_presets(struct apple_isp *isp, u32 num_fw_presets) if (!num_fw_presets) return 0; + /* + * A deferred start detects the camera after the presets were + * advertised: keep them, and refuse a stream on one the firmware + * lacks instead. + */ + if (isp->hw->deferred_start) { + isp->num_fw_presets = num_fw_presets; + for (int i = 0; i < isp->num_presets; i++) + if (isp->presets[i].index >= num_fw_presets) + dev_warn(isp->dev, + "%ux%u preset: config %u, firmware has %u\n", + isp->presets[i].output_dim.x, + isp->presets[i].output_dim.y, + isp->presets[i].index, num_fw_presets); + return 0; + } + for (int i = 0; i < isp->num_presets; i++) { struct isp_preset *preset = &isp->presets[i]; @@ -212,6 +259,225 @@ static int isp_check_presets(struct apple_isp *isp, u32 num_fw_presets) return 0; } +/* Do not mistake stacked sensor input rows for a processed output mode. */ +static bool isp_sensor_config_usable(const struct cmd_ch_camera_config *config) +{ + return config->in_width && config->in_height && + config->out_width && config->out_height && + config->out_width <= 16384 && config->out_height <= 16384 && + !(config->out_width & 1) && !(config->out_height & 1) && + config->out_width <= config->in_width && + config->out_height <= config->in_height && + config->in_width == config->in_width2 && + config->in_height == config->in_height2 && + config->out_width == config->out_width2 && + config->out_height == config->out_height2; +} + +static int isp_ch_cache_sensor_configs(struct apple_isp *isp, u32 ch, u32 count) +{ + struct cmd_ch_camera_config_h17 args; + struct isp_sensor_config *configs; + struct isp_preset *presets; + unsigned int num = isp->num_presets; + int err; + + /* The extended reply is established only for the IMX958 T6040 path. */ + if (!isp_supports_p010(isp)) + return 0; + if (!count || count > ISP_MAX_SENSOR_CONFIGS) + return -EINVAL; + + presets = devm_kcalloc(isp->dev, num + count, sizeof(*presets), GFP_KERNEL); + if (!presets) + return -ENOMEM; + memcpy(presets, isp->presets, num * sizeof(*presets)); + configs = kcalloc(count, sizeof(*configs), GFP_KERNEL); + if (!configs) + return -ENOMEM; + + for (u32 i = 0; i < count; i++) { + struct cmd_ch_camera_config *config = &args.config; + struct isp_sensor_config *cached = &configs[i]; + bool duplicate = false; + + err = isp_cmd_ch_camera_config_get(isp, ch, i, &args); + if (err) + goto free_configs; + if (config->opcode != (u64)CISP_CMD_CH_CAMERA_CONFIG_GET << 32 || + config->chan != ch || config->preset != i) { + err = -EIO; + goto free_configs; + } + + memcpy(cached->reply, &args, sizeof(args)); + cached->input_dim = (struct coord){config->in_width, config->in_height}; + cached->output_dim = (struct coord){config->out_width, config->out_height}; + cached->sensor_clk = config->sensor_clk; + cached->usable = isp_sensor_config_usable(config); + dev_dbg(isp->dev, "sensor config %u: input %ux%u output %ux%u clock %u%s\n", + i, config->in_width, config->in_height, + config->out_width, config->out_height, config->sensor_clk, + cached->usable ? "" : " (unverified geometry)"); + print_hex_dump_debug("apple-isp config: ", DUMP_PREFIX_OFFSET, + 16, 4, &args, sizeof(args), false); + /* Both processed preview sizes are recorded in the proxy source. */ + for (unsigned int j = 0; j < num; j++) { + struct isp_preset *preset = &presets[j]; + bool preview = i == 5 && config->in_width == 1920 && + config->in_height == 2160 && + ((preset->output_dim.x == 1280 && + preset->output_dim.y == 720) || + (preset->output_dim.x == 1920 && + preset->output_dim.y == 1080)); + bool reported = cached->usable && + preset->output_dim.x == config->out_width && + preset->output_dim.y == config->out_height; + + if (preset->index == i && + preset->input_dim.x == config->in_width && + preset->input_dim.y == config->in_height && + !preset->crop_offset.x && !preset->crop_offset.y && + /* Same aspect ratio, never enlarged: the scaler may shrink it. */ + preset->crop_size.x >= preset->output_dim.x && + preset->crop_size.x * preset->output_dim.y == + preset->crop_size.y * preset->output_dim.x) + preset->p010 = preview || reported; + } + if (!cached->usable) + continue; + + /* Keep the board's config-5 presets, including the default, first. */ + for (unsigned int j = 0; j < num; j++) { + if (presets[j].output_dim.x == config->out_width && + presets[j].output_dim.y == config->out_height) { + duplicate = true; + break; + } + } + if (duplicate) + continue; + + presets[num++] = (struct isp_preset){ + .index = i, + .input_dim = cached->input_dim, + .output_dim = cached->output_dim, + .crop_size = cached->output_dim, + .p010 = true, + }; + } + isp->sensor_configs = configs; + isp->num_sensor_configs = count; + isp->presets = presets; + isp->num_presets = num; + return 0; + +free_configs: + kfree(configs); + return err; +} + +/* Common call sizes, offered only when a known processed crop contains them. */ +static const struct coord isp_call_sizes[] = { + { 640, 480 }, { 1280, 720 }, { 1920, 1080 }, { 1080, 1920 }, + { 1760, 1328 }, { 1328, 1760 }, { 1552, 1552 }, + { 1280, 960 }, { 960, 1280 }, +}; + +/* + * CH_CROP[_SCL1]_SET takes x/y/width/height independently of the output + * dimensions in CH_OUTPUT_CONFIG[_SCL1]_SET. Stay within an established + * processed crop, rather than the sensor input (which may contain stacked + * rows). Use the largest exact-aspect crop, centred on the chroma grid, + * with no upscaling. Neither command reports a scaler limit or rotation. + */ +static bool isp_size_from_crop(const struct isp_preset *source, + struct coord size, struct isp_preset *preset) +{ + u32 divisor, x, y, scale; + + if (!size.x || !size.y || (size.x | size.y) & 1 || + !source->crop_size.x || !source->crop_size.y || + (source->crop_offset.x | source->crop_offset.y) & 1 || + source->crop_size.x > 16384 || source->crop_size.y > 16384 || + source->crop_offset.x > source->input_dim.x || + source->crop_size.x > source->input_dim.x - source->crop_offset.x || + source->crop_offset.y > source->input_dim.y || + source->crop_size.y > source->input_dim.y - source->crop_offset.y) + return false; + + divisor = gcd(size.x, size.y); + x = size.x / divisor; + y = size.y / divisor; + scale = round_down(min(source->crop_size.x / x, + source->crop_size.y / y), 2); + if (scale < divisor) + return false; + + *preset = *source; + preset->output_dim = size; + preset->crop_size = (struct coord){ x * scale, y * scale }; + preset->crop_offset.x += round_down((source->crop_size.x - x * scale) / 2, 2); + preset->crop_offset.y += round_down((source->crop_size.y - y * scale) / 2, 2); + return true; +} + +static unsigned int isp_append_size(struct isp_preset *presets, unsigned int num, + unsigned int sources, struct coord size) +{ + struct isp_preset candidate, best; + u32 area, best_area = 0; + + for (unsigned int i = 0; i < num; i++) + if (presets[i].output_dim.x == size.x && + presets[i].output_dim.y == size.y) + return num; + + /* Never use a generated size as evidence for another generated size. */ + for (unsigned int i = 0; i < sources; i++) { + if (!isp_size_from_crop(&presets[i], size, &candidate)) + continue; + area = candidate.crop_size.x * candidate.crop_size.y; + if (area > best_area) { + best = candidate; + best_area = area; + } + } + if (best_area) + presets[num++] = best; + return num; +} + +static int isp_add_call_sizes(struct apple_isp *isp) +{ + unsigned int sources = isp->num_presets, num = sources; + struct isp_preset *presets; + struct isp_preset candidate; + u32 square = 0; + + presets = devm_kcalloc(isp->dev, sources + ARRAY_SIZE(isp_call_sizes) + 1, + sizeof(*presets), GFP_KERNEL); + if (!presets) + return -ENOMEM; + memcpy(presets, isp->presets, sources * sizeof(*presets)); + + for (unsigned int i = 0; i < ARRAY_SIZE(isp_call_sizes); i++) + num = isp_append_size(presets, num, sources, isp_call_sizes[i]); + + /* A smaller sensor can still offer a square without enlarging pixels. */ + for (unsigned int i = 0; i < sources; i++) { + u32 side = round_down(min(presets[i].crop_size.x, + presets[i].crop_size.y), 2); + + if (isp_size_from_crop(&presets[i], (struct coord){ side, side }, &candidate)) + square = max(square, side); + } + num = isp_append_size(presets, num, sources, (struct coord){ square, square }); + isp->presets = presets; + isp->num_presets = num; + return 0; +} + static int isp_ch_cache_sensor_info(struct apple_isp *isp, u32 ch) { struct isp_format *fmt = isp_get_format(isp, ch); @@ -228,10 +494,14 @@ static int isp_ch_cache_sensor_info(struct apple_isp *isp, u32 ch) dev_dbg(isp->dev, "found sensor %x on ch %d\n", args->version, ch); - /* The metadata buffers are allocated for the sizes the driver knows. */ + /* + * The metadata buffers are allocated for the sizes the driver knows; + * without a capture metadata pool its size is not used. + */ if (isp->hw->fw_abi == ISP_FW_ABI_H17 && (args->unk_68 != isp->hw->meta_size || - args->unk_78 != isp->hw->capture_meta_size)) { + (isp->hw->capture_meta_size && + args->unk_78 != isp->hw->capture_meta_size))) { dev_err(isp->dev, "metadata sizes 0x%x/0x%x, expected 0x%x/0x%x\n", args->unk_68, args->unk_78, isp->hw->meta_size, @@ -245,7 +515,8 @@ static int isp_ch_cache_sensor_info(struct apple_isp *isp, u32 ch) err = isp_ch_get_sensor_id(isp, ch); if (err || (fmt->id != ISP_IMX248_1820_01 && fmt->id != ISP_IMX558_1921_01 && - fmt->id != ISP_IMX558_1925_03 && fmt->id != ISP_IMX364_8720_01)) { + fmt->id != ISP_IMX558_1925_03 && fmt->id != ISP_IMX364_8720_01 && + fmt->id != ISP_IMX958_2224_01 && fmt->id != ISP_IMX958_2226_02)) { dev_err(isp->dev, "ch %d: unsupported sensor. Please file a bug report with hardware info & dmesg trace.\n", ch); @@ -254,6 +525,10 @@ static int isp_ch_cache_sensor_info(struct apple_isp *isp, u32 ch) } err = isp_check_presets(isp, args->num_presets); + if (!err) + err = isp_ch_cache_sensor_configs(isp, ch, args->num_presets); + if (!err) + err = isp_add_call_sizes(isp); exit: kfree(args); @@ -311,8 +586,12 @@ int apple_isp_detect_camera(struct apple_isp *isp) dev_err(isp->dev, "failed to boot firmware for initial sensor detection: %d\n", err); - /* Resident firmware would fail a deferred retry the same way. */ - return isp->hw->resident_fw ? err : -EPROBE_DEFER; + /* + * Resident firmware would fail a deferred retry the same way, + * and a deferred start is not a probe to defer. + */ + return isp->hw->resident_fw || isp->hw->deferred_start ? + err : -EPROBE_DEFER; } err = isp_detect_camera(isp); @@ -321,6 +600,8 @@ int apple_isp_detect_camera(struct apple_isp *isp) if (isp->hw->resident_fw) { if (err) apple_isp_firmware_halt(isp); + else + isp->camera_detected = true; return err; } @@ -331,9 +612,153 @@ int apple_isp_detect_camera(struct apple_isp *isp) apple_isp_firmware_shutdown(isp); + if (!err) + isp->camera_detected = true; return err; } +/* + * A setfile is a chain of { le32 size, le32 0, le32 tag, payload } sections + * from 0x14 on, size counting what follows it. The lens shading sections + * hold 18-byte table records after a 10-byte header: { ?, 0x20, 0x20, + * offset lo, offset hi, 0, 0, width, height }. The xx24 setfiles keep the + * row stride (2 * width) in "offset hi"; the H17 firmware reads it as the + * offset's high half ("baseHi") and faults far past the file. Their xx25 + * twins are the same tables with it zeroed, as macOS hands them over. + */ +static void isp_setfile_fixup_h17(void *data, size_t len) +{ + size_t off = 0x14; + + while (off + 12 <= len) { + u32 size = get_unaligned_le32(data + off); + size_t end = off + 4 + size; + size_t rec; + int i; + + if (size < 8 || end > len) + break; + + switch (get_unaligned_le32(data + off + 8)) { + case 0xc003: + case 0xc01b: + case 0xc01c: + case 0xc01f: + case 0xc021: + rec = off + 12 + 10; + for (i = 0; i < 16 && rec + 18 <= end; i++, rec += 18) { + if (get_unaligned_le16(data + rec + 2) != 0x20 || + get_unaligned_le16(data + rec + 4) != 0x20) + break; + if (get_unaligned_le16(data + rec + 8) == + 2 * get_unaligned_le16(data + rec + 14)) + put_unaligned_le16(0, data + rec + 8); + } + break; + } + off = end; + } +} + +/* + * The noise reduction radial gains (setfile record 0xc404) from the lens + * shading table (0xc003), as macOS's appleh16camerad computes them before + * loading the setfile: per radius bin, 4096 over the mean shading gain of + * the four Bayer planes along the rays to the four image corners. + */ +static u8 *isp_setfile_record(u8 *data, size_t len, u32 tag, size_t *size) +{ + size_t off = 0x14; + + while (off + 12 <= len) { + u32 sz = get_unaligned_le32(data + off); + + if (get_unaligned_le32(data + off + 4) || sz < 8 || off + 4 + sz > len) + return NULL; + if (get_unaligned_le32(data + off + 8) == tag) { + *size = sz; + return data + off + 4; + } + off += 4 + sz; + } + return NULL; +} + +#define LSC_PLANES 4 +#define LSC_TABLE 0x5c +#define RG_BINS 257 + +static u32 isp_lsc_gain(const u8 *lsc, size_t lsc_size, int plane, s64 x, s64 y) +{ + const u8 *h = lsc + 0x12 + plane * 0x12; + u32 sx = get_unaligned_le16(h + 2), sy = get_unaligned_le16(h + 4); + u32 base = get_unaligned_le32(h + 6); + u32 gx = get_unaligned_le16(h + 14), gy = get_unaligned_le16(h + 16); + s64 fx, fy, ax, ay; + s64 ix, iy; + u32 t00, t10, t01, t11; + size_t i00; + + /* x and y in 1/256 half-resolution pixels; fx, fy in 1/256 cells */ + fx = div_s64(x, sx); + fy = div_s64(y, sy); + ix = clamp_t(s64, fx >> 8, 0, gx - 2); + iy = clamp_t(s64, fy >> 8, 0, gy - 2); + ax = clamp_t(s64, fx - (ix << 8), 0, 256); + ay = clamp_t(s64, fy - (iy << 8), 0, 256); + i00 = LSC_TABLE + 2 * (base + iy * gx + ix); + if (i00 + 2 * (gx + 2) > lsc_size + 4) + return 4096; + t00 = get_unaligned_le16(lsc + i00); + t10 = get_unaligned_le16(lsc + i00 + 2); + t01 = get_unaligned_le16(lsc + i00 + 2 * gx); + t11 = get_unaligned_le16(lsc + i00 + 2 * gx + 2); + return ((t00 * (256 - ax) + t10 * ax) * (256 - ay) + + (t01 * (256 - ax) + t11 * ax) * ay) >> 16; +} + +static void isp_setfile_radial_gain(u8 *data, size_t len) +{ + size_t lsc_size, rg_size; + u8 *lsc = isp_setfile_record(data, len, 0xc003, &lsc_size); + u8 *rg = isp_setfile_record(data, len, 0xc404, &rg_size); + s64 cx, cy, dx[4], dy[4], dist[4], rmax = 0; + u32 w, h, shift; + int i, c, p; + + if (!lsc || !rg || lsc_size < LSC_TABLE || rg_size < 0xe + 2 * RG_BINS - 4) + return; + w = get_unaligned_le16(lsc + 0xe); + h = get_unaligned_le16(lsc + 0x10); + if (!w || !h) + return; + + /* full-resolution pixels in 1/256; the optical centre sits 156 rows up */ + cx = (s64)w << 7; + cy = ((s64)h << 7) - (156 << 8); + for (c = 0; c < 4; c++) { + dx[c] = ((c & 1) ? (s64)w << 8 : 0) - cx; + dy[c] = ((c & 2) ? (s64)h << 8 : 0) - cy; + dist[c] = int_sqrt64(dx[c] * dx[c] + dy[c] * dy[c]); + rmax = max(rmax, dist[c]); + } + shift = order_base_2(DIV_ROUND_UP(rmax, 256 << 8)); + put_unaligned_le16(shift, rg + 0xc); + + for (i = 0; i < RG_BINS; i++) { + s64 t = min_t(s64, (s64)i << (shift + 8), rmax); + u64 sum = 0; + + for (p = 0; p < LSC_PLANES; p++) + for (c = 0; c < 4; c++) + sum += isp_lsc_gain(lsc, lsc_size, p, + (cx + div64_s64(t * dx[c], dist[c])) / 2, + (cy + div64_s64(t * dy[c], dist[c])) / 2); + put_unaligned_le16(min_t(u64, div64_u64(16ULL * 4096 * 4096, sum), 0xffff), + rg + 0xe + 2 * i); + } +} + static int isp_ch_load_setfile(struct apple_isp *isp, u32 ch) { struct isp_format *fmt = isp_get_format(isp, ch); @@ -343,14 +768,20 @@ static int isp_ch_load_setfile(struct apple_isp *isp, u32 ch) u32 magic; int err; + KUNIT_STATIC_STUB_REDIRECT(isp_ch_load_setfile, isp, ch); + if (WARN_ON_ONCE(setfile->size > isp->data_surf->size)) return -ENOSPC; err = firmware_request_nowarn(&fw, setfile->path, isp->dev); if (err) { - dev_warn_once(isp->dev, - "setfile '%s' not loaded (%d), streaming without calibration\n", - setfile->path, err); + if (err == -ENOENT) + dev_warn_once(isp->dev, + "setfile '%s' missing, streaming without sensor tuning\n", + setfile->path); + else + dev_err(isp->dev, "failed to read setfile '%s': %d\n", + setfile->path, err); return err; } @@ -372,9 +803,29 @@ static int isp_ch_load_setfile(struct apple_isp *isp, u32 ch) memcpy(isp->data_surf->virt, fw->data, len); memset(isp->data_surf->virt + len, 0, setfile->size - len); release_firmware(fw); + /* Seen on T6040 only; T8140 runs its setfiles as they are. */ + if (isp->hw->gen == ISP_GEN_T6040 || isp->hw->setfile_stride_fixup) + isp_setfile_fixup_h17(isp->data_surf->virt, len); + if (isp->hw->setfile_radial_gain) + isp_setfile_radial_gain(isp->data_surf->virt, len); + + if (isp->hw->lsc_ideal_percent) { + err = isp_cmd_ch_lsc_ideal_percent_set(isp, ch, + isp->hw->lsc_ideal_percent); + if (err) + return err; + } - return isp_cmd_ch_set_file_load(isp, ch, isp->data_surf->iova, - setfile->size); + err = isp_cmd_ch_set_file_load(isp, ch, isp->data_surf->iova, + setfile->size); + if (err) + dev_err(isp->dev, "ch %u: setfile '%s' load failed: %d\n", + ch, setfile->path, err); + else + dev_dbg(isp->dev, "ch %u: loaded sensor tuning '%s' (0x%zx bytes)\n", + ch, setfile->path, setfile->size); + + return err; } static int isp_ch_configure_frame_rate(struct apple_isp *isp, u32 ch) @@ -397,26 +848,103 @@ static int isp_ch_configure_frame_rate(struct apple_isp *isp, u32 ch) return isp_cmd_ch_ae_frame_rate_min_set(isp, ch, min_rate); } -static int isp_ch_configure_pools(struct apple_isp *isp, u32 ch) +/* + * Tell auto exposure the mains frequency, so that it picks exposure times + * that do not beat with lights on that supply. The firmware takes it in Hz, + * 16.16 fixed point. macOS sends it on the H17 interface for every camera. + */ +static int isp_ch_configure_power_line(struct apple_isp *isp, u32 ch) +{ + u32 hz = 50; + + if (isp->hw->fw_abi != ISP_FW_ABI_H17) + return 0; + + if (isp->power_line_frequency && + v4l2_ctrl_g_ctrl(isp->power_line_frequency) == + V4L2_CID_POWER_LINE_FREQUENCY_60HZ) + hz = 60; + + return isp_cmd_apple_ch_ae_flicker_freq_update_current_set(isp, ch, + hz << 16); +} + +static int isp_ch_configure_temporal_filter(struct apple_isp *isp, u32 ch) { struct isp_format *fmt = isp_get_format(isp, ch); int err; - err = isp_cmd_ch_buffer_pool_config_set(isp, ch, CISP_POOL_TYPE_META); + switch (isp_setfiles[fmt->id].temporal_filter) { + case ISP_TEMPORAL_FILTER_OFF: + /* The firmware keeps its state between streams; stop it. */ + err = isp_cmd_apple_ch_temporal_filter_disable(isp, ch); + if (err) + return err; + + err = isp_cmd_apple_ch_motion_history_stop(isp, ch); + if (err) + return err; + + return isp_cmd_apple_ch_temporal_filter_stop(isp, ch); + + case ISP_TEMPORAL_FILTER_BAND0: + err = isp_cmd_apple_ch_tnr_start_h17(isp, ch); + if (err) + return err; + + err = isp_cmd_apple_ch_tnr_high_strength_set(isp, ch, 0); + if (err) + return err; + + err = isp_cmd_apple_ch_tnr_band0_mod_set(isp, ch, 0); + if (err) + return err; + + /* 120 and 100, in 1/256 steps */ + err = isp_cmd_apple_ch_tnr_band0_threshold_set(isp, ch, 120 << 8, + 100 << 8); + if (err) + return err; + break; + + default: + err = isp_cmd_apple_ch_temporal_filter_start(isp, ch, + isp->temporal_filter); + if (err) + return err; + break; + } + + err = isp_cmd_apple_ch_motion_history_start(isp, ch); if (err) return err; - err = isp_cmd_ch_buffer_pool_config_set(isp, ch, - CISP_POOL_TYPE_META_CAPTURE); + return isp_cmd_apple_ch_temporal_filter_enable(isp, ch); +} + +static int isp_ch_configure_pools(struct apple_isp *isp, u32 ch) +{ + struct isp_format *fmt = isp_get_format(isp, ch); + int err; + + err = isp_cmd_ch_buffer_pool_config_set(isp, ch, CISP_POOL_TYPE_META); if (err) return err; + /* H17 firmware without capture metadata has no such pool. */ + if (isp->hw->fw_abi != ISP_FW_ABI_H17 || isp->hw->capture_meta_size) { + err = isp_cmd_ch_buffer_pool_config_set(isp, ch, + CISP_POOL_TYPE_META_CAPTURE); + if (err) + return err; + } + /* The H17 firmware also takes the geometry of the output buffers. */ if (isp->hw->fw_abi != ISP_FW_ABI_H17) return 0; return isp_cmd_ch_buffer_pool_config_set_rendered(isp, ch, - ISP_MAX_BUFFERS, + isp_num_rendered(isp), fmt->plane_size[0], fmt->strides[0], fmt->plane_size[1], @@ -429,14 +957,21 @@ static int isp_ch_configure_capture(struct apple_isp *isp, u32 ch) bool h17 = isp->hw->fw_abi == ISP_FW_ABI_H17; int err; - isp_cmd_flicker_sensor_set(isp, 0); + err = isp_cmd_flicker_sensor_set(isp, 0); + if (isp_is_p010(isp) && err) + return err; + + /* The proxy-qualified P010 route uses the firmware defaults. */ + if (isp_is_p010(isp)) + goto select_config; /* - * The setfile isn't requisite but then we don't get calibration. If - * loading it was interrupted by a signal, give up on the stream. + * Missing sensor tuning is optional. A present but invalid setfile or + * a failed firmware upload must not silently select firmware defaults. + * This model-wide tuning is separate from per-module factory data. */ err = isp_ch_load_setfile(isp, ch); - if (err == -EINTR) + if (err && err != -ENOENT) return err; if (isp->hw->lpdp) { @@ -445,6 +980,11 @@ static int isp_ch_configure_capture(struct apple_isp *isp, u32 ch) return err; } + err = isp_ch_configure_power_line(isp, ch); + if (err) + return err; + +select_config: err = isp_cmd_ch_sbs_enable(isp, ch, 1); if (err) return err; @@ -472,7 +1012,8 @@ static int isp_ch_configure_capture(struct apple_isp *isp, u32 ch) err = isp_cmd_ch_output_config_set(isp, ch, fmt->preset->output_dim.x, fmt->preset->output_dim.y, fmt->strides, CISP_COLORSPACE_REC709, - CISP_OUTPUT_FORMAT_YUV_2PLANE); + isp_is_p010(isp) ? CISP_OUTPUT_FORMAT_P010 : + CISP_OUTPUT_FORMAT_YUV_2PLANE); if (err) return err; @@ -500,6 +1041,9 @@ static int isp_ch_configure_capture(struct apple_isp *isp, u32 ch) if (err) return err; + if (isp_is_p010(isp)) + return isp_cmd_ch_master_slave_sync_mode_set(isp, ch, 0); + err = isp_cmd_ch_cnr_start(isp, ch); if (err) return err; @@ -508,8 +1052,8 @@ static int isp_ch_configure_capture(struct apple_isp *isp, u32 ch) if (err) return err; - /* The H17 firmware faults on this face-detection metering setup. */ - if (!h17) { + /* Most H17 firmware faults on this face-detection metering setup. */ + if (!h17 || isp->hw->ae_fd_scene_metering) { err = isp_cmd_apple_ch_ae_fd_scene_metering_config_set(isp, ch); if (err) @@ -538,15 +1082,7 @@ static int isp_ch_configure_capture(struct apple_isp *isp, u32 ch) return err; } - err = isp_cmd_apple_ch_temporal_filter_start(isp, ch, isp->temporal_filter); - if (err) - return err; - - err = isp_cmd_apple_ch_motion_history_start(isp, ch); - if (err) - return err; - - err = isp_cmd_apple_ch_temporal_filter_enable(isp, ch); + err = isp_ch_configure_temporal_filter(isp, ch); if (err) return err; @@ -563,18 +1099,38 @@ static int isp_configure_capture(struct apple_isp *isp) int apple_isp_start_camera(struct apple_isp *isp) { + struct isp_format *fmt = isp_get_current_format(isp); int err; + /* + * A deferred start detects the camera now. Resident firmware is then + * left running; firmware that starts again is stopped after the + * detection like at probe, and booted again here. + */ + if (isp->hw->deferred_start && !isp->camera_detected) { + err = apple_isp_detect_camera(isp); + if (err < 0) { + dev_err(isp->dev, "failed to detect the camera: %d\n", err); + return err; + } + } err = apple_isp_firmware_boot(isp); if (err < 0) { dev_err(isp->dev, "failed to boot firmware: %d\n", err); return err; } + if (isp->num_fw_presets && fmt->preset->index >= isp->num_fw_presets) { + dev_err(isp->dev, "preset config %u: firmware has %u\n", + fmt->preset->index, isp->num_fw_presets); + apple_isp_firmware_shutdown(isp); + return -EINVAL; + } + err = isp_configure_capture(isp); if (err) { dev_err(isp->dev, "failed to configure capture: %d\n", err); - apple_isp_firmware_shutdown(isp); + apple_isp_stop_camera(isp); return err; } @@ -583,7 +1139,15 @@ int apple_isp_start_camera(struct apple_isp *isp) void apple_isp_stop_camera(struct apple_isp *isp) { - apple_isp_firmware_shutdown(isp); + /* + * A timed-out request is resolved before anything the firmware may + * still use for it is released. Firmware that does not answer even + * late is stopped first. + */ + if (isp_ipc_resync(isp)) + apple_isp_firmware_halt(isp); + else + apple_isp_firmware_shutdown(isp); } /* @@ -607,6 +1171,8 @@ static enum hrtimer_restart apple_isp_wdt_timer(struct hrtimer *timer) struct apple_isp *isp = container_of(timer, struct apple_isp, wdt_timer); + if (isp->hw->camera_light && !isp->cil_lit) + return HRTIMER_NORESTART; apple_isp_wdt_kick(isp); hrtimer_forward_now(timer, ns_to_ktime(ISP_WDT_PERIOD_NS)); @@ -623,6 +1189,8 @@ static void apple_isp_wdt_start(struct apple_isp *isp) { if (!isp->wdt || isp->wdt_running) return; + if (isp->hw->camera_light && !isp->cil_lit) + return; isp->wdt_running = true; apple_isp_wdt_kick(isp); @@ -639,25 +1207,95 @@ void apple_isp_wdt_stop(struct apple_isp *isp) isp->wdt_running = false; } +#define ISP_GPIO_DATA BIT(0) +#define ISP_GPIO_MODE GENMASK(3, 1) +#define ISP_GPIO_INPUT_ENABLE BIT(9) +/* The mode and the pin's level, as the input buffer reads it */ +#define ISP_GPIO_CHECK (ISP_GPIO_MODE | ISP_GPIO_DATA) + +/* + * Light the camera light before the sensor may stream: drive its pin as an + * output at the on level, with the input buffer on so the pin's level reads + * back, and refuse to stream unless it does. + */ +static int apple_isp_light_on(struct apple_isp *isp) +{ + u32 val, on = isp->cil_on_high ? ISP_GPIO_DATA : 0; + + if (!isp->hw->camera_light) + return 0; + val = (isp->cil_config & ~ISP_GPIO_DATA) | ISP_GPIO_INPUT_ENABLE | on; + writel(val, isp->cil); + usleep_range(10, 20); + if ((readl(isp->cil) & ISP_GPIO_CHECK) != (val & ISP_GPIO_CHECK)) { + dev_err(isp->dev, "camera light did not come on (0x%x, wrote 0x%x), not streaming\n", + readl(isp->cil), val); + writel(isp->cil_saved, isp->cil); + return -EIO; + } + isp->cil_lit = true; + return 0; +} + +/* + * Only once the sensor has stopped streaming. The pin goes back to how the + * boot loader left it, where a powered sensor still lights the light. + */ +void apple_isp_light_off(struct apple_isp *isp) +{ + if (!isp->hw->camera_light || !isp->cil_lit) + return; + apple_isp_wdt_stop(isp); + isp->cil_lit = false; + writel(isp->cil_saved, isp->cil); +} + +/* + * Once the firmware is halted no frame can reach the host, but a sensor + * the dead firmware left powered would keep the light on until reset: + * drive it off. A halted resident firmware does not start again. + */ +void apple_isp_light_force_off(struct apple_isp *isp) +{ + if (!isp->hw->camera_light) + return; + apple_isp_light_off(isp); + writel((isp->cil_config & ~ISP_GPIO_DATA) | (isp->cil_on_high ? 0 : ISP_GPIO_DATA), + isp->cil); +} + int apple_isp_start_capture(struct apple_isp *isp) { int err; + err = apple_isp_light_on(isp); + if (err) + return err; + /* Serviced from before the channel starts... */ apple_isp_wdt_start(isp); err = isp_cmd_ch_start(isp, 0); // TODO channel mask - if (err) + if (err) { apple_isp_wdt_stop(isp); + apple_isp_light_off(isp); + } return err; } void apple_isp_stop_capture(struct apple_isp *isp) { + if (isp->ipc_failed || isp->fw_state == ISP_FW_DEAD) + return; isp_cmd_ch_stop(isp, 0); // TODO channel mask isp_cmd_ch_buffer_return(isp, isp->current_ch); /* ... until its buffers are back. */ apple_isp_wdt_stop(isp); + apple_isp_light_off(isp); } + +#if IS_ENABLED(CONFIG_VIDEO_APPLE_ISP_KUNIT_TEST) +#include "isp-cam-test.c" +#endif diff --git a/drivers/media/platform/apple/isp/isp-cam.h b/drivers/media/platform/apple/isp/isp-cam.h index 51c2f2ec6c0793..8cdcd17e2088e5 100644 --- a/drivers/media/platform/apple/isp/isp-cam.h +++ b/drivers/media/platform/apple/isp/isp-cam.h @@ -22,6 +22,8 @@ int apple_isp_start_capture(struct apple_isp *isp); void apple_isp_stop_capture(struct apple_isp *isp); void apple_isp_wdt_init(struct apple_isp *isp); +void apple_isp_light_off(struct apple_isp *isp); +void apple_isp_light_force_off(struct apple_isp *isp); void apple_isp_wdt_stop(struct apple_isp *isp); #endif /* __ISP_CAM_H__ */ diff --git a/drivers/media/platform/apple/isp/isp-cmd.c b/drivers/media/platform/apple/isp/isp-cmd.c index 42c448fd0f30ce..3e5a4a732a7a0c 100644 --- a/drivers/media/platform/apple/isp/isp-cmd.c +++ b/drivers/media/platform/apple/isp/isp-cmd.c @@ -5,30 +5,58 @@ #include "isp-drv.h" #include "isp-iommu.h" #include "isp-ipc.h" +#include + +#if IS_ENABLED(CONFIG_VIDEO_APPLE_ISP_KUNIT_TEST) +#include +#endif #define CISP_OPCODE_SHIFT 32UL #define CISP_OPCODE(x) (((u64)(x)) << CISP_OPCODE_SHIFT) #define CISP_OPCODE_GET(x) (((u64)(x)) >> CISP_OPCODE_SHIFT) #define CISP_TIMEOUT msecs_to_jiffies(3000) -#define CISP_SEND_IN(x, a) (cisp_send((x), &(a), sizeof(a), 0, CISP_TIMEOUT)) -#define CISP_SEND_INOUT(x, a) (cisp_send((x), &(a), sizeof(a), sizeof(a), CISP_TIMEOUT)) +#define CISP_SEND_IN(x, a) (isp_cmd_send((x), &(a), sizeof(a), 0, CISP_TIMEOUT)) +#define CISP_SEND_INOUT(x, a) (isp_cmd_send((x), &(a), sizeof(a), sizeof(a), CISP_TIMEOUT)) #define CISP_SEND_OUT(x, a) (cisp_send_read((x), (a), sizeof(*a), sizeof(*a))) -#define CISP_POST_IN(x, a) (cisp_send((x), &(a), sizeof(a), 0, 0)) -#define CISP_POST_INOUT(x, a) (cisp_send((x), &(a), sizeof(a), sizeof(a), 0)) +#define CISP_POST_IN(x, a) (isp_cmd_send((x), &(a), sizeof(a), 0, 0)) +#define CISP_POST_INOUT(x, a) (isp_cmd_send((x), &(a), sizeof(a), sizeof(a), 0)) -static int cisp_send(struct apple_isp *isp, void *args, u32 insize, u32 outsize, int timeout) +int isp_cmd_send(struct apple_isp *isp, void *args, u32 insize, u32 outsize, int timeout) { - struct isp_channel *chan = isp->chan_io; - struct isp_message *req = &chan->req; + struct isp_channel *chan; + struct isp_message *req; int err; +#if IS_ENABLED(CONFIG_VIDEO_APPLE_ISP_KUNIT_TEST) + KUNIT_STATIC_STUB_REDIRECT(isp_cmd_send, isp, args, insize, outsize, timeout); +#endif + /* Before the command area is overwritten */ + err = isp_ipc_resync(isp); + if (err) + return err; + chan = isp->chan_io; + req = &chan->req; + req->arg0 = isp->cmd_iova; req->arg1 = insize; req->arg2 = outsize; memcpy(isp->cmd_virt, args, insize); err = ipc_chan_send(isp, chan, timeout); + /* + * An answered request leaves the ring in step, so a malformed answer + * fails only this command. A timeout is resolved before the next one. + */ + if (isp_is_p010(isp)) { + struct isp_message *rsp = &chan->rsp; + + if (!err && timeout && + (rsp->arg1 != outsize || rsp->arg2 || rsp->arg3 || + rsp->arg4 || rsp->arg5 || rsp->arg6 || rsp->arg7 || + get_unaligned_le64(isp->cmd_virt) != get_unaligned_le64(args))) + err = -EIO; + } if (err) { u64 opcode; memcpy(&opcode, args, sizeof(opcode)); @@ -45,7 +73,7 @@ static int cisp_send_read(struct apple_isp *isp, void *args, u32 insize, u32 outsize) { /* TODO do I need to lock the iova space? */ - int err = cisp_send(isp, args, insize, outsize, CISP_TIMEOUT); + int err = isp_cmd_send(isp, args, insize, outsize, CISP_TIMEOUT); if (err) return err; @@ -151,16 +179,24 @@ int isp_cmd_set_dsid_clr_req_base(struct apple_isp *isp, u64 dsid_clr_base, return CISP_SEND_IN(isp, args); } -int isp_cmd_set_dsid_clr_multi_bc(struct apple_isp *isp, u64 dsid_clr_base, - u32 dsid_clr_range) +int isp_cmd_set_dsid_clr_multi_bc(struct apple_isp *isp, const u64 *bases, + unsigned int count, u32 dsid_clr_range) { struct cmd_set_dsid_clr_multi_bc_reg_base args = { .opcode = CISP_OPCODE(CISP_CMD_SET_DSID_CLR_MULTI_BC_REG_BASE), - .count = 1, + .count = count, .dsid_clr_range = dsid_clr_range, - .dsid_clr_base = dsid_clr_base, }; - return CISP_SEND_IN(isp, args); + + /* The caller, isp_set_dsid_clr(), bounds count by the array. */ + if (!count) + return -EINVAL; + memcpy(args.dsid_clr_base, bases, count * sizeof(*bases)); + + return isp_cmd_send(isp, &args, + offsetof(typeof(args), dsid_clr_base) + + count * sizeof(*bases), 0, + CISP_TIMEOUT); } int isp_cmd_pmp_ctrl_set(struct apple_isp *isp, u64 clock_scratch, @@ -224,6 +260,8 @@ int isp_cmd_flicker_sensor_set(struct apple_isp *isp, u32 mode) .opcode = CISP_OPCODE(CISP_CMD_FLICKER_SENSOR_SET), .mode = mode, }; + if (isp_is_p010(isp)) + return CISP_SEND_IN(isp, args); return CISP_SEND_INOUT(isp, args); } @@ -252,6 +290,16 @@ int isp_cmd_ch_info_get(struct apple_isp *isp, u32 chan, return err; } +int isp_cmd_ch_camera_config_get(struct apple_isp *isp, u32 chan, u32 index, + struct cmd_ch_camera_config_h17 *args) +{ + memset(args, 0, sizeof(*args)); + args->config.opcode = CISP_OPCODE(CISP_CMD_CH_CAMERA_CONFIG_GET); + args->config.chan = chan; + args->config.preset = index; + return CISP_SEND_OUT(isp, args); +} + int isp_cmd_ch_camera_config_current_get(struct apple_isp *isp, u32 chan, struct cmd_ch_camera_config *args) { @@ -460,9 +508,9 @@ int isp_cmd_ch_buffer_pool_config_set(struct apple_isp *isp, u32 chan, u16 type) .opcode = CISP_OPCODE(CISP_CMD_CH_BUFFER_POOL_CONFIG_SET), .chan = chan, .type = type, - .count = ISP_MAX_BUFFERS, - .meta_size0 = size, - .meta_size1 = size, + .count = isp_num_meta(isp), + .meta_size0 = isp_is_p010(isp) ? 0x8000 : size, + .meta_size1 = isp_is_p010(isp) ? 0x8000 : size, .unk0 = 0, .unk1 = 0, .unk2 = 0, @@ -481,7 +529,8 @@ int isp_cmd_ch_buffer_pool_config_set_rendered(struct apple_isp *isp, u32 chan, struct cmd_ch_buffer_pool_config_set_rendered args = { .opcode = CISP_OPCODE(CISP_CMD_CH_BUFFER_POOL_CONFIG_SET), .chan = chan, - .type = CISP_POOL_TYPE_RENDERED, + .type = isp->hw->scl1 ? CISP_POOL_TYPE_RENDERED_SCL1 : + CISP_POOL_TYPE_RENDERED, .count = count, .plane0_size = plane0_size, .plane0_stride = plane0_stride, @@ -558,6 +607,49 @@ int isp_cmd_apple_ch_temporal_filter_disable(struct apple_isp *isp, u32 chan) return CISP_SEND_IN(isp, args); } +int isp_cmd_apple_ch_tnr_start_h17(struct apple_isp *isp, u32 chan) +{ + struct cmd_apple_ch_temporal_filter_start_h17 args = { + .opcode = CISP_OPCODE(CISP_CMD_APPLE_CH_TEMPORAL_FILTER_START), + .chan = chan, + .unk_c = 1, + }; + return CISP_SEND_IN(isp, args); +} + +int isp_cmd_apple_ch_tnr_high_strength_set(struct apple_isp *isp, u32 chan, + u32 enable) +{ + struct cmd_apple_ch_temporal_filter_enable_set args = { + .opcode = CISP_OPCODE(CISP_CMD_APPLE_CH_TEMPORAL_FILTER_HIGH_STRENGTH), + .chan = chan, + .enable = enable, + }; + return CISP_SEND_IN(isp, args); +} + +int isp_cmd_apple_ch_tnr_band0_mod_set(struct apple_isp *isp, u32 chan, + u32 enable) +{ + struct cmd_apple_ch_temporal_filter_enable_set args = { + .opcode = CISP_OPCODE(CISP_CMD_APPLE_CH_TEMPORAL_FILTER_BAND0_MODULATION), + .chan = chan, + .enable = enable, + }; + return CISP_SEND_IN(isp, args); +} + +int isp_cmd_apple_ch_tnr_band0_threshold_set(struct apple_isp *isp, u32 chan, + u32 first, u32 second) +{ + struct cmd_apple_ch_temporal_filter_band0_threshold args = { + .opcode = CISP_OPCODE(CISP_CMD_APPLE_CH_TEMPORAL_FILTER_BAND0_THRESHOLD), + .chan = chan, + .threshold = { first, second }, + }; + return CISP_SEND_IN(isp, args); +} + int isp_cmd_ch_ae_stability_set(struct apple_isp *isp, u32 chan, u32 stability) { struct cmd_ch_ae_stability_set args = { @@ -637,6 +729,17 @@ int isp_cmd_apple_ch_ae_metering_mode_set(struct apple_isp *isp, u32 chan, return CISP_SEND_IN(isp, args); } +int isp_cmd_ch_lsc_ideal_percent_set(struct apple_isp *isp, u32 chan, + u16 percent) +{ + struct cmd_ch_lsc_ideal_percent_set args = { + .opcode = CISP_OPCODE(CISP_CMD_CH_LSC_IDEAL_PERCENT_SET), + .chan = chan, + .percent = percent, + }; + return CISP_SEND_IN(isp, args); +} + int isp_cmd_apple_ch_ae_flicker_freq_update_current_set(struct apple_isp *isp, u32 chan, u32 freq) { diff --git a/drivers/media/platform/apple/isp/isp-cmd.h b/drivers/media/platform/apple/isp/isp-cmd.h index ab0c85023bebf1..acbd864816d283 100644 --- a/drivers/media/platform/apple/isp/isp-cmd.h +++ b/drivers/media/platform/apple/isp/isp-cmd.h @@ -70,6 +70,7 @@ #define CISP_CMD_CH_ALS_DISABLE 0x0a1d #define CISP_CMD_CH_CNR_START 0x0a2f #define CISP_CMD_CH_MBNR_ENABLE 0x0a3a +#define CISP_CMD_CH_LSC_IDEAL_PERCENT_SET 0x0a4e #define CISP_CMD_CH_OUTPUT_CONFIG_SET 0x0b01 #define CISP_CMD_CH_OUTPUT_CONFIG_SCL1_SET 0x0b09 #define CISP_CMD_CH_PREVIEW_STREAM_SET 0x0b0d @@ -97,6 +98,9 @@ #define CISP_CMD_APPLE_CH_MOTION_HISTORY_STOP 0xc103 #define CISP_CMD_APPLE_CH_TEMPORAL_FILTER_ENABLE 0xc113 #define CISP_CMD_APPLE_CH_TEMPORAL_FILTER_DISABLE 0xc114 +#define CISP_CMD_APPLE_CH_TEMPORAL_FILTER_BAND0_MODULATION 0xc11c +#define CISP_CMD_APPLE_CH_TEMPORAL_FILTER_BAND0_THRESHOLD 0xc11d +#define CISP_CMD_APPLE_CH_TEMPORAL_FILTER_HIGH_STRENGTH 0xc120 #define CISP_POOL_TYPE_META 0x0 #define CISP_POOL_TYPE_RENDERED 0x1 @@ -124,6 +128,7 @@ #define CISP_COLORSPACE_REC709 0x1 #define CISP_OUTPUT_FORMAT_YUV_2PLANE 0x0 #define CISP_OUTPUT_FORMAT_YUV_1PLANE 0x1 +#define CISP_OUTPUT_FORMAT_P010 0x12 #define CISP_OUTPUT_FORMAT_RGB 0x2 #define CISP_BUFFER_RECYCLE_MODE_EMPTY_ONLY 0x1 @@ -197,15 +202,20 @@ struct cmd_set_dsid_clr_req_base { } __packed; static_assert(sizeof(struct cmd_set_dsid_clr_req_base) == 0x14); -/* H17: a count of broadcast-clear windows and the first window */ +/* + * H17: a count of broadcast-clear windows, their common range and the + * windows; the command carries only the @count windows. + */ +#define ISP_DSID_MULTI_BC_MAX 8 + struct cmd_set_dsid_clr_multi_bc_reg_base { u64 opcode; u8 count; u8 pad_9[3]; u32 dsid_clr_range; - u64 dsid_clr_base; + u64 dsid_clr_base[ISP_DSID_MULTI_BC_MAX]; } __packed; -static_assert(sizeof(struct cmd_set_dsid_clr_multi_bc_reg_base) == 0x18); +static_assert(sizeof(struct cmd_set_dsid_clr_multi_bc_reg_base) == 0x50); struct cmd_pmp_ctrl_set { u64 opcode; @@ -250,6 +260,8 @@ struct cmd_flicker_sensor_set { } __packed; static_assert(sizeof(struct cmd_flicker_sensor_set) == 0xc); +int isp_cmd_send(struct apple_isp *isp, void *args, u32 insize, u32 outsize, + int timeout); int isp_cmd_start(struct apple_isp *isp, u32 mode); int isp_cmd_stop(struct apple_isp *isp, u32 mode); int isp_cmd_power_down(struct apple_isp *isp); @@ -260,8 +272,8 @@ int isp_cmd_config_get(struct apple_isp *isp, struct cmd_config_get *args); int isp_cmd_set_isp_pmu_base(struct apple_isp *isp, u64 pmu_base); int isp_cmd_set_dsid_clr_req_base(struct apple_isp *isp, u64 dsid_clr_base, u32 dsid_clr_range); -int isp_cmd_set_dsid_clr_multi_bc(struct apple_isp *isp, u64 dsid_clr_base, - u32 dsid_clr_range); +int isp_cmd_set_dsid_clr_multi_bc(struct apple_isp *isp, const u64 *bases, + unsigned int count, u32 dsid_clr_range); int isp_cmd_set_dsid_clr_req_base2(struct apple_isp *isp, u64 dsid_clr_base0, u64 dsid_clr_base1, u64 dsid_clr_base2, u64 dsid_clr_base3, u32 dsid_clr_range0, @@ -375,6 +387,15 @@ struct cmd_ch_camera_config { } __packed; static_assert(sizeof(struct cmd_ch_camera_config) == 0xdc); +/* H17 appends 0x44 bytes to the common camera configuration record. */ +struct cmd_ch_camera_config_h17 { + struct cmd_ch_camera_config config; + u8 unknown[0x44]; +} __packed; +static_assert(sizeof(struct cmd_ch_camera_config_h17) == 0x120); +static_assert(offsetof(struct cmd_ch_camera_config, in_width) == 0x10); +static_assert(offsetof(struct cmd_ch_camera_config, out_width2) == 0xd4); + struct cmd_ch_camera_config_select { u64 opcode; u32 chan; @@ -511,6 +532,8 @@ int isp_cmd_ch_start(struct apple_isp *isp, u32 chan); int isp_cmd_ch_stop(struct apple_isp *isp, u32 chan); int isp_cmd_ch_info_get(struct apple_isp *isp, u32 chan, struct cmd_ch_info *args); +int isp_cmd_ch_camera_config_get(struct apple_isp *isp, u32 chan, u32 index, + struct cmd_ch_camera_config_h17 *args); int isp_cmd_ch_camera_config_current_get(struct apple_isp *isp, u32 chan, struct cmd_ch_camera_config *args); int isp_cmd_ch_camera_config_select(struct apple_isp *isp, u32 chan, @@ -624,6 +647,32 @@ struct cmd_apple_ch_temporal_filter_start { } __packed; static_assert(sizeof(struct cmd_apple_ch_temporal_filter_start) == 0x14); +/* The H17 firmware's start record carries one more word, sent as zero. */ +struct cmd_apple_ch_temporal_filter_start_h17 { + u64 opcode; + u32 chan; + u32 unk_c; + u32 unk_10; + u32 unk_14; +} __packed; +static_assert(sizeof(struct cmd_apple_ch_temporal_filter_start_h17) == 0x18); + +/* High-strength filtering (0xc120) and band 0 modulation (0xc11c) */ +struct cmd_apple_ch_temporal_filter_enable_set { + u64 opcode; + u32 chan; + u32 enable; +} __packed; +static_assert(sizeof(struct cmd_apple_ch_temporal_filter_enable_set) == 0x10); + +/* Band 0 strength modulation thresholds, in 1/256 steps */ +struct cmd_apple_ch_temporal_filter_band0_threshold { + u64 opcode; + u32 chan; + u32 threshold[2]; +} __packed; +static_assert(sizeof(struct cmd_apple_ch_temporal_filter_band0_threshold) == 0x14); + struct cmd_apple_ch_temporal_filter_stop { u64 opcode; u32 chan; @@ -660,6 +709,13 @@ int isp_cmd_apple_ch_motion_history_start(struct apple_isp *isp, u32 chan); int isp_cmd_apple_ch_motion_history_stop(struct apple_isp *isp, u32 chan); int isp_cmd_apple_ch_temporal_filter_enable(struct apple_isp *isp, u32 chan); int isp_cmd_apple_ch_temporal_filter_disable(struct apple_isp *isp, u32 chan); +int isp_cmd_apple_ch_tnr_start_h17(struct apple_isp *isp, u32 chan); +int isp_cmd_apple_ch_tnr_high_strength_set(struct apple_isp *isp, u32 chan, + u32 enable); +int isp_cmd_apple_ch_tnr_band0_mod_set(struct apple_isp *isp, u32 chan, + u32 enable); +int isp_cmd_apple_ch_tnr_band0_threshold_set(struct apple_isp *isp, u32 chan, + u32 first, u32 second); struct cmd_ch_ae_stability_set { u64 opcode; @@ -709,6 +765,15 @@ struct cmd_apple_ch_ae_fd_scene_metering_config_set { static_assert(sizeof(struct cmd_apple_ch_ae_fd_scene_metering_config_set) == 0x24); +/* The lens shading falloff the firmware corrects to, in percent at the corner */ +struct cmd_ch_lsc_ideal_percent_set { + u64 opcode; + u32 chan; + u16 percent; + u16 pad; +} __packed; +static_assert(sizeof(struct cmd_ch_lsc_ideal_percent_set) == 0x10); + struct cmd_apple_ch_ae_metering_mode_set { u64 opcode; u32 chan; @@ -737,6 +802,8 @@ int isp_cmd_apple_ch_ae_fd_scene_metering_config_set(struct apple_isp *isp, u32 chan); int isp_cmd_apple_ch_ae_metering_mode_set(struct apple_isp *isp, u32 chan, u32 mode); +int isp_cmd_ch_lsc_ideal_percent_set(struct apple_isp *isp, u32 chan, + u16 percent); int isp_cmd_apple_ch_ae_flicker_freq_update_current_set(struct apple_isp *isp, u32 chan, u32 freq); diff --git a/drivers/media/platform/apple/isp/isp-drv-test.c b/drivers/media/platform/apple/isp/isp-drv-test.c new file mode 100644 index 00000000000000..dbddb079a0f572 --- /dev/null +++ b/drivers/media/platform/apple/isp/isp-drv-test.c @@ -0,0 +1,135 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * KUnit tests for the per-SoC data of the Apple ISP driver, built into + * isp-drv.c: the DART address filter windows and the firmware start. They + * need no hardware. + */ + +#include +#include +#include + +/* Every address filter window must lie inside a window the firmware is mapped. */ +static void isp_test_dapf_in_fw_mmio(struct kunit *test) +{ + const struct of_device_id *match; + + for (match = apple_isp_of_match; match->compatible[0]; match++) { + const struct apple_isp_hw *hw = match->data; + + for (unsigned int i = 0; i < hw->num_dapf; i++) { + const struct isp_dapf_window *w = &hw->dapf[i]; + bool inside = false; + + KUNIT_EXPECT_LE_MSG(test, w->start, w->end, "%s window %u", + match->compatible, i); + for (unsigned int j = 0; j < hw->num_fw_mmio; j++) { + const struct isp_mmio_window *m = &hw->fw_mmio[j]; + + if (w->start >= m->base && w->end < m->base + m->size) + inside = true; + } + KUNIT_EXPECT_TRUE_MSG(test, inside, + "%s window %u 0x%llx-0x%llx is not in fw_mmio", + match->compatible, i, w->start, w->end); + } + } +} + +#define ISP_TEST_DAPF_FILL 0xa5 + +/* + * Each window fills its own 0x40-byte slot with exactly these words, and + * leaves every other byte alone. The bank is plain memory here: the driver + * is arm64 only, where the MMIO accessors work on it unchanged. + */ +static void isp_test_dapf_program(struct kunit *test) +{ + static const struct isp_dapf_window windows[] = { + { 0x380704000, 0x380704063 }, + { 0x382824000, 0x382824004 }, + }; + static const struct apple_isp_hw hw = { + .dapf = windows, + .num_dapf = ARRAY_SIZE(windows), + }; + size_t size = (ARRAY_SIZE(windows) + 1) * DAPF_WINDOW_STRIDE; + u8 expect[DAPF_WINDOW_STRIDE]; + struct apple_isp *isp; + u8 *bank; + + isp = kunit_kzalloc(test, sizeof(*isp), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, isp); + isp->dev = kunit_device_register(test, "apple-isp-dapf-test"); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, isp->dev); + bank = kunit_kmalloc(test, size, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, bank); + memset(bank, ISP_TEST_DAPF_FILL, size); + isp->hw = &hw; + isp->dapf = (__force void __iomem *)bank; + + KUNIT_ASSERT_EQ(test, apple_isp_program_dapf(isp), 0); + + for (unsigned int i = 0; i < ARRAY_SIZE(windows); i++) { + memset(expect, ISP_TEST_DAPF_FILL, sizeof(expect)); + put_unaligned_le32(0x31, &expect[0x00]); + put_unaligned_le32(0, &expect[0x04]); + put_unaligned_le64(windows[i].start, &expect[0x08]); + put_unaligned_le64(windows[i].end, &expect[0x10]); + put_unaligned_le32(1, &expect[0x20]); + KUNIT_EXPECT_MEMEQ_MSG(test, bank + i * DAPF_WINDOW_STRIDE, expect, + sizeof(expect), "window %u", i); + } + + /* The slot after the last window is untouched. */ + KUNIT_EXPECT_NULL(test, memchr_inv(bank + ARRAY_SIZE(windows) * DAPF_WINDOW_STRIDE, + ISP_TEST_DAPF_FILL, DAPF_WINDOW_STRIDE)); +} + +static struct kunit_case isp_dapf_test_cases[] = { + KUNIT_CASE(isp_test_dapf_in_fw_mmio), + KUNIT_CASE(isp_test_dapf_program), + {} +}; + +static struct kunit_suite isp_dapf_test_suite = { + .name = "apple-isp-dapf", + .test_cases = isp_dapf_test_cases, +}; + +kunit_test_suite(isp_dapf_test_suite); + +/* + * A deferred start detects the camera once: its firmware must keep running + * or start again. Firmware that starts again is not resident, and only it + * is quiesced before the power-down. + */ +static void isp_test_firmware_lifetime(struct kunit *test) +{ + const struct of_device_id *match; + + for (match = apple_isp_of_match; match->compatible[0]; match++) { + const struct apple_isp_hw *hw = match->data; + + if (hw->deferred_start) + KUNIT_EXPECT_TRUE_MSG(test, hw->resident_fw || hw->fw_restore, + "%s", match->compatible); + KUNIT_EXPECT_FALSE_MSG(test, hw->resident_fw && hw->fw_restore, "%s", + match->compatible); + if (hw->coproc_quiesce) + KUNIT_EXPECT_TRUE_MSG(test, hw->fw_restore, "%s", + match->compatible); + } +} + +static struct kunit_case isp_hw_test_cases[] = { + KUNIT_CASE(isp_test_firmware_lifetime), + {} +}; + +static struct kunit_suite isp_hw_test_suite = { + .name = "apple-isp-hw", + .test_cases = isp_hw_test_cases, +}; + +kunit_test_suite(isp_hw_test_suite); diff --git a/drivers/media/platform/apple/isp/isp-drv.c b/drivers/media/platform/apple/isp/isp-drv.c index 2cbdcd2fb00bde..53a54604ca613a 100644 --- a/drivers/media/platform/apple/isp/isp-drv.c +++ b/drivers/media/platform/apple/isp/isp-drv.c @@ -5,10 +5,12 @@ * Copyright (C) 2023 The Asahi Linux Contributors */ +#include #include #include #include #include +#include #include #include #include @@ -20,6 +22,41 @@ #include "isp-regs.h" #include "isp-v4l2.h" +static void apple_isp_kvfree(void *data) +{ + kvfree(data); +} + +/* + * Keep a copy of the firmware data segment as the boot loader loaded it + * (hw->fw_restore). This must run before the firmware first starts. + */ +static int apple_isp_copy_fw_data(struct apple_isp *isp) +{ + struct device *dev = isp->dev; + struct resource res; + int err; + + err = of_reserved_mem_region_to_resource_byname(dev->of_node, "data", &res); + if (err) + return err; + + isp->fw_data_size = resource_size(&res); + isp->fw_data = devm_memremap(dev, res.start, isp->fw_data_size, MEMREMAP_WB); + if (IS_ERR(isp->fw_data)) + return PTR_ERR(isp->fw_data); + + isp->fw_data_copy = kvmalloc(isp->fw_data_size, GFP_KERNEL); + if (!isp->fw_data_copy) + return -ENOMEM; + err = devm_add_action_or_reset(dev, apple_isp_kvfree, isp->fw_data_copy); + if (err) + return err; + + memcpy(isp->fw_data_copy, isp->fw_data, isp->fw_data_size); + return 0; +} + static void apple_isp_detach_genpd(struct apple_isp *isp) { if (isp->pd_count <= 1) @@ -144,17 +181,117 @@ static int apple_isp_map_fw_mmio(struct apple_isp *isp) return 0; } +/* The IOVA range of a memory-region, from its last iommu-addresses entry. */ +static int isp_of_region_iova(struct device *dev, const char *name, + phys_addr_t *base, size_t *size) +{ + const __be32 *maps, *end; + int idx, len; + + idx = of_property_match_string(dev->of_node, "memory-region-names", + name); + if (idx < 0) + return -ENOENT; + + struct device_node *np __free(device_node) = + of_parse_phandle(dev->of_node, "memory-region", idx); + if (!np) + return -ENODEV; + + maps = of_get_property(np, "iommu-addresses", &len); + if (!maps || !len) + return -ENODEV; + + end = maps + len / sizeof(__be32); + + while (maps < end) { + maps++; + maps = of_translate_dma_region(dev->of_node, maps, base, size); + } + + return 0; +} + +/* + * The firmware reaches its fixed MMIO windows through the first DART, whose + * address filter the ADT describes for them. Its registers are on that DART. + */ +static int apple_isp_map_dapf(struct apple_isp *isp) +{ + struct device *dev = isp->dev; + /* The first iommus entry, whatever its #iommu-cells */ + struct device_node *dart __free(device_node) = + of_parse_phandle(dev->of_node, "iommus", 0); + struct resource res; + int idx, err; + + if (!dart) + return dev_err_probe(dev, -ENODEV, "no ISP DART\n"); + + /* DAPF_* describe the T8110 DART's address filter */ + if (!of_device_is_compatible(dart, "apple,t8110-dart")) + return dev_err_probe(dev, -ENODEV, + "%pOF has no known address filter\n", dart); + + idx = of_property_match_string(dart, "reg-names", "dapf"); + if (idx < 0) + return dev_err_probe(dev, idx, + "%pOF has no address filter registers\n", dart); + + err = of_address_to_resource(dart, idx, &res); + if (err) + return dev_err_probe(dev, err, "%pOF: bad address filter registers\n", + dart); + + if (resource_size(&res) < isp->hw->num_dapf * DAPF_WINDOW_STRIDE) + return dev_err_probe(dev, -EINVAL, "%pOF: address filter too small\n", + dart); + + isp->dapf = devm_ioremap_resource(dev, &res); + return PTR_ERR_OR_ZERO(isp->dapf); +} + +/* Program the address filter windows, then check that they took. */ +int apple_isp_program_dapf(struct apple_isp *isp) +{ + const struct apple_isp_hw *hw = isp->hw; + u32 ctrl2 = hw->dapf_ctrl2 ?: DAPF_CTRL2_ISP; + void __iomem *w; + unsigned int i; + + for (i = 0; i < hw->num_dapf; i++) { + w = isp->dapf + i * DAPF_WINDOW_STRIDE; + writel(0, w + DAPF_CTRL1); + writeq(hw->dapf[i].start, w + DAPF_START); + writeq(hw->dapf[i].end, w + DAPF_END); + writel(DAPF_CTRL0_ISP, w + DAPF_CTRL0); + writel(ctrl2, w + DAPF_CTRL2); + } + + /* Only bits 7:0 of CTRL0 and bits 63:2 of END read back. */ + for (i = 0; i < hw->num_dapf; i++) { + w = isp->dapf + i * DAPF_WINDOW_STRIDE; + if (readl(w + DAPF_CTRL1) || + readq(w + DAPF_START) != hw->dapf[i].start || + (readq(w + DAPF_END) | 3) != (hw->dapf[i].end | 3) || + (readl(w + DAPF_CTRL0) & 0xff) != DAPF_CTRL0_ISP || + readl(w + DAPF_CTRL2) != ctrl2) { + dev_err(isp->dev, "DAPF window %u (0x%llx-0x%llx) failed readback\n", + i, hw->dapf[i].start, hw->dapf[i].end); + return -EIO; + } + } + + return 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; + phys_addr_t heap_base, data_base; + size_t heap_size, data_size; u64 vm_size; int err; - int idx; - int size; - struct device_node *mem_node; - const __be32 *maps, *end; isp->domain = iommu_get_domain_for_dev(isp->dev); if (!isp->domain) @@ -162,30 +299,38 @@ static int apple_isp_init_iommu(struct apple_isp *isp) isp->shift = __ffs(isp->domain->pgsize_bitmap); isp->fw_iova_mask = isp->hw->fw_iova_mask ?: U64_MAX; - idx = of_property_match_string(dev->of_node, "memory-region-names", - "heap"); - mem_node = of_parse_phandle(dev->of_node, "memory-region", idx); - 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) { + err = isp_of_region_iova(dev, "heap", &heap_base, &heap_size); + if (err) { dev_err(dev, "No valid iommu-addresses found for heap\n"); return -ENODEV; } - end = maps + size / sizeof(__be32); + isp->fw.heap_base = heap_base; + isp->fw.heap_top = heap_base + heap_size; - while (maps < end) { - maps++; - maps = of_translate_dma_region(dev->of_node, maps, &heap_base, - &heap_size); + /* + * Where the bootloader loads the firmware's data, it backs the + * firmware's main memory only up to the end of it. The rest, up to + * the heap top, is the host's to back. + */ + err = -ENOENT; + if (isp->hw->gen == ISP_GEN_T6040) + err = isp_of_region_iova(dev, "data", &data_base, &data_size); + if (!err) { + isp->fw.data_top = data_base + data_size; + if (isp->fw.data_top <= isp->fw.heap_base || + isp->fw.data_top > isp->fw.heap_top || + !IS_ALIGNED(isp->fw.data_top, 1UL << isp->shift)) { + dev_err(dev, "data 0x%llx outside the heap 0x%llx-0x%llx\n", + isp->fw.data_top, isp->fw.heap_base, + isp->fw.heap_top); + return -EINVAL; + } + } else if (err != -ENOENT) { + dev_err(dev, "No valid iommu-addresses found for data\n"); + return -ENODEV; } - isp->fw.heap_top = heap_base + heap_size; - err = of_property_read_u64(dev->of_node, "apple,dart-vm-size", &vm_size); if (err) { @@ -195,11 +340,11 @@ static int apple_isp_init_iommu(struct apple_isp *isp) // FIXME: refactor this, maybe use regular iova stuff? isp->iova_size = vm_size - (heap_base & 0xffffffff); - drm_mm_init(&isp->iovad, isp->fw.heap_top, isp->iova_size); + mt_init_flags(&isp->iovas, MT_FLAGS_ALLOC_RANGE); err = apple_isp_map_fw_mmio(isp); if (err) { - drm_mm_takedown(&isp->iovad); + mtree_destroy(&isp->iovas); return err; } @@ -209,7 +354,8 @@ static int apple_isp_init_iommu(struct apple_isp *isp) static void apple_isp_free_iommu(struct apple_isp *isp) { apple_isp_unmap_fw_mmio(isp, isp->hw->num_fw_mmio); - drm_mm_takedown(&isp->iovad); + WARN_ON(!mtree_empty(&isp->iovas)); + mtree_destroy(&isp->iovas); } static int isp_of_read_coord(struct device *dev, struct device_node *np, @@ -434,6 +580,10 @@ static int apple_isp_probe(struct platform_device *pdev) isp->temporal_filter = 0; } + /* the sensor connection layout, for firmware that takes it at boot */ + of_property_read_u32(dev->of_node, "apple,cam-connections-scheme", + &isp->cam_connections_scheme); + err = apple_isp_init_presets(isp); if (err) { dev_err(dev, "failed to initialize presets\n"); @@ -482,6 +632,12 @@ static int apple_isp_probe(struct platform_device *pdev) } } + if (isp->hw->num_dapf) { + err = apple_isp_map_dapf(isp); + if (err) + goto detach_genpd; + } + /* Capture watchdog, where the ISP gates its frames on one */ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "wdt"); if (res) { @@ -493,6 +649,26 @@ static int apple_isp_probe(struct platform_device *pdev) apple_isp_wdt_init(isp); } + if (isp->hw->camera_light) { + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cil"); + if (!res || + of_property_read_u32(dev->of_node, "apple,cil-config", + &isp->cil_config)) { + dev_err(dev, "no camera light described, not using the camera\n"); + err = -ENODEV; + goto detach_genpd; + } + /* Not requested: the pin sits in a GPIO block Linux does not own. */ + isp->cil = devm_ioremap(dev, res->start, resource_size(res)); + if (!isp->cil) { + err = -ENOMEM; + goto detach_genpd; + } + isp->cil_on_high = of_property_read_bool(dev->of_node, + "apple,cil-active-high"); + isp->cil_saved = readl(isp->cil); + } + isp->irq = platform_get_irq(pdev, 0); if (isp->irq < 0) { err = isp->irq; @@ -503,7 +679,6 @@ static int apple_isp_probe(struct platform_device *pdev) goto detach_genpd; } - mutex_init(&isp->iovad_lock); mutex_init(&isp->video_lock); spin_lock_init(&isp->buf_lock); init_waitqueue_head(&isp->wait); @@ -512,6 +687,7 @@ static int apple_isp_probe(struct platform_device *pdev) mutex_init(&isp->gc_lock); INIT_LIST_HEAD(&isp->bufs_pending); INIT_LIST_HEAD(&isp->bufs_submitted); + INIT_LIST_HEAD(&isp->bufs_returned); isp->wq = alloc_workqueue("apple-isp-wq", WQ_UNBOUND, 0); if (!isp->wq) { dev_err(dev, "failed to create workqueue\n"); @@ -531,12 +707,23 @@ static int apple_isp_probe(struct platform_device *pdev) goto free_iommu; } + if (isp->hw->fw_restore) { + err = apple_isp_copy_fw_data(isp); + if (err) { + dev_err(dev, "failed to copy the firmware data: %d\n", err); + apple_isp_free_firmware_surface(isp); + goto free_iommu; + } + } + pm_runtime_enable(dev); - err = apple_isp_detect_camera(isp); - if (err) { - dev_err(dev, "failed to detect camera: %d\n", err); - goto free_surface; + if (!isp->hw->deferred_start) { + err = apple_isp_detect_camera(isp); + if (err) { + dev_err(dev, "failed to detect camera: %d\n", err); + goto free_surface; + } } err = apple_isp_setup_video(isp); @@ -559,6 +746,7 @@ static int apple_isp_probe(struct platform_device *pdev) detach_genpd: apple_isp_detach_genpd(isp); free_isp: + kfree(isp->sensor_configs); /* Nothing else can reach it before the video device is registered. */ kfree(isp); return err; @@ -799,6 +987,277 @@ static const struct apple_isp_hw apple_isp_hw_t8140 = { .boot_mode = 1, .capture_meta_size = ISP_CAPTURE_META_SIZE_T8140, .resident_fw = true, + .meta_exposure = true, +}; + +/* The same for T6040, from the J616s ADT's DART address filter. */ +static const struct isp_mmio_window apple_isp_fw_mmio_t6040[] = { + { 0x220004000, 0x1d4000 }, /* DSID broadcast-clear windows */ + { 0x222004000, 0x1d4000 }, + { 0x224004000, 0x1d4000 }, + { 0x226004000, 0x1d4000 }, + { 0x485660000, 0x4000 }, + { 0x5003c0000, 0x28000 }, /* PMGR, with the PMP clock scratch */ + { 0x500e3c000, 0x4000 }, + { 0x502284000, 0x4000 }, /* PMGR, ISP power states */ + { 0x502880000, 0x8000 }, + { 0x504824000, 0x4000 }, /* PMP bandwidth scratch */ + { 0x51062c000, 0x20000 }, +}; + +/* + * T6040 runs the same coprocessor and firmware interface as T8140, booted + * as macOS boots it on the J616s (macOS 26.6.2 camera log, kext register + * map) and as aurora's m1n1 proxy captures with it: no coprocessor reset, + * four broadcast-clear windows in eight slots, the scaler 1 output path and + * no capture metadata pool or watchdog. + */ +static const struct apple_isp_hw apple_isp_hw_t6040 = { + .gen = ISP_GEN_T6040, + .fw_abi = ISP_FW_ABI_H17, + .pmu_base = 0x0, + + .dsid_count = 4, + .dsid_slots = 8, + .dsid_clr_base0 = 0x2201d4000, + .dsid_clr_base1 = 0x2221d4000, + .dsid_clr_base2 = 0x2241d4000, + .dsid_clr_base3 = 0x2261d4000, + .dsid_clr_range0 = 0x2fc, + + /* the PMGR and PMP scratch words of the ISP's DAPF windows */ + .clock_scratch = 0x5003d0fa8, + .clock_base = 0x0, + .clock_bit = 0x0, + .clock_size = 0x8, + .bandwidth_scratch = 0x504824000, + .bandwidth_base = 0x0, + .bandwidth_bit = 0x0, + .bandwidth_size = 0x8, + .mbox_irq_enable = ISP_MBOX_IRQ_ENABLE_T6031, + + .scl1 = true, + .lpdp = false, + .meta_size = ISP_META_SIZE_T8140, + .fw_mmio = apple_isp_fw_mmio_t6040, + .num_fw_mmio = ARRAY_SIZE(apple_isp_fw_mmio_t6040), + + .coproc_control = ISP_COPROC_CONTROL_T8140, + .boot_mode = 1, + .shared_size = 0xde600000, + .resident_fw = true, + .meta_exposure = true, +}; + +/* T8132: the firmware's MMIO windows, from the J713 ADT's DART address filter */ +static const struct isp_mmio_window apple_isp_fw_mmio_t8132[] = { + { 0x220004000, 0x1d4000 }, /* DSID broadcast-clear windows */ + { 0x222004000, 0x1d4000 }, + { 0x3803c0000, 0x28000 }, /* PMGR, with the PMP clock scratch */ + { 0x380704000, 0x4000 }, /* PMGR, ISP power states */ + { 0x380730000, 0x4000 }, + { 0x380e3c000, 0x4000 }, + { 0x382824000, 0x4000 }, /* PMP bandwidth scratch */ + { 0x39062c000, 0x20000 }, + { 0x501660000, 0x4000 }, +}; + +/* The ADT's DART address filter windows, in its order and with its ends */ +static const struct isp_dapf_window apple_isp_dapf_t8132[] = { + { 0x380704000, 0x380704063 }, /* PMGR, ISP power states */ + { 0x380730000, 0x380733fff }, + { 0x380e3c000, 0x380e3c003 }, + { 0x39062c000, 0x390648003 }, + { 0x501660000, 0x501660003 }, + { 0x220004000, 0x2200162fc }, /* DSID broadcast-clear windows */ + { 0x220044000, 0x2200562fc }, + { 0x2201c4000, 0x2201d62fc }, + { 0x222004000, 0x2220162fc }, + { 0x222044000, 0x2220562fc }, + { 0x2221c4000, 0x2221d62fc }, + { 0x3803c0000, 0x3803e4000 }, /* PMGR, with the PMP clock scratch */ + { 0x382824000, 0x382824004 }, /* PMP bandwidth scratch */ +}; + +/* + * T8132 runs T6040's coprocessor and firmware interface, booted the same + * way. Its two AMCCs (ADT mcc amcc_aperture_count) give two broadcast-clear + * windows, passed one per AMCC without padding slots. No PMP_CTRL_SET is + * sent: T8132's PMP scratch offsets are not established. Its firmware + * starts again from its data segment as loaded once the coprocessor was + * quiesced before the power-down, so the ISP is powered only while the + * camera is in use. + */ +static const struct apple_isp_hw apple_isp_hw_t8132 = { + .gen = ISP_GEN_T6040, + .fw_abi = ISP_FW_ABI_H17, + .pmu_base = 0x0, + + .dsid_count = 2, + .dsid_clr_base0 = 0x2201d4000, + .dsid_clr_base1 = 0x2221d4000, + .dsid_clr_range0 = 0x2fc, + + .mbox_irq_enable = ISP_MBOX_IRQ_ENABLE_T6031, + + .scl1 = true, + .lpdp = false, + .meta_size = ISP_META_SIZE_T8140, + .fw_mmio = apple_isp_fw_mmio_t8132, + .num_fw_mmio = ARRAY_SIZE(apple_isp_fw_mmio_t8132), + .dapf = apple_isp_dapf_t8132, + .num_dapf = ARRAY_SIZE(apple_isp_dapf_t8132), + + .coproc_control = ISP_COPROC_CONTROL_T8140, + .coproc_status = ISP_COPROC_STATUS_T8140, + .coproc_quiesce = ISP_COPROC_QUIESCE_T8140, + .boot_mode = 1, + .shared_size = 0xdec00000, + .fw_restore = true, + .deferred_start = true, +}; + +/* + * T8142 (M5, J813): the Neo's ISP17a. The J813 ADT's dart-isp + * dapf-instance-0 ranges, rounded out to 16 KiB pages; mostly the T8140 + * windows at +0x80000000, with one DSID window and two new ranges. + */ +static const struct isp_mmio_window apple_isp_fw_mmio_t8142[] = { + { 0x220104000, 0x14000 }, /* DSID broadcast-clear window */ + { 0x3803c0000, 0x28000 }, /* PMGR, with the PMP clock scratch */ + { 0x380704000, 0x4000 }, /* PMGR, ISP power states */ + { 0x380730000, 0x4000 }, + { 0x380e3c000, 0x4000 }, + { 0x382724000, 0x4000 }, /* PMP bandwidth scratch */ + { 0x39062c000, 0x30000 }, + { 0x3a1340000, 0x4000 }, + { 0x3a1358000, 0xc000 }, + { 0x421660000, 0x4000 }, +}; + +static const struct apple_isp_hw apple_isp_hw_t8142 = { + .gen = ISP_GEN_T8140, + .fw_abi = ISP_FW_ABI_H17, + .pmu_base = 0x0, + + .dsid_count = 1, + .dsid_clr_base0 = 0x220116000, + .dsid_clr_range0 = 0x2fc, + + .clock_scratch = 0x3803d0ca0, + .clock_base = 0x0, + .clock_bit = 0x0, + .clock_size = 0x8, + .bandwidth_scratch = 0x382724000, + .bandwidth_base = 0x0, + .bandwidth_bit = 0x0, + .bandwidth_size = 0x8, + .mbox_irq_enable = ISP_MBOX_IRQ_ENABLE_T6031, + + /* + * No BES scaler: the firmware asserts on CH_CROP_SET ("BesProc is + * removed/not present. Must config AuxSclPr") and takes the SCL1 set. + */ + .scl1 = true, + .lpdp = true, + .meta_size = ISP_META_SIZE_T8140, + + .fw_iova_mask = GENMASK_ULL(35, 0), + .mbox2_offset = 0x410, + .mbox_irq_route = true, + .coproc_control = ISP_COPROC_CONTROL_T8140, + .fw_mmio = apple_isp_fw_mmio_t8142, + .num_fw_mmio = ARRAY_SIZE(apple_isp_fw_mmio_t8142), + .boot_mode = 1, + .capture_meta_size = ISP_CAPTURE_META_SIZE_T8140, + .resident_fw = true, + /* The J813 IMX958 runs the xx24 setfile 2224_01, as T6040 does. */ + .setfile_stride_fixup = true, +}; + +/* + * T6050 (M5 Max, J714c): the J714c ADT's dart-isp0 dapf-instance-0 ranges, + * rounded out to 16 KiB pages, with eight DSID broadcast-clear windows. + */ +static const struct isp_mmio_window apple_isp_fw_mmio_t6050[] = { + { 0x2220004000, 0x14000 }, /* DSID broadcast-clear windows */ + { 0x2222004000, 0x14000 }, + { 0x2224004000, 0x14000 }, + { 0x2226004000, 0x14000 }, + { 0x2228004000, 0x14000 }, + { 0x222a004000, 0x14000 }, + { 0x222c004000, 0x14000 }, + { 0x222e004000, 0x14000 }, + { 0x280680000, 0x8000 }, + { 0x280900000, 0x4000 }, /* PMGR, ISP power states */ + { 0x284240000, 0x28000 }, /* PMGR, as T8140's PMP clock scratch window */ + { 0x284e3c000, 0x4000 }, + { 0x286724000, 0x4000 }, /* PMP bandwidth scratch */ + { 0x29062c000, 0x20000 }, + { 0x509660000, 0x4000 }, +}; + +/* The J714c ADT's dart-isp0 address filter windows, in its order and with its ends */ +static const struct isp_dapf_window apple_isp_dapf_t6050[] = { + { 0x2809003b0, 0x2809003f3 }, /* PMGR, ISP power states */ + { 0x280680000, 0x280687fff }, + { 0x284e3c000, 0x284e3c003 }, + { 0x29062c000, 0x290648003 }, + { 0x509660000, 0x509660003 }, + { 0x286724000, 0x286724004 }, /* PMP bandwidth scratch */ + { 0x284240000, 0x284264000 }, /* PMGR, as T8140's PMP clock scratch window */ + { 0x2220004000, 0x22200162fc }, /* DSID broadcast-clear windows */ + { 0x2222004000, 0x22220162fc }, + { 0x2224004000, 0x22240162fc }, + { 0x2226004000, 0x22260162fc }, + { 0x2228004000, 0x22280162fc }, + { 0x222a004000, 0x222a0162fc }, + { 0x222c004000, 0x222c0162fc }, + { 0x222e004000, 0x222e0162fc }, +}; + +/* + * T6050 (M5 Max, J714c) boots as T6040: the same isp0 and dart-isp0 + * addresses, mailbox at +0x2924000, and 32 MiB of firmware main memory at + * IOVA 0 whose __TEXT and __DATA end at 0x1fec000. The broadcast-clear + * window is the first of the eight in its DAPF ranges. The PMP clock scratch + * word is not known yet; without it the driver sends no PMP control. + */ +static const struct apple_isp_hw apple_isp_hw_t6050 = { + .gen = ISP_GEN_T6040, + .fw_abi = ISP_FW_ABI_H17, + .pmu_base = 0x0, + + .dsid_count = 1, + .dsid_slots = 8, + .dsid_clr_base0 = 0x2220016000, + .dsid_clr_range0 = 0x2fc, + + .clock_scratch = 0x0, + .mbox_irq_enable = ISP_MBOX_IRQ_ENABLE_T6031, + + .scl1 = true, + /* The sensor link is LPDP ("SIF 0 (LPDP)"), as on T8142. */ + .lpdp = true, + .meta_size = ISP_META_SIZE_T8140, + .fw_mmio = apple_isp_fw_mmio_t6050, + .num_fw_mmio = ARRAY_SIZE(apple_isp_fw_mmio_t6050), + .dapf = apple_isp_dapf_t6050, + .num_dapf = ARRAY_SIZE(apple_isp_dapf_t6050), + .dapf_ctrl2 = 0xcc3, + + .coproc_control = ISP_COPROC_CONTROL_T8140, + .boot_mode = 1, + .shared_size = 0xde600000, + .resident_fw = true, + .meta_exposure = true, + .camera_light = true, + /* The J714c's IMX958 (build revision 2) is tuned by 2226_02 */ + .imx958_2226 = true, + .setfile_radial_gain = true, + /* As macOS's appleh16camerad sets them for the J714c's IMX958 */ + .lsc_ideal_percent = 84, + .ae_fd_scene_metering = true, }; static const struct of_device_id apple_isp_of_match[] = { @@ -810,6 +1269,10 @@ static const struct of_device_id apple_isp_of_match[] = { { .compatible = "apple,t6030-isp", .data = &apple_isp_hw_t6030 }, { .compatible = "apple,t6031-isp", .data = &apple_isp_hw_t6031 }, { .compatible = "apple,t8140-isp", .data = &apple_isp_hw_t8140 }, + { .compatible = "apple,t8142-isp", .data = &apple_isp_hw_t8142 }, + { .compatible = "apple,t6050-isp", .data = &apple_isp_hw_t6050 }, + { .compatible = "apple,t6041-isp", .data = &apple_isp_hw_t6040 }, + { .compatible = "apple,t8132-isp", .data = &apple_isp_hw_t8132 }, {}, }; MODULE_DEVICE_TABLE(of, apple_isp_of_match); @@ -850,8 +1313,8 @@ static __maybe_unused int apple_isp_freeze(struct device *dev) /* * Hibernation hands the system from one kernel to another, and * firmware left running would go on using the memory of the kernel - * that started it. Stop it cleanly instead; the camera is then - * unavailable until the next system boot. + * that started it. Stop it cleanly instead; if it ran, the camera is + * then unavailable until the next system boot. */ if (isp->hw->resident_fw) { mutex_lock(&isp->video_lock); @@ -883,6 +1346,23 @@ static const struct dev_pm_ops apple_isp_pm_ops = { RUNTIME_PM_OPS(apple_isp_runtime_suspend, apple_isp_runtime_resume, NULL) }; +/* + * Stop firmware that starts again (hw->fw_restore) before a reboot or a + * kexec, so that the next kernel finds its data segment as loaded. + */ +static void apple_isp_shutdown(struct platform_device *pdev) +{ + struct apple_isp *isp = platform_get_drvdata(pdev); + + if (!isp || !isp->hw->fw_restore) + return; + /* A stream that still runs is stopped cleanly first, as for hibernation */ + apple_isp_video_suspend(isp); + mutex_lock(&isp->video_lock); + apple_isp_firmware_halt(isp); + mutex_unlock(&isp->video_lock); +} + static struct platform_driver apple_isp_driver = { .driver = { .name = "apple-isp", @@ -891,9 +1371,14 @@ static struct platform_driver apple_isp_driver = { }, .probe = apple_isp_probe, .remove = apple_isp_remove, + .shutdown = apple_isp_shutdown, }; module_platform_driver(apple_isp_driver); MODULE_AUTHOR("Eileen Yoon "); MODULE_DESCRIPTION("Apple ISP driver"); MODULE_LICENSE("GPL v2"); + +#if IS_ENABLED(CONFIG_VIDEO_APPLE_ISP_KUNIT_TEST) +#include "isp-drv-test.c" +#endif diff --git a/drivers/media/platform/apple/isp/isp-drv.h b/drivers/media/platform/apple/isp/isp-drv.h index 8f945c26f00e6d..ec8b80f3d3281f 100644 --- a/drivers/media/platform/apple/isp/isp-drv.h +++ b/drivers/media/platform/apple/isp/isp-drv.h @@ -6,11 +6,11 @@ #include #include +#include #include #include #include -#include #include #include #include @@ -30,6 +30,8 @@ /* used to limit the user space buffers to the buffer_pool_config */ #define ISP_MAX_BUFFERS 16 +#define ISP_MAX_SENSOR_CONFIGS 64 +#define ISP_SENSOR_CONFIG_SIZE 0x120 /* capture metadata buffers, for firmware that has that pool */ #define ISP_CAPMETA_BUFFERS 8 @@ -51,6 +53,7 @@ enum isp_generation { ISP_GEN_T8112, ISP_GEN_T6031, ISP_GEN_T8140, + ISP_GEN_T6040, }; /* @@ -79,7 +82,6 @@ enum isp_firmware_version { }; struct isp_surf { - struct drm_mm_node *mm; struct list_head head; u64 size; u64 type; @@ -91,6 +93,7 @@ struct isp_surf { refcount_t refcount; bool gc; bool submitted; + bool iova_reserved; /* @iova comes from &apple_isp.iovas */ }; struct isp_message { @@ -115,6 +118,8 @@ struct isp_channel { void *virt; u32 doorbell; u32 cursor; + unsigned long deadline; + bool deadline_active; struct mutex lock; struct isp_message req; struct isp_message rsp; @@ -132,12 +137,23 @@ struct isp_mmio_window { u64 size; }; +/* + * A DART address filter window. Both bounds are inclusive and word + * granular, as the hardware takes them. + */ +struct isp_dapf_window { + u64 start; + u64 end; +}; + struct isp_preset { u32 index; struct coord input_dim; struct coord output_dim; struct coord crop_offset; struct coord crop_size; + /* Processed P010 geometry established by preview or a config reply. */ + bool p010; }; struct apple_isp_hw { @@ -146,6 +162,8 @@ struct apple_isp_hw { u64 pmu_base; int dsid_count; + /* windows of the H17 multi broadcast-clear command, the unused all ones */ + u8 dsid_slots; u64 dsid_clr_base0; u64 dsid_clr_base1; u64 dsid_clr_base2; @@ -178,22 +196,79 @@ struct apple_isp_hw { bool mbox_irq_route; /* coprocessor control register, 0 for ISP_COPROC_CONTROL */ u32 coproc_control; + /* coprocessor status register, 0 for ISP_COPROC_STATUS */ + u32 coproc_status; + /* + * coprocessor quiesce register, 0 for none. The CPU core domains of + * a coprocessor that stopped only power down cleanly once it has + * quiesced; otherwise they stay busy and never run again. + */ + u32 coproc_quiesce; /* windows mapped 1:1 for the firmware */ const struct isp_mmio_window *fw_mmio; unsigned int num_fw_mmio; + /* + * The windows the ADT gives the first DART's address filter, inside + * the fw_mmio windows. The filter loses them with ISP_SYS, so they + * are programmed after every power-up. + */ + const struct isp_dapf_window *dapf; + unsigned int num_dapf; + /* The ADT's DAPF r20 word, if not DAPF_CTRL2_ISP */ + u32 dapf_ctrl2; + /* ISP_GPIO_6 boot mode */ u32 boot_mode; + /* shared memory size in the H16 boot descriptor, 0 for the T8140 one */ + u64 shared_size; + /* size of a capture metadata buffer, 0 for no such pool */ u32 capture_meta_size; + /* metadata buffers carry the frame's exposure report (H17 firmware) */ + bool meta_exposure; + /* - * The firmware can be started only once per system boot, so it is - * started at probe and kept running while the driver is bound. + * The firmware leaves its data segment changed when it stops, and + * does not start from it again. Keep a copy of the segment as the + * boot loader loaded it, taken at probe before the firmware first + * runs, and put it back whenever the firmware has stopped. + */ + bool fw_restore; + + /* + * The firmware can be started only once per system boot, so once + * started it is kept running while the driver is bound. It starts at + * probe, or at the first stream with deferred_start. */ bool resident_fw; + + /* + * Start the firmware, and detect the camera, at the first stream + * instead of at probe, so the ISP stays off until then. The firmware + * must be resident or start again (fw_restore): the camera is + * detected only once. + */ + bool deferred_start; + /* + * The camera light is the driver's to drive: no stream starts unless + * it is lit, and the capture watchdog is fed only while it is. + */ + bool camera_light; + + /* The xx24 setfiles' lens shading strides need zeroing (T8142). */ + bool setfile_stride_fixup; + /* The IMX958 module takes setfile 2226_02, not 2224_01 */ + bool imx958_2226; + /* Compute the setfile's noise reduction radial gains from its lens shading */ + bool setfile_radial_gain; + /* The lens shading falloff to correct to, in percent at the corner (0: unset) */ + u16 lsc_ideal_percent; + /* H17 firmware that takes the face-detection scene metering setup */ + bool ae_fd_scene_metering; }; enum isp_sensor_id { @@ -244,13 +319,24 @@ enum isp_sensor_id { ISP_IMX814_2123_01, ISP_IMX853_7622_01, ISP_IMX913_7523_01, + ISP_IMX958_2224_01, + ISP_IMX958_2226_02, ISP_VD56G0_6221_01, ISP_VD56G0_6222_01, }; +struct isp_sensor_config { + struct coord input_dim; + struct coord output_dim; + u32 sensor_clk; + bool usable; + u8 reply[ISP_SENSOR_CONFIG_SIZE]; +}; + struct isp_format { enum isp_sensor_id id; u32 version; + u32 pixelformat; struct isp_preset *preset; unsigned int num_planes; u32 strides[VB2_MAX_PLANES]; @@ -264,8 +350,12 @@ struct apple_isp { enum isp_firmware_version fw_compat; u32 platform_id; u32 temporal_filter; + u32 cam_connections_scheme; struct isp_preset *presets; int num_presets; + /* Read-only sensor configuration replies, cached before video registration. */ + unsigned int num_sensor_configs; + struct isp_sensor_config *sensor_configs; int num_channels; struct isp_format fmts[ISP_MAX_CHANNELS]; @@ -276,10 +366,16 @@ struct apple_isp { struct v4l2_device v4l2_dev; struct v4l2_ctrl_handler ctrl_handler; struct v4l2_ctrl *exposure_priority; + struct v4l2_ctrl *power_line_frequency; + /* read-only exposure report of the last frame, NULL without one */ + struct v4l2_ctrl *gain; + struct v4l2_ctrl *exposure; + /* last reported total gain (1/256 steps) and exposure (us) */ + u32 frame_gain; + u32 frame_exposure_us; struct vb2_queue vbq; struct mutex video_lock; unsigned int sequence; - bool multiplanar; /* capture rate in frames per second, changes under video_lock */ unsigned int frame_rate; @@ -295,25 +391,43 @@ struct apple_isp { void __iomem *gpio; void __iomem *mbox2; void __iomem *wdt; + /* The camera light's GPIO register (hw->camera_light) */ + void __iomem *cil; + u32 cil_config; + u32 cil_saved; + bool cil_on_high; + bool cil_lit; + void __iomem *dapf; struct hrtimer wdt_timer; bool wdt_running; struct iommu_domain *domain; unsigned long shift; - struct drm_mm iovad; /* TODO iova.c can't allocate bottom-up */ - u64 iova_size; /* size of the iovad range */ + /* allocated IOVA ranges, in IOMMU pages, lowest free range first */ + struct maple_tree iovas; + u64 iova_size; /* size of the range @iovas allocates from */ u64 fw_iova_mask; /* see isp_fw_iova() */ - struct mutex iovad_lock; struct isp_firmware { + u64 heap_base; u64 heap_top; + u64 data_top; /* 0 unless the bootloader loads the data */ } fw; /* changes under video_lock once the video device is registered */ enum isp_fw_state fw_state; + /* the camera was detected; until then a deferred start is pending */ + bool camera_detected; + /* configurations the firmware has, once a deferred start detected them */ + u32 num_fw_presets; struct isp_surf *ipc_surf; struct isp_surf *extra_surf; struct isp_surf *data_surf; + struct isp_surf *main_tail_surf; + /* With hw->fw_restore: the firmware data segment and its copy */ + void *fw_data; + void *fw_data_copy; + size_t fw_data_size; struct isp_surf *log_surf; struct isp_surf *bt_surf; struct isp_surf *meta_surfs[ISP_MAX_BUFFERS]; @@ -347,16 +461,35 @@ struct apple_isp { spinlock_t buf_lock; struct list_head bufs_pending; struct list_head bufs_submitted; + struct list_head bufs_returned; + u64 buffer_tag; + unsigned long meta_returned; + /* + * The channel of a timed-out request that has not been answered yet, + * see isp_ipc_resync(). Sends are serialized by the callers, which + * share the command area. + */ + struct isp_channel *ipc_stale; + /* + * Not even a late answer came, so where the firmware is in the ring + * is unknown. Nothing is sent until the firmware is stopped, and + * resident firmware cannot be started again before the next boot. + */ + bool ipc_failed; }; struct isp_chan_ops { int (*handle)(struct apple_isp *isp, struct isp_channel *chan); + /* Called after the response slot and its doorbell are published. */ + void (*complete)(struct apple_isp *isp); }; struct isp_buffer { struct vb2_v4l2_buffer vb; struct list_head link; struct isp_surf surfs[VB2_MAX_PLANES]; + u64 tag; + enum vb2_buffer_state return_state; }; #define to_isp_buffer(x) container_of((x), struct isp_buffer, vb) @@ -367,6 +500,8 @@ enum { ISP_STATE_SLEEPING, }; +int apple_isp_program_dapf(struct apple_isp *isp); + #define isp_dbg(isp, fmt, ...) \ dev_dbg((isp)->dev, "[%s] " fmt, __func__, ##__VA_ARGS__) @@ -384,4 +519,37 @@ enum { ((isp)->hw->capture_meta_size ? ISP_CAPMETA_BUFFERS : 0) #define isp_get_current_format(isp) (isp_get_format(isp, isp->current_ch)) +static inline bool isp_supports_p010(struct apple_isp *isp) +{ + /* Its config discovery would change formats already advertised. */ + return isp->hw->gen == ISP_GEN_T6040 && !isp->hw->deferred_start && + isp_get_current_format(isp)->version == 0x958; +} + +static inline bool isp_has_p010(struct apple_isp *isp) +{ + if (!isp_supports_p010(isp)) + return false; + for (int i = 0; i < isp->num_presets; i++) { + if (isp->presets[i].p010) + return true; + } + return false; +} + +static inline bool isp_is_p010(struct apple_isp *isp) +{ + return isp_get_current_format(isp)->pixelformat == V4L2_PIX_FMT_P010; +} + +static inline unsigned int isp_num_rendered(struct apple_isp *isp) +{ + return isp_is_p010(isp) ? 2 : ISP_MAX_BUFFERS; +} + +static inline unsigned int isp_num_meta(struct apple_isp *isp) +{ + return isp_is_p010(isp) ? 8 : ISP_MAX_BUFFERS; +} + #endif /* __ISP_DRV_H__ */ diff --git a/drivers/media/platform/apple/isp/isp-fw.c b/drivers/media/platform/apple/isp/isp-fw.c index c96681173fd0fa..bab0d7d9d8b8ef 100644 --- a/drivers/media/platform/apple/isp/isp-fw.c +++ b/drivers/media/platform/apple/isp/isp-fw.c @@ -6,10 +6,12 @@ #include #include +#include #include #include #include #include +#include #include "isp-cam.h" #include "isp-cmd.h" @@ -52,6 +54,11 @@ static inline u32 isp_coproc_control(struct apple_isp *isp) return isp->hw->coproc_control ?: ISP_COPROC_CONTROL; } +static inline u32 isp_coproc_status(struct apple_isp *isp) +{ + return isp->hw->coproc_status ?: ISP_COPROC_STATUS; +} + /* Wait for the firmware to write @expected to a GPIO word. */ static int isp_gpio_wait(struct apple_isp *isp, u32 reg, u32 expected) { @@ -163,6 +170,7 @@ static_assert(sizeof(struct isp_firmware_bootargs) == 0x180); */ #define ISP_H16_DESCRIPTOR_SIZE 0x200 #define ISP_H16_SHARED_SIZE 0xee000000ULL +#define ISP_H16_DESC_CAM_SCHEME 0x60 #define ISP_H16_DESC_NO_OPTICAL_CARD_ID 0xb0 struct isp_firmware_bootargs_h16 { @@ -210,6 +218,7 @@ static const struct isp_chan_ops sm_ops = { static const struct isp_chan_ops bt_ops = { .handle = ipc_bt_handle, + .complete = ipc_bt_complete, }; static irqreturn_t apple_isp_isr(int irq, void *dev) @@ -315,6 +324,31 @@ static int isp_reset_coproc_t8140(struct apple_isp *isp) return 0; } +/* + * The T6040 firmware is started as the bootloader left it, without a reset: + * the coprocessor must never have run, and its reset vector must be the + * entry of the firmware text at the base of the heap region. + */ +static int isp_check_coproc_t6040(struct apple_isp *isp) +{ + u32 control = isp_coproc_read32(isp, isp_coproc_control(isp)); + u64 rvbar = readq(isp->coproc + ISP_COPROC_RVBAR); + + if (control) { + isp_err(isp, "coprocessor already started (control 0x%x)\n", + control); + return -EBUSY; + } + + if (rvbar != (isp->fw.heap_base | 1)) { + isp_err(isp, "reset vector 0x%llx is not the firmware at 0x%llx\n", + rvbar, isp->fw.heap_base); + return -ENODEV; + } + + return 0; +} + static int isp_reset_coproc(struct apple_isp *isp) { int retries; @@ -323,6 +357,8 @@ static int isp_reset_coproc(struct apple_isp *isp) if (isp->hw->gen == ISP_GEN_T8140) return isp_reset_coproc_t8140(isp); + if (isp->hw->gen == ISP_GEN_T6040) + return isp_check_coproc_t6040(isp); isp_coproc_write32(isp, ISP_COPROC_EDPRCR, 0x2); @@ -361,10 +397,47 @@ static int isp_reset_coproc(struct apple_isp *isp) return 0; } +/* + * With hw->fw_restore, put the firmware memory back as the boot loader left + * it: the data segment from its copy, and the main memory above it cleared. + */ +static void isp_restore_fw_memory(struct apple_isp *isp) +{ + struct isp_surf *tail = isp->main_tail_surf; + + if (!isp->fw_data_copy) + return; + + memcpy(isp->fw_data, isp->fw_data_copy, isp->fw_data_size); + if (tail) + for (u32 i = 0; i < tail->num_pages; i++) + clear_highpage(tail->pages[i]); +} + static void isp_firmware_shutdown_stage1(struct apple_isp *isp) { + /* Only a coprocessor that was started has to settle and quiesce */ + bool started = isp->hw->coproc_quiesce && + isp_coproc_read32(isp, isp_coproc_control(isp)); + u32 val; + + /* A coprocessor that powered down waits in WFI */ + if (started && + readl_poll_timeout(isp->coproc + isp_coproc_status(isp), val, + val & ISP_COPROC_IN_WFI, 100, 200 * USEC_PER_MSEC)) + dev_warn(isp->dev, "coproc not in WFI before power-down (status 0x%x)\n", + val); + isp_coproc_write32(isp, isp_coproc_control(isp), 0x0); + if (started) { + /* The request bit alone asks for it, and reads back once done */ + isp_coproc_write32(isp, isp->hw->coproc_quiesce, ISP_COPROC_QUIESCED); + if (readl_poll_timeout(isp->coproc + isp->hw->coproc_quiesce, val, + val & ISP_COPROC_QUIESCED, 10, 50 * USEC_PER_MSEC)) + dev_warn(isp->dev, "coproc did not quiesce (0x%x)\n", val); + } + apple_isp_power_down_domains(isp); } @@ -373,12 +446,20 @@ static int isp_firmware_boot_stage1(struct apple_isp *isp) int err; // u32 val; + isp_restore_fw_memory(isp); + err = apple_isp_power_up_domains(isp); if (err < 0) return err; - /* ISP17a has no clock enable word */ - if (isp->hw->gen != ISP_GEN_T8140) + if (isp->dapf) { + err = apple_isp_program_dapf(isp); + if (err) + goto shutdown; + } + + /* ISP17a and T6040 have no clock enable word */ + if (isp->hw->gen != ISP_GEN_T8140 && isp->hw->gen != ISP_GEN_T6040) isp_gpio_write32(isp, ISP_GPIO_CLOCK_EN, 0x1); #if 0 @@ -445,11 +526,27 @@ int apple_isp_alloc_firmware_surface(struct apple_isp *isp) dev_dbg(isp->dev, "Data surface iova: 0x%llx\n", (long long)isp->data_surf->iova); + /* Without it, the firmware faults on its first writes there. */ + if (isp->fw.data_top && isp->fw.data_top < isp->fw.heap_top) { + isp->main_tail_surf = + isp_alloc_surface_at(isp, isp->fw.data_top, + isp->fw.heap_top - isp->fw.data_top); + if (!isp->main_tail_surf) { + isp_err(isp, "failed to back main memory 0x%llx-0x%llx\n", + isp->fw.data_top, isp->fw.heap_top); + isp_free_surface(isp, isp->data_surf); + isp_free_surface(isp, isp->ipc_surf); + return -ENOMEM; + } + } + return 0; } void apple_isp_free_firmware_surface(struct apple_isp *isp) { + if (isp->main_tail_surf) + isp_free_surface(isp, isp->main_tail_surf); isp_free_surface(isp, isp->data_surf); isp_free_surface(isp, isp->ipc_surf); } @@ -491,12 +588,14 @@ static void isp_write_bootargs_h16(struct apple_isp *isp, void *virt, memset(&args, 0, sizeof(args)); args.ipc_iova = isp->ipc_surf->iova; args.shared_base = isp->fw.heap_top & 0xffffffff; - args.shared_size = ISP_H16_SHARED_SIZE; + args.shared_size = isp->hw->shared_size ?: ISP_H16_SHARED_SIZE; args.extra_iova = isp->extra_surf->iova; args.extra_size = isp->extra_surf->size; args.platform_id = isp->platform_id; args.ipc_queue_size = (u64)args_offset + 1; args.unk_68 = 0x40; + put_unaligned_le64(isp->cam_connections_scheme, + &args.descriptor[ISP_H16_DESC_CAM_SCHEME]); args.descriptor[ISP_H16_DESC_NO_OPTICAL_CARD_ID] = 1; memcpy(virt, &args, sizeof(args)); } @@ -789,26 +888,26 @@ static int isp_firmware_boot_stage3(struct apple_isp *isp) static int isp_stop_command_processor(struct apple_isp *isp) { -#if 0 - int res = isp_cmd_stop(isp, 0); - if (res) { - isp_err(isp, "isp_cmd_stop() failed\n"); - return res; - } + int res, ret; - /* Wait for ISP_GPIO_0 to 0xf7fbdff9 -> 0x8042006 */ isp_gpio_write32(isp, ISP_GPIO_0, 0xf7fbdff9); - isp_cmd_power_down(isp); -#else - isp_gpio_write32(isp, ISP_GPIO_0, 0xf7fbdff9); - - int res = isp_cmd_suspend(isp); + /* + * Firmware that starts again (hw->fw_restore) is stopped for good: + * STOP also powers the camera module down, which SUSPEND leaves on, + * even across a reboot. POWER_DOWN follows even if STOP failed. + */ + if (isp->hw->fw_restore) { + res = isp_cmd_stop(isp, 0); + ret = isp_cmd_power_down(isp); + res = res ?: ret; + } else { + res = isp_cmd_suspend(isp); + } if (res) { - isp_err(isp, "isp_cmd_suspend() failed\n"); + isp_err(isp, "failed to stop the firmware: %d\n", res); return res; } -#endif if (isp_gpio_wait(isp, ISP_GPIO_0, 0x8042006)) { isp_err(isp, "never received magic number from firmware\n"); @@ -825,12 +924,26 @@ static int isp_set_dsid_clr(struct apple_isp *isp) int err; /* - * The H17 firmware takes no PMU base, and its single broadcast-clear - * window in the multi-window form. + * The H17 firmware takes no PMU base, and its broadcast-clear windows + * in the multi-window form. */ - if (hw->fw_abi == ISP_FW_ABI_H17) - return isp_cmd_set_dsid_clr_multi_bc(isp, hw->dsid_clr_base0, + if (hw->fw_abi == ISP_FW_ABI_H17) { + const u64 used[] = { hw->dsid_clr_base0, hw->dsid_clr_base1, + hw->dsid_clr_base2, hw->dsid_clr_base3 }; + u64 bases[ISP_DSID_MULTI_BC_MAX]; + unsigned int slots = max_t(unsigned int, hw->dsid_count, + hw->dsid_slots); + + if (WARN_ON(hw->dsid_count > ARRAY_SIZE(used) || + slots > ARRAY_SIZE(bases))) + return -EINVAL; + + for (unsigned int i = 0; i < slots; i++) + bases[i] = i < hw->dsid_count ? used[i] : U64_MAX; + + return isp_cmd_set_dsid_clr_multi_bc(isp, bases, slots, hw->dsid_clr_range0); + } err = isp_cmd_set_isp_pmu_base(isp, hw->pmu_base); if (err) @@ -909,6 +1022,9 @@ static void isp_firmware_stop(struct apple_isp *isp) isp_firmware_shutdown_stage3(isp); isp_firmware_shutdown_stage2(isp); isp_collect_gc_surface(isp); + + /* Also leave it as loaded for a rebound driver or another kernel. */ + isp_restore_fw_memory(isp); } static int isp_firmware_boot(struct apple_isp *isp) @@ -920,6 +1036,8 @@ static int isp_firmware_boot(struct apple_isp *isp) /* Stage 1 stops the coprocessor and powers it down itself. */ isp_err(isp, "failed firmware boot stage 1: %d\n", err); isp_collect_gc_surface(isp); + /* The firmware may have run: leave its memory as loaded. */ + isp_restore_fw_memory(isp); return err; } @@ -977,7 +1095,8 @@ static void isp_firmware_shutdown(struct apple_isp *isp) * Resident firmware (hw->resident_fw) is loaded by the bootloader and * does not start again once it has been stopped: after CISP_CMD_SUSPEND, * a coprocessor reset and a power cycle of its domains it never completes - * the first handshake. It is booted once, at probe, and runs until the + * the first handshake. It is booted once, at probe or with + * deferred_start at the first stream, and runs until the * driver is unbound, probe fails or the system hibernates, also across * suspend; after it has stopped the device stays unusable until the next * system boot. @@ -998,6 +1117,10 @@ int apple_isp_firmware_boot(struct apple_isp *isp) return -EIO; } + /* The firmware starts with new rings. */ + isp->ipc_stale = NULL; + isp->ipc_failed = false; + /* Needs to be power cycled for IOMMU to behave correctly */ err = pm_runtime_resume_and_get(isp->dev); if (err < 0) { @@ -1019,7 +1142,7 @@ int apple_isp_firmware_boot(struct apple_isp *isp) return 0; } -/* The end of a stream or of the camera detection at probe */ +/* The end of a stream or of the camera detection */ void apple_isp_firmware_shutdown(struct apple_isp *isp) { if (!isp->hw->resident_fw) { @@ -1049,5 +1172,7 @@ void apple_isp_firmware_halt(struct apple_isp *isp) isp_firmware_shutdown(isp); pm_runtime_put_sync(isp->dev); + apple_isp_light_force_off(isp); + isp->ipc_stale = NULL; isp->fw_state = isp->hw->resident_fw ? ISP_FW_DEAD : ISP_FW_OFF; } diff --git a/drivers/media/platform/apple/isp/isp-iommu.c b/drivers/media/platform/apple/isp/isp-iommu.c index ade5a4a31f4993..12dbf6d47cccbb 100644 --- a/drivers/media/platform/apple/isp/isp-iommu.c +++ b/drivers/media/platform/apple/isp/isp-iommu.c @@ -56,41 +56,35 @@ static void isp_surf_vunmap(struct apple_isp *isp, struct isp_surf *surf) static void isp_surf_unreserve_iova(struct apple_isp *isp, struct isp_surf *surf) { - if (surf->mm) { - mutex_lock(&isp->iovad_lock); - drm_mm_remove_node(surf->mm); - mutex_unlock(&isp->iovad_lock); - kfree(surf->mm); - } - surf->mm = NULL; + if (surf->iova_reserved) + mtree_erase(&isp->iovas, surf->iova >> isp->shift); + surf->iova_reserved = false; } +/* + * The IOVA range starts at the top of the firmware heap. Hand out the lowest + * free range of whole IOMMU pages above it. + */ static int isp_surf_reserve_iova(struct apple_isp *isp, struct isp_surf *surf) { + unsigned long first = DIV_ROUND_UP_ULL(isp->fw.heap_top, 1ULL << isp->shift); + unsigned long last = ((isp->fw.heap_top + isp->iova_size) >> isp->shift) - 1; + unsigned long pages = DIV_ROUND_UP_ULL(surf->size, 1ULL << isp->shift); + unsigned long index; int err; - surf->mm = kzalloc(sizeof(*surf->mm), GFP_KERNEL); - if (!surf->mm) - return -ENOMEM; - - mutex_lock(&isp->iovad_lock); - err = drm_mm_insert_node_generic(&isp->iovad, surf->mm, - ALIGN(surf->size, 1UL << isp->shift), - 1UL << isp->shift, 0, 0); - mutex_unlock(&isp->iovad_lock); + err = mtree_alloc_range(&isp->iovas, &index, surf, pages, first, last, + GFP_KERNEL); if (err < 0) { dev_err(isp->dev, "failed to reserve 0x%llx of iova space\n", surf->size); - goto mm_free; + return err; } - surf->iova = surf->mm->start; + surf->iova = (dma_addr_t)index << isp->shift; + surf->iova_reserved = true; return 0; -mm_free: - kfree(surf->mm); - surf->mm = NULL; - return err; } static void isp_surf_iommu_unmap(struct apple_isp *isp, struct isp_surf *surf) @@ -129,7 +123,7 @@ static int isp_surf_iommu_map(struct apple_isp *isp, struct isp_surf *surf) static void __isp_surf_init(struct apple_isp *isp, struct isp_surf *surf, u64 size, bool gc) { - surf->mm = NULL; + surf->iova_reserved = false; surf->virt = NULL; surf->size = ALIGN(size, 1UL << isp->shift); surf->num_pages = surf->size >> isp->shift; @@ -218,6 +212,35 @@ struct isp_surf *isp_alloc_surface_vmap(struct apple_isp *isp, u64 size) return surf; } +/* A surface at a fixed IOVA, outside the range the others come from. */ +struct isp_surf *isp_alloc_surface_at(struct apple_isp *isp, dma_addr_t iova, + u64 size) +{ + struct isp_surf *surf; + + surf = kzalloc_obj(*surf); + if (!surf) + return NULL; + + __isp_surf_init(isp, surf, size, false); + surf->iova = iova; + + if (isp_surf_alloc_pages(surf) < 0) + goto free_surf; + + if (isp_surf_iommu_map(isp, surf) < 0) + goto free_pages; + + refcount_set(&surf->refcount, 1); + return surf; + +free_pages: + isp_surf_free_pages(surf); +free_surf: + kfree(surf); + return NULL; +} + void isp_free_surface(struct apple_isp *isp, struct isp_surf *surf) { if (refcount_dec_and_test(&surf->refcount)) { @@ -262,7 +285,7 @@ int apple_isp_iommu_map_sgt(struct apple_isp *isp, struct isp_surf *surf, ssize_t mapped; // TODO userptr sends unaligned sizes - surf->mm = NULL; + surf->iova_reserved = false; surf->size = size; err = isp_surf_reserve_iova(isp, surf); diff --git a/drivers/media/platform/apple/isp/isp-iommu.h b/drivers/media/platform/apple/isp/isp-iommu.h index a7fce2713f5841..3a999a8c5b3d5b 100644 --- a/drivers/media/platform/apple/isp/isp-iommu.h +++ b/drivers/media/platform/apple/isp/isp-iommu.h @@ -10,6 +10,8 @@ struct isp_surf *__isp_alloc_surface(struct apple_isp *isp, u64 size, bool gc); #define isp_alloc_surface(isp, size) (__isp_alloc_surface(isp, size, false)) #define isp_alloc_surface_gc(isp, size) (__isp_alloc_surface(isp, size, true)) struct isp_surf *isp_alloc_surface_vmap(struct apple_isp *isp, u64 size); +struct isp_surf *isp_alloc_surface_at(struct apple_isp *isp, dma_addr_t iova, + u64 size); int isp_surf_vmap(struct apple_isp *isp, struct isp_surf *surf); void isp_free_surface(struct apple_isp *isp, struct isp_surf *surf); void isp_free_released_surfaces(struct apple_isp *isp); diff --git a/drivers/media/platform/apple/isp/isp-ipc-test.c b/drivers/media/platform/apple/isp/isp-ipc-test.c index 6521cecb4cfb6c..d7ca456055cec0 100644 --- a/drivers/media/platform/apple/isp/isp-ipc-test.c +++ b/drivers/media/platform/apple/isp/isp-ipc-test.c @@ -144,7 +144,139 @@ static void isp_test_sm_free_log_bt(struct kunit *test) KUNIT_EXPECT_NULL(test, t->isp->bt_surf); } +static void isp_test_command_ring_wrap(struct kunit *test) +{ + struct isp_sm_test *t = isp_sm_test_alloc(test); + struct isp_channel *chan = t->chan; + struct isp_message *slots; + + chan->num = 8; + chan->virt = kunit_kcalloc(test, chan->num, sizeof(*slots), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, chan->virt); + slots = chan->virt; + chan->req.arg0 = 0x5000000; + isp_get_current_format(t->isp)->pixelformat = V4L2_PIX_FMT_P010; + for (unsigned int i = 0; i < 100000; i++) { + unsigned int cursor = chan->cursor; + + /* Re-publication must clear the old ACK before waiting on a wrap. */ + slots[cursor].arg0 = chan->req.arg0; + KUNIT_ASSERT_FALSE(test, chan_tx_done(t->isp, chan)); + KUNIT_ASSERT_EQ(test, chan->cursor, cursor); + slots[cursor].arg0 |= ISP_IPC_FLAG_ACK; + KUNIT_ASSERT_TRUE(test, chan_tx_done(t->isp, chan)); + KUNIT_ASSERT_EQ(test, chan->cursor, (cursor + 1) % chan->num); + } + KUNIT_EXPECT_EQ(test, chan->cursor, 0); +} + +static void isp_test_late_ack_keeps_cursor(struct kunit *test) +{ + struct isp_sm_test *t = isp_sm_test_alloc(test); + struct isp_message response = { .arg0 = 0x5000001 }; + + isp_get_current_format(t->isp)->pixelformat = V4L2_PIX_FMT_P010; + t->chan->virt = &response; + t->chan->num = 8; + t->chan->req.arg0 = 0x5000000; + t->chan->deadline_active = true; + t->chan->deadline = jiffies; + KUNIT_EXPECT_FALSE(test, chan_tx_done(t->isp, t->chan)); + KUNIT_EXPECT_EQ(test, t->chan->cursor, 0); + t->chan->deadline = jiffies + HZ; + KUNIT_EXPECT_TRUE(test, chan_tx_done(t->isp, t->chan)); + KUNIT_EXPECT_EQ(test, t->chan->cursor, 1); +} + +/* A P010 command ring whose slots and doorbell are plain memory */ +static struct isp_message *isp_test_command_ring(struct kunit *test, + struct isp_sm_test *t) +{ + struct isp_channel *chan = t->chan; + struct isp_message *slots; + + t->isp->mbox2 = (__force void __iomem *) + kunit_kzalloc(test, ISP_MBOX2_SIZE, GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, (__force void *)t->isp->mbox2); + init_waitqueue_head(&t->isp->wait); + isp_get_current_format(t->isp)->pixelformat = V4L2_PIX_FMT_P010; + + chan->name = "IO"; + chan->num = 8; + chan->doorbell = 1; + chan->virt = kunit_kcalloc(test, chan->num, sizeof(*slots), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, chan->virt); + chan->req.arg0 = 0x5000000; + + return chan->virt; +} + +static void isp_test_timeout_late_answer(struct kunit *test) +{ + struct isp_sm_test *t = isp_sm_test_alloc(test); + struct isp_message *slots = isp_test_command_ring(test, t); + struct isp_channel *chan = t->chan; + + KUNIT_EXPECT_EQ(test, ipc_chan_send(t->isp, chan, 1), -ETIME); + KUNIT_EXPECT_PTR_EQ(test, t->isp->ipc_stale, chan); + KUNIT_EXPECT_FALSE(test, t->isp->ipc_failed); + KUNIT_EXPECT_EQ(test, chan->cursor, 0); + + /* The answer comes after the deadline and is consumed by the resync. */ + slots[0].arg0 |= ISP_IPC_FLAG_ACK; + KUNIT_EXPECT_EQ(test, isp_ipc_resync(t->isp), 0); + KUNIT_EXPECT_NULL(test, t->isp->ipc_stale); + KUNIT_EXPECT_EQ(test, chan->cursor, 1); + + /* The next request takes the next slot; the old ACK does not answer it. */ + KUNIT_EXPECT_EQ(test, ipc_chan_send(t->isp, chan, 1), -ETIME); + KUNIT_EXPECT_EQ(test, slots[1].arg0, chan->req.arg0); + KUNIT_EXPECT_EQ(test, chan->cursor, 1); + slots[1].arg0 |= ISP_IPC_FLAG_ACK; + KUNIT_EXPECT_EQ(test, isp_ipc_resync(t->isp), 0); + KUNIT_EXPECT_EQ(test, chan->cursor, 2); + KUNIT_EXPECT_FALSE(test, t->isp->ipc_failed); +} + +static void isp_test_timeout_no_answer(struct kunit *test) +{ + struct isp_sm_test *t = isp_sm_test_alloc(test); + struct isp_message *slots = isp_test_command_ring(test, t); + struct isp_channel *chan = t->chan; + + KUNIT_EXPECT_EQ(test, ipc_chan_send(t->isp, chan, 1), -ETIME); + KUNIT_EXPECT_EQ(test, isp_ipc_resync(t->isp), -EIO); + KUNIT_EXPECT_TRUE(test, t->isp->ipc_failed); + KUNIT_EXPECT_NULL(test, t->isp->ipc_stale); + + /* An answer after the resync gave up admits nothing. */ + slots[0].arg0 |= ISP_IPC_FLAG_ACK; + KUNIT_EXPECT_EQ(test, ipc_chan_send(t->isp, chan, 1), -EIO); + KUNIT_EXPECT_EQ(test, isp_ipc_resync(t->isp), -EIO); + KUNIT_EXPECT_EQ(test, chan->cursor, 0); +} + +static void isp_test_message_payload_copy(struct kunit *test) +{ + struct isp_sm_test *t = isp_sm_test_alloc(test); + struct isp_message response = { + .arg0 = 0x5000001, .arg1 = 1, .arg2 = 2, .arg3 = 3, + .arg4 = 4, .arg5 = 5, .arg6 = 6, .arg7 = 7, + }; + struct isp_message copied = {}; + + isp_get_current_format(t->isp)->pixelformat = V4L2_PIX_FMT_P010; + t->chan->virt = &response; + chan_read_msg_index(t->isp, t->chan, &copied, 0); + KUNIT_EXPECT_MEMEQ(test, &copied, &response, sizeof(response)); +} + static struct kunit_case isp_ipc_test_cases[] = { + KUNIT_CASE(isp_test_message_payload_copy), + KUNIT_CASE(isp_test_late_ack_keeps_cursor), + KUNIT_CASE(isp_test_timeout_late_answer), + KUNIT_CASE(isp_test_timeout_no_answer), + KUNIT_CASE(isp_test_command_ring_wrap), KUNIT_CASE(isp_test_sm_free_releases), KUNIT_CASE(isp_test_sm_free_alias), KUNIT_CASE(isp_test_sm_free_unknown), diff --git a/drivers/media/platform/apple/isp/isp-ipc.c b/drivers/media/platform/apple/isp/isp-ipc.c index f709f6e3057639..7b4dddf892a044 100644 --- a/drivers/media/platform/apple/isp/isp-ipc.c +++ b/drivers/media/platform/apple/isp/isp-ipc.c @@ -6,10 +6,16 @@ #include "isp-regs.h" #include "isp-fw.h" +#if IS_ENABLED(CONFIG_VIDEO_APPLE_ISP_KUNIT_TEST) +#include +#endif + #define ISP_IPC_FLAG_TERMINAL_ACK 0x3 /* longer firmware log lines are cut */ #define ISP_IPC_TERMINAL_MAX_LEN 512 #define ISP_IPC_BUFEXC_STAT_META_OFFSET 0x10 +/* how much longer a timed-out request may take to be answered */ +#define ISP_IPC_RESYNC_TIMEOUT msecs_to_jiffies(1000) struct isp_sm_deferred_work { struct work_struct work; @@ -66,7 +72,17 @@ static inline void chan_read_msg_index(struct apple_isp *isp, struct isp_channel *chan, struct isp_message *msg, u32 index) { - memcpy(msg, chan_msg_virt(chan, index), sizeof(*msg)); + if (isp_is_p010(isp)) { + u64 *slot = chan_msg_virt(chan, index); + u64 arg0 = READ_ONCE(*slot); + + /* Acquire validity before consuming the firmware-owned payload. */ + dma_rmb(); + memcpy(msg, slot, sizeof(*msg)); + msg->arg0 = arg0; + } else { + memcpy(msg, chan_msg_virt(chan, index), sizeof(*msg)); + } } static inline void chan_read_msg(struct apple_isp *isp, @@ -124,6 +140,8 @@ static int chan_handle_once(struct apple_isp *isp, struct isp_channel *chan) isp_mbox2_write32(isp, ISP_MBOX2_IRQ_DOORBELL, chan->doorbell); chan_update_cursor(chan); + if (chan->ops->complete) + chan->ops->complete(isp); return 0; } @@ -139,10 +157,12 @@ static inline bool chan_rx_done(struct apple_isp *isp, struct isp_channel *chan) int ipc_chan_handle(struct apple_isp *isp, struct isp_channel *chan) { + unsigned int budget = isp_is_p010(isp) ? chan->num : UINT_MAX; int err = 0; mutex_lock(&chan->lock); - while (1) { + /* A busy producer must not starve the other completion/control rings. */ + while (budget--) { chan_read_msg(isp, chan, &chan->req); if (chan_rx_done(isp, chan)) { err = 0; @@ -160,6 +180,9 @@ int ipc_chan_handle(struct apple_isp *isp, struct isp_channel *chan) static inline bool chan_tx_done(struct apple_isp *isp, struct isp_channel *chan) { + if (isp_is_p010(isp) && chan->deadline_active && + time_after_eq(jiffies, chan->deadline)) + return false; dma_rmb(); chan_read_msg(isp, chan, &chan->rsp); @@ -171,11 +194,66 @@ static inline bool chan_tx_done(struct apple_isp *isp, struct isp_channel *chan) return false; } +/* + * A request that timed out still owns its slot, and the firmware may answer + * it late. That answer must not be taken for the answer to the next request, + * which goes in the same slot with the same arg0, and the next request must + * not overwrite the command area while the firmware may still read the old + * one. So before anything else is written, wait once more for the late + * answer, for a bounded time, and consume it; the ring is then in step again. + * If it has not come yet, the doorbell is rung again in case the first one + * was missed. IO and DEBUG share a doorbell bit, so the firmware already + * copes with a doorbell that brings no new request. If the firmware still + * does not answer, where it is in the ring is unknown and nothing more is + * sent until it is stopped. + */ +int isp_ipc_resync(struct apple_isp *isp) +{ + struct isp_channel *chan = isp->ipc_stale; + + if (isp->ipc_failed) + return -EIO; + if (!chan) + return 0; + + isp->ipc_stale = NULL; + chan->deadline_active = false; + if (!chan_tx_done(isp, chan)) { + isp_mbox2_write32(isp, ISP_MBOX2_IRQ_DOORBELL, chan->doorbell); + if (!wait_event_timeout(isp->wait, chan_tx_done(isp, chan), + ISP_IPC_RESYNC_TIMEOUT)) { + isp->ipc_failed = true; + dev_err(isp->dev, + "%s: no answer to the timed-out request, sending no more commands\n", + chan->name); + return -EIO; + } + } + + dev_warn(isp->dev, + "%s: timed-out request answered late, channel back in step\n", + chan->name); + + return 0; +} + int ipc_chan_send(struct apple_isp *isp, struct isp_channel *chan, unsigned long timeout) { long t; + int err; +#if IS_ENABLED(CONFIG_VIDEO_APPLE_ISP_KUNIT_TEST) + KUNIT_STATIC_STUB_REDIRECT(ipc_chan_send, isp, chan, timeout); +#endif + /* Callers that fill the command area resync before doing so. */ + err = isp_ipc_resync(isp); + if (err) + return err; + if (isp_is_p010(isp) && timeout) { + chan->deadline = jiffies + timeout; + chan->deadline_active = true; + } chan_write_msg(isp, chan, &chan->req); dma_wmb(); @@ -186,6 +264,9 @@ int ipc_chan_send(struct apple_isp *isp, struct isp_channel *chan, t = wait_event_timeout(isp->wait, chan_tx_done(isp, chan), timeout); if (t == 0) { + /* Resolved before the next request, see isp_ipc_resync(). */ + if (isp_is_p010(isp)) + isp->ipc_stale = chan; dev_err(isp->dev, "%s: timed out on request [0x%llx, 0x%llx, 0x%llx]\n", chan->name, chan->req.arg0, chan->req.arg1, @@ -193,6 +274,7 @@ int ipc_chan_send(struct apple_isp *isp, struct isp_channel *chan, return -ETIME; } + chan->deadline_active = false; isp_dbg(isp, "%s: request success (%ld)\n", chan->name, t); return 0; diff --git a/drivers/media/platform/apple/isp/isp-ipc.h b/drivers/media/platform/apple/isp/isp-ipc.h index 7bc95a20054657..0c93100020baa7 100644 --- a/drivers/media/platform/apple/isp/isp-ipc.h +++ b/drivers/media/platform/apple/isp/isp-ipc.h @@ -21,6 +21,7 @@ int ipc_chan_handle(struct apple_isp *isp, struct isp_channel *chan); int ipc_chan_send(struct apple_isp *isp, struct isp_channel *chan, unsigned long timeout); +int isp_ipc_resync(struct apple_isp *isp); int ipc_tm_handle(struct apple_isp *isp, struct isp_channel *chan); int ipc_sm_handle(struct apple_isp *isp, struct isp_channel *chan); diff --git a/drivers/media/platform/apple/isp/isp-regs.h b/drivers/media/platform/apple/isp/isp-regs.h index f2f6f1c9489f46..b7f9b2fb87faa9 100644 --- a/drivers/media/platform/apple/isp/isp-regs.h +++ b/drivers/media/platform/apple/isp/isp-regs.h @@ -24,6 +24,10 @@ #define ISP_COPROC_IRQ_MASK_5 0x1400a14 #define ISP_COPROC_CONTROL_T8140 0x1600044 +#define ISP_COPROC_STATUS_T8140 0x1600048 +#define ISP_COPROC_QUIESCE_T8140 0x1600040 +/* Requests the quiesce when set, and reads back once it has happened */ +#define ISP_COPROC_QUIESCED BIT(25) /* * ISP17a (T8140) reset. The fourth fabric word is at 0xa50, off the 0x100 @@ -40,6 +44,20 @@ #define ISP_COPROC_RESET_ACK_0_T8140 0x1600818 #define ISP_COPROC_RESET_ACK_1_T8140 0x160081c +/* + * Address filter (DAPF) registers of a T8110-type DART: an array of windows, + * each with its inclusive start and end and three control words. Every ISP + * window takes the control values its ADT dapf-instance entry gives. + */ +#define DAPF_WINDOW_STRIDE 0x40 +#define DAPF_CTRL0 0x00 +#define DAPF_CTRL0_ISP 0x31 +#define DAPF_CTRL1 0x04 +#define DAPF_START 0x08 +#define DAPF_END 0x10 +#define DAPF_CTRL2 0x20 +#define DAPF_CTRL2_ISP 0x1 + #define ISP_MBOX_IRQ_INTERRUPT 0x00 #define ISP_MBOX_IRQ_ENABLE 0x04 #define ISP_MBOX_IRQ_ENABLE_T6031 0x08 diff --git a/drivers/media/platform/apple/isp/isp-v4l2-test.c b/drivers/media/platform/apple/isp/isp-v4l2-test.c index 895a6d1299c220..88f428b3b0c276 100644 --- a/drivers/media/platform/apple/isp/isp-v4l2-test.c +++ b/drivers/media/platform/apple/isp/isp-v4l2-test.c @@ -7,6 +7,7 @@ #include #include +#include #include #define ISP_TEST_FRAME_SIZE 0x1000 @@ -19,6 +20,8 @@ static struct apple_isp *isp_test_alloc(struct kunit *test) KUNIT_ASSERT_NOT_ERR_OR_NULL(test, isp); mutex_init(&isp->video_lock); + spin_lock_init(&isp->buf_lock); + INIT_LIST_HEAD(&isp->bufs_returned); isp_get_current_format(isp)->total_size = ISP_TEST_FRAME_SIZE; return isp; @@ -34,6 +37,8 @@ static void isp_test_queue_init(struct kunit *test) KUNIT_ASSERT_EQ(test, isp_vb2_queue_init(isp), 0); KUNIT_EXPECT_GE(test, isp->vbq.max_num_buffers, VB2_MAX_FRAME); + KUNIT_EXPECT_EQ(test, isp->vbq.type, V4L2_BUF_TYPE_VIDEO_CAPTURE); + KUNIT_EXPECT_FALSE(test, isp->vbq.is_multiplanar); vb2_queue_release(&isp->vbq); } @@ -99,6 +104,12 @@ static void isp_test_create_bufs_limit(struct kunit *test) KUNIT_EXPECT_EQ(test, isp_test_setup(test, ISP_MAX_BUFFERS, &nbuffers, &num_planes, sizes), -ENOBUFS); + /* The contiguous API must refuse a second independent memory plane. */ + nbuffers = 1; + num_planes = 2; + KUNIT_EXPECT_EQ(test, isp_test_setup(test, 0, &nbuffers, &num_planes, + sizes), -EINVAL); + /* A plane smaller than a frame is still refused. */ nbuffers = 1; num_planes = 1; @@ -107,7 +118,289 @@ static void isp_test_create_bufs_limit(struct kunit *test) sizes), -EINVAL); } +static const struct apple_isp_hw isp_test_t6040 = { + .gen = ISP_GEN_T6040, + .fw_abi = ISP_FW_ABI_H17, +}; + +static void isp_test_p010_format(struct kunit *test) +{ + struct apple_isp *isp = isp_test_alloc(test); + struct isp_format *fmt = isp_get_current_format(isp); + struct isp_preset preset = { .output_dim = { 1920, 1080 }, .p010 = true }; + struct v4l2_format f = {}; + unsigned int sizes[VB2_MAX_PLANES] = {}; + unsigned int nbuffers = 16, num_planes = 0; + + isp->hw = &isp_test_t6040; + fmt->version = 0x958; + KUNIT_ASSERT_EQ(test, isp_set_preset(isp, fmt, &preset, V4L2_PIX_FMT_P010), 0); + isp_get_sp_pix_format(isp, &f, fmt); + KUNIT_EXPECT_EQ(test, f.fmt.pix.pixelformat, V4L2_PIX_FMT_P010); + KUNIT_EXPECT_EQ(test, f.fmt.pix.bytesperline, 3840); + KUNIT_EXPECT_EQ(test, f.fmt.pix.sizeimage, 6220800); + KUNIT_EXPECT_EQ(test, fmt->plane_size[0], (size_t)4147200); + KUNIT_EXPECT_EQ(test, fmt->plane_size[1], (size_t)2073600); + KUNIT_EXPECT_EQ(test, f.fmt.pix.quantization, V4L2_QUANTIZATION_LIM_RANGE); + + isp->vbq.drv_priv = isp; + isp_test_set_num_buffers(test, &isp->vbq, 0); + KUNIT_ASSERT_EQ(test, + isp_vb2_queue_setup(&isp->vbq, &nbuffers, &num_planes, sizes, NULL), 0); + KUNIT_EXPECT_EQ(test, nbuffers, 2); + KUNIT_EXPECT_EQ(test, num_planes, 1); + KUNIT_EXPECT_EQ(test, sizes[0], 6220800); + KUNIT_EXPECT_EQ(test, isp_num_meta(isp), 8); + + preset.output_dim = (struct coord){1280, 720}; + KUNIT_ASSERT_EQ(test, isp_set_preset(isp, fmt, &preset, V4L2_PIX_FMT_P010), 0); + KUNIT_EXPECT_EQ(test, fmt->strides[0], 2560); + KUNIT_EXPECT_EQ(test, fmt->total_size, (size_t)2764800); + /* NV12 remains the default and restores the existing pool capacity. */ + KUNIT_ASSERT_EQ(test, isp_set_preset(isp, fmt, &preset, V4L2_PIX_FMT_NV12), 0); + KUNIT_EXPECT_EQ(test, fmt->pixelformat, V4L2_PIX_FMT_NV12); + KUNIT_EXPECT_EQ(test, fmt->total_size, (size_t)1382400); + KUNIT_EXPECT_EQ(test, isp_num_rendered(isp), ISP_MAX_BUFFERS); + KUNIT_EXPECT_EQ(test, isp_num_meta(isp), ISP_MAX_BUFFERS); + +} + +static void isp_test_p010_admission(struct kunit *test) +{ + static const struct apple_isp_hw neo = { .gen = ISP_GEN_T8140 }; + struct apple_isp *isp = isp_test_alloc(test); + struct isp_format *fmt = isp_get_current_format(isp); + struct isp_preset preset = { .output_dim = {1280, 720}, .p010 = true }; + struct v4l2_fmtdesc desc = { .index = 0 }; + + isp->presets = &preset; + isp->num_presets = 1; + isp->hw = &isp_test_t6040; + fmt->version = 0x958; + KUNIT_ASSERT_EQ(test, isp_enum_pixelformat(isp, &desc), 0); + KUNIT_EXPECT_EQ(test, desc.pixelformat, V4L2_PIX_FMT_NV12); + desc.index = 1; + KUNIT_ASSERT_EQ(test, isp_enum_pixelformat(isp, &desc), 0); + KUNIT_EXPECT_EQ(test, desc.pixelformat, V4L2_PIX_FMT_P010); + desc.index = 2; + KUNIT_EXPECT_EQ(test, isp_enum_pixelformat(isp, &desc), -EINVAL); + desc.index = 1; + isp->hw = &neo; + KUNIT_EXPECT_EQ(test, isp_enum_pixelformat(isp, &desc), -EINVAL); + KUNIT_ASSERT_EQ(test, isp_set_preset(isp, fmt, &preset, V4L2_PIX_FMT_P010), 0); + KUNIT_EXPECT_EQ(test, fmt->pixelformat, V4L2_PIX_FMT_NV12); + KUNIT_EXPECT_EQ(test, fmt->strides[0], 1280); +} + +static void isp_test_p010_completion_identity(struct kunit *test) +{ + struct isp_format fmt = { .plane_size = {4147200, 2073600} }; + struct isp_buffer buf = { .surfs = {{ .iova = 0x10020000000ULL }}, .tag = 42 }; + struct isp_buflist_buffer desc = { + .iovas = {0x20000000, 0x203f4800}, + .num_planes = 2, .pool_type = CISP_POOL_TYPE_RENDERED_SCL1, .tag = 42, + }; + + KUNIT_EXPECT_TRUE(test, isp_p010_buffer_matches(&fmt, &buf, &desc)); + desc.tag--; + KUNIT_EXPECT_FALSE(test, isp_p010_buffer_matches(&fmt, &buf, &desc)); + desc.tag++; + desc.iovas[1]++; + KUNIT_EXPECT_FALSE(test, isp_p010_buffer_matches(&fmt, &buf, &desc)); + desc.iovas[1]--; + desc.iovas[0] |= BIT_ULL(40); + /* Reject mixed encodings, accept both exact full submitted addresses. */ + KUNIT_EXPECT_FALSE(test, isp_p010_buffer_matches(&fmt, &buf, &desc)); + desc.iovas[1] |= BIT_ULL(40); + KUNIT_EXPECT_TRUE(test, isp_p010_buffer_matches(&fmt, &buf, &desc)); + desc.iovas[0] |= BIT_ULL(41); + desc.iovas[1] |= BIT_ULL(41); + KUNIT_EXPECT_FALSE(test, isp_p010_buffer_matches(&fmt, &buf, &desc)); + desc.iovas[0] = (u32)desc.iovas[0]; + desc.iovas[1] = (u32)desc.iovas[1]; + desc.pool_type = CISP_POOL_TYPE_RENDERED; + KUNIT_EXPECT_FALSE(test, isp_p010_buffer_matches(&fmt, &buf, &desc)); + desc.pool_type = CISP_POOL_TYPE_RENDERED_SCL1; + desc.num_planes = 1; + KUNIT_EXPECT_FALSE(test, isp_p010_buffer_matches(&fmt, &buf, &desc)); +} + +static void isp_test_p010_report_defers_completion(struct kunit *test) +{ + struct apple_isp *isp = isp_test_alloc(test); + struct isp_format *fmt = isp_get_current_format(isp); + struct isp_buffer *buf = kunit_kzalloc(test, sizeof(*buf), GFP_KERNEL); + struct { + u64 type, count; + struct isp_buflist_buffer desc; + } report = { + .type = 2, .count = 1, + .desc = { .iovas = {0x20000000, 0x203f4800}, + .num_planes = 2, .pool_type = 9, .tag = 42 }, + }; + struct isp_surf report_surf = { + .iova = 0x30000000, .size = sizeof(report), .virt = &report, + }; + struct isp_channel chan = { + .req = { .arg0 = report_surf.iova, .arg1 = sizeof(report), + .arg2 = ISP_IPC_BUFEXC_FLAG_RENDER }, + }; + + KUNIT_ASSERT_NOT_NULL(test, buf); + fmt->pixelformat = V4L2_PIX_FMT_P010; + fmt->plane_size[0] = 4147200; + isp->fw_iova_mask = U64_MAX; + isp->bt_surf = &report_surf; + buf->surfs[0].iova = 0x10020000000ULL; + buf->tag = 42; + INIT_LIST_HEAD(&isp->bufs_submitted); + list_add(&buf->link, &isp->bufs_submitted); + /* There is no vb2 queue: completing it before the ACK would fault. */ + KUNIT_ASSERT_EQ(test, ipc_bt_handle(isp, &chan), 0); + KUNIT_EXPECT_TRUE(test, list_empty(&isp->bufs_submitted)); + KUNIT_EXPECT_PTR_EQ(test, + list_first_entry(&isp->bufs_returned, struct isp_buffer, link), buf); + KUNIT_EXPECT_EQ(test, buf->return_state, VB2_BUF_STATE_DONE); + KUNIT_EXPECT_EQ(test, chan.rsp.arg0, report_surf.iova | ISP_IPC_FLAG_ACK); +} + +static void isp_test_p010_mode_selection(struct kunit *test) +{ + struct apple_isp *isp = isp_test_alloc(test); + struct isp_preset presets[] = { + { .index = 5, .output_dim = {1920, 1080} }, + { .index = 5, .output_dim = {1280, 720}, .p010 = true }, + { .index = 1, .output_dim = {4096, 3072} }, + }; + + isp->hw = &isp_test_t6040; + isp_get_current_format(isp)->version = 0x958; + isp->presets = presets; + isp->num_presets = ARRAY_SIZE(presets); + KUNIT_EXPECT_PTR_EQ(test, isp_select_preset(isp, 0, 0, V4L2_PIX_FMT_P010), &presets[1]); + KUNIT_EXPECT_PTR_EQ(test, isp_select_preset(isp, 1920, 1080, V4L2_PIX_FMT_P010), + &presets[1]); + KUNIT_EXPECT_PTR_EQ(test, isp_select_preset(isp, 4096, 3072, V4L2_PIX_FMT_P010), + &presets[1]); + KUNIT_EXPECT_PTR_EQ(test, isp_select_preset(isp, 1920, 1080, V4L2_PIX_FMT_NV12), + &presets[0]); + /* Only a matching firmware output enables the larger P010 size. */ + presets[2].p010 = true; + KUNIT_EXPECT_PTR_EQ(test, isp_select_preset(isp, 4096, 3072, V4L2_PIX_FMT_P010), + &presets[2]); +} + +static int isp_test_buffer_ack(struct apple_isp *isp, struct isp_channel *chan, + unsigned long timeout) +{ + unsigned int *calls = kunit_get_current_test()->priv; + + (*calls)++; + return 0; +} + +static void isp_test_imx958_last_lease_requeue(struct kunit *test) +{ + struct apple_isp *isp = isp_test_alloc(test); + struct isp_format *fmt = isp_get_current_format(isp); + struct isp_buffer *buf = kunit_kzalloc(test, sizeof(*buf), GFP_KERNEL); + struct isp_buffer *submitted; + unsigned int calls = 0; + + KUNIT_ASSERT_NOT_NULL(test, buf); + isp->hw = &isp_test_t6040; + fmt->version = 0x958; + fmt->pixelformat = V4L2_PIX_FMT_P010; + fmt->num_planes = 2; + fmt->plane_size[0] = 1843200; + fmt->plane_size[1] = 921600; + INIT_LIST_HEAD(&isp->bufs_pending); + INIT_LIST_HEAD(&isp->bufs_submitted); + isp->cmd_virt = kunit_kzalloc(test, ISP_CMD_AREA_SIZE(0), GFP_KERNEL); + isp->chan_bh = kunit_kzalloc(test, sizeof(*isp->chan_bh), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, isp->cmd_virt); + KUNIT_ASSERT_NOT_NULL(test, isp->chan_bh); + for (unsigned int i = 0; i < ISP_MAX_BUFFERS; i++) { + isp->meta_surfs[i] = kunit_kzalloc(test, sizeof(struct isp_surf), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, isp->meta_surfs[i]); + isp->meta_surfs[i]->submitted = true; + } + isp->vbq.drv_priv = isp; + buf->vb.vb2_buf.vb2_queue = &isp->vbq; + buf->surfs[0].iova = 0x20000000; + set_bit(ISP_STATE_STREAMING, &isp->state); + test->priv = &calls; + kunit_activate_static_stub(test, ipc_chan_send, isp_test_buffer_ack); + for (unsigned int format = 0; format < 2; format++) { + fmt->pixelformat = format ? V4L2_PIX_FMT_NV12 : V4L2_PIX_FMT_P010; + calls = 0; + for (unsigned int i = 1; i <= 10000; i++) { + /* Both lists empty, as after the last completion was dequeued. */ + isp_vb2_buf_queue(&buf->vb.vb2_buf); + KUNIT_ASSERT_EQ(test, calls, i); + if (!format) + KUNIT_ASSERT_EQ(test, buf->tag, (u64)i); + KUNIT_ASSERT_TRUE(test, list_empty(&isp->bufs_pending)); + submitted = list_first_entry(&isp->bufs_submitted, struct isp_buffer, link); + KUNIT_ASSERT_PTR_EQ(test, submitted, buf); + list_del(&buf->link); + } + } +} + +/* The exposure report is found through the section table, never past it. */ +static void isp_test_meta_exposure(struct kunit *test) +{ + static const struct apple_isp_hw hw = { .meta_exposure = true }; + static const struct apple_isp_hw hw_none = { }; + struct apple_isp *isp = isp_test_alloc(test); + struct isp_surf meta = { .size = 0x2000 }; + u8 *virt = kunit_kzalloc(test, meta.size, GFP_KERNEL); + + KUNIT_ASSERT_NOT_NULL(test, virt); + meta.virt = virt; + isp->hw = &hw; + isp->frame_gain = 256; + + /* fourth table entry: the section at 0x1870 */ + put_unaligned_le32(0x1870, virt + 0x1c); + put_unaligned_le32(32475, virt + 0x1870); + put_unaligned_le16(0x0800, virt + 0x1874); + put_unaligned_le16(3253, virt + 0x1876); + isp_meta_read_exposure(isp, &meta); + KUNIT_EXPECT_EQ(test, isp->frame_exposure_us, 32475); + KUNIT_EXPECT_EQ(test, isp->frame_gain, 3253); + + /* a section that would end past the buffer is ignored */ + put_unaligned_le32(meta.size - 4, virt + 0x1c); + put_unaligned_le32(1000, virt + meta.size - 4); + isp_meta_read_exposure(isp, &meta); + KUNIT_EXPECT_EQ(test, isp->frame_gain, 3253); + + /* so is an unwritten section */ + put_unaligned_le32(0x1000, virt + 0x1c); + isp_meta_read_exposure(isp, &meta); + KUNIT_EXPECT_EQ(test, isp->frame_exposure_us, 32475); + + /* and firmware without the report */ + put_unaligned_le32(0x1870, virt + 0x1c); + put_unaligned_le16(600, virt + 0x1876); + isp->hw = &hw_none; + isp_meta_read_exposure(isp, &meta); + KUNIT_EXPECT_EQ(test, isp->frame_gain, 3253); + isp->hw = &hw; + isp_meta_read_exposure(isp, &meta); + KUNIT_EXPECT_EQ(test, isp->frame_gain, 600); +} + static struct kunit_case isp_v4l2_test_cases[] = { + KUNIT_CASE(isp_test_meta_exposure), + KUNIT_CASE(isp_test_imx958_last_lease_requeue), + KUNIT_CASE(isp_test_p010_report_defers_completion), + KUNIT_CASE(isp_test_p010_mode_selection), + KUNIT_CASE(isp_test_p010_format), + KUNIT_CASE(isp_test_p010_admission), + KUNIT_CASE(isp_test_p010_completion_identity), KUNIT_CASE(isp_test_queue_init), KUNIT_CASE(isp_test_reqbufs_limit), KUNIT_CASE(isp_test_create_bufs_limit), diff --git a/drivers/media/platform/apple/isp/isp-v4l2.c b/drivers/media/platform/apple/isp/isp-v4l2.c index 072b8523279c28..81964ab1916c9d 100644 --- a/drivers/media/platform/apple/isp/isp-v4l2.c +++ b/drivers/media/platform/apple/isp/isp-v4l2.c @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -21,24 +22,20 @@ #define ISP_MIN_FRAMES 2 #define ISP_MAX_PLANES 4 -#define ISP_MAX_PIX_FORMATS 2 #define ISP_BUFFER_TIMEOUT msecs_to_jiffies(1500) #define ISP_STRIDE_ALIGNMENT 64 +static void isp_vb2_set_min_buffers(struct apple_isp *isp); + /* Capture rates offered to userspace, in frames per second */ static const unsigned int isp_frame_rates[] = { 30, 25, 24, 20, 15 }; -static bool multiplanar = false; -module_param(multiplanar, bool, 0644); -MODULE_PARM_DESC(multiplanar, "Enable multiplanar API"); - struct isp_buflist_buffer { u64 iovas[ISP_MAX_PLANES]; u32 flags[ISP_MAX_PLANES]; u32 num_planes; u32 pool_type; - u32 tag; - u32 pad; + u64 tag; } __packed; static_assert(sizeof(struct isp_buflist_buffer) == ISP_BUFLIST_DESC_SIZE); @@ -57,6 +54,77 @@ static_assert(ISP_CMD_AREA_SIZE(0) >= ISP_IPC_BUFEXC_STAT_SIZE); */ #define ISP_BUFLIST_POOL_CAPTURE_META 2 +static bool isp_p010_buffer_matches(const struct isp_format *fmt, + const struct isp_buffer *buf, + const struct isp_buflist_buffer *desc) +{ + u64 y = buf->surfs[0].iova; + u64 uv = y + fmt->plane_size[0]; + bool full = desc->iovas[0] == y && desc->iovas[1] == uv; + bool low = desc->iovas[0] == (u32)y && desc->iovas[1] == (u32)uv; + + /* Accept the submitted pair or the zero-extended pair observed on H17. */ + return desc->num_planes == 2 && + desc->pool_type == CISP_POOL_TYPE_RENDERED_SCL1 && (full || low) && + !desc->iovas[2] && !desc->iovas[3] && desc->tag == buf->tag; +} + +/* + * A metadata buffer starts with a table of section offsets. On H17 firmware + * the fourth section opens with the frame's exposure: the integration time in + * microseconds (le32 at 0) and the total sensor gain in 1/256 steps, 256 for + * unity (le16 at 6). Observed on T6040 and T8140 with AE converging under a + * fixed scene and with the frame rate capping the integration time. + */ +#define ISP_META_SECTIONS 0x10 +#define ISP_META_SECTION_EXPOSURE 3 +#define ISP_META_EXPOSURE_TIME 0x0 +#define ISP_META_EXPOSURE_GAIN 0x6 +#define ISP_META_EXPOSURE_SIZE 0x8 + +static void isp_meta_read_exposure(struct apple_isp *isp, + const struct isp_surf *meta) +{ + const u8 *virt = meta->virt; + u32 offset, time; + u16 gain; + + if (!isp->hw->meta_exposure || !virt) + return; + + offset = get_unaligned_le32(virt + ISP_META_SECTIONS + + 4 * ISP_META_SECTION_EXPOSURE); + if (offset < ISP_META_SECTIONS || offset > meta->size || + meta->size - offset < ISP_META_EXPOSURE_SIZE) + return; + + time = get_unaligned_le32(virt + offset + ISP_META_EXPOSURE_TIME); + gain = get_unaligned_le16(virt + offset + ISP_META_EXPOSURE_GAIN); + /* An unwritten section or one this layout does not describe */ + if (!time || !gain) + return; + + WRITE_ONCE(isp->frame_exposure_us, time); + WRITE_ONCE(isp->frame_gain, gain); +} + +void ipc_bt_complete(struct apple_isp *isp) +{ + struct isp_buffer *buf, *tmp; + unsigned long flags, i; + + /* The firmware has received its ACK before userspace can reuse a lease. */ + spin_lock_irqsave(&isp->buf_lock, flags); + for_each_set_bit(i, &isp->meta_returned, ISP_MAX_BUFFERS) + isp->meta_surfs[i]->submitted = false; + isp->meta_returned = 0; + list_for_each_entry_safe(buf, tmp, &isp->bufs_returned, link) { + list_del(&buf->link); + vb2_buffer_done(&buf->vb.vb2_buf, buf->return_state); + } + spin_unlock_irqrestore(&isp->buf_lock, flags); +} + int ipc_bt_handle(struct apple_isp *isp, struct isp_channel *chan) { struct isp_message *req = &chan->req, *rsp = &chan->rsp; @@ -96,11 +164,15 @@ int ipc_bt_handle(struct apple_isp *isp, struct isp_channel *chan) bufd->pool_type); */ if (bufd->pool_type == 0) { - for (int j = 0; j < ARRAY_SIZE(isp->meta_surfs); j++) { + for (int j = 0; j < isp_num_meta(isp); j++) { struct isp_surf *meta = isp->meta_surfs[j]; if ((u32)bufd->iovas[0] == (u32)meta->iova) { WARN_ON(!meta->submitted); - meta->submitted = false; + isp_meta_read_exposure(isp, meta); + if (isp_is_p010(isp)) + __set_bit(j, &isp->meta_returned); + else + meta->submitted = false; } } } else if (bufd->pool_type == ISP_BUFLIST_POOL_CAPTURE_META && @@ -114,8 +186,10 @@ int ipc_bt_handle(struct apple_isp *isp, struct isp_channel *chan) } else { list_for_each_entry_safe_reverse( buf, tmp, &isp->bufs_submitted, link) { - if ((u32)buf->surfs[0].iova == - (u32)bufd->iovas[0]) { + if (isp_is_p010(isp) ? + isp_p010_buffer_matches(isp_get_current_format(isp), + buf, bufd) : + (u32)buf->surfs[0].iova == (u32)bufd->iovas[0]) { enum vb2_buffer_state state = VB2_BUF_STATE_ERROR; @@ -126,9 +200,13 @@ int ipc_bt_handle(struct apple_isp *isp, struct isp_channel *chan) if (req->arg2 == ISP_IPC_BUFEXC_FLAG_RENDER) state = VB2_BUF_STATE_DONE; - vb2_buffer_done(&buf->vb.vb2_buf, - state); - list_del(&buf->link); + if (isp_is_p010(isp)) { + buf->return_state = state; + list_move_tail(&buf->link, &isp->bufs_returned); + } else { + vb2_buffer_done(&buf->vb.vb2_buf, state); + list_del(&buf->link); + } } } } @@ -161,12 +239,17 @@ static int isp_submit_buffers(struct apple_isp *isp, bool pre_start) struct isp_buflist *bl = isp->cmd_virt; struct isp_buflist_buffer *bufd = &bl->buffers[0]; + /* Before the command area is overwritten */ + err = isp_ipc_resync(isp); + if (err) + return err; + /* Clear what earlier commands and batches left in the reserved fields. */ memset(bl, 0, ISP_CMD_AREA_SIZE(isp_num_capmeta(isp))); bl->type = 1; spin_lock_irqsave(&isp->buf_lock, flags); - for (int i = 0; i < ARRAY_SIZE(isp->meta_surfs); i++) { + for (int i = 0; i < isp_num_meta(isp); i++) { struct isp_surf *meta = isp->meta_surfs[i]; if (meta->submitted) @@ -205,9 +288,13 @@ static int isp_submit_buffers(struct apple_isp *isp, bool pre_start) } /* One rendered pool per batch; the rest stays pending for the next. */ - while (num_rendered < ISP_MAX_BUFFERS && + while (num_rendered < isp_num_rendered(isp) && (buf = list_first_entry_or_null(&isp->bufs_pending, struct isp_buffer, link))) { + if (isp_is_p010(isp)) { + buf->tag = ++isp->buffer_tag; + bufd->tag = buf->tag; + } bufd->num_planes = fmt->num_planes; bufd->pool_type = isp->hw->scl1 ? CISP_POOL_TYPE_RENDERED_SCL1 : CISP_POOL_TYPE_RENDERED; @@ -249,6 +336,12 @@ static int isp_submit_buffers(struct apple_isp *isp, bool pre_start) err = ipc_chan_send(isp, chan, ISP_BUFFER_TIMEOUT); if (err) { + /* + * The firmware may have taken the batch. Keep its leases owned + * until the timeout is resolved, see apple_isp_stop_camera(). + */ + if (isp_is_p010(isp)) + return err; /* If we fail, consider the buffer not submitted. */ dev_err(isp->dev, "%s: failed to send bufs: [0x%llx, 0x%llx, 0x%llx]\n", @@ -269,7 +362,7 @@ static int isp_submit_buffers(struct apple_isp *isp, bool pre_start) &isp->bufs_pending); } } - for (int j = 0; j < ARRAY_SIZE(isp->meta_surfs); j++) { + for (int j = 0; j < isp_num_meta(isp); j++) { struct isp_surf *meta = isp->meta_surfs[j]; if (bufd->iovas[0] == meta->iova) { meta->submitted = false; @@ -308,13 +401,13 @@ static int isp_vb2_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, * REQBUFS frees the old buffers first, CREATE_BUFS adds to them, so * count the buffers the queue already has. */ - if (q_num_bufs >= ISP_MAX_BUFFERS) + if (q_num_bufs >= isp_num_rendered(isp)) return -ENOBUFS; *nbuffers = min_t(unsigned int, *nbuffers, - ISP_MAX_BUFFERS - q_num_bufs); + isp_num_rendered(isp) - q_num_bufs); if (*num_planes) { - if (sizes[0] < fmt->total_size) + if (*num_planes != 1 || sizes[0] < fmt->total_size) return -EINVAL; return 0; @@ -407,8 +500,23 @@ static void isp_vb2_buf_queue(struct vb2_buffer *vb) list_add_tail(&buf->link, &isp->bufs_pending); spin_unlock_irqrestore(&isp->buf_lock, flags); - if (test_bit(ISP_STATE_STREAMING, &isp->state) && !empty) - isp_submit_buffers(isp, false); + /* Restart an empty IMX958 queue when its last returned lease is queued. */ + if (test_bit(ISP_STATE_STREAMING, &isp->state) && + (isp_supports_p010(isp) || !empty)) { + if (isp_submit_buffers(isp, false) && isp_is_p010(isp)) { + /* + * After a timeout the leases stay owned until the + * stream stops. Only firmware that did not answer at + * all is stopped here, before its leases are released. + */ + if (isp->ipc_failed) { + apple_isp_firmware_halt(isp); + isp_vb2_release_buffers(isp, + VB2_BUF_STATE_ERROR); + } + vb2_queue_error(&isp->vbq); + } + } } static int apple_isp_start_streaming(struct apple_isp *isp) @@ -423,11 +531,12 @@ static int apple_isp_start_streaming(struct apple_isp *isp) } /* - * Resident firmware was not restarted, but the channel's pools are - * configured again for every stream. Metadata buffers still marked - * as submitted to the previous pools would never reach the new ones. + * The channel's pools are configured again for every stream, by + * resident firmware that kept running or by firmware that started + * afresh. Metadata buffers still marked as submitted to the previous + * pools, or to firmware that stopped, would never reach the new ones. */ - if (isp->hw->resident_fw) { + if (isp->hw->resident_fw || isp->hw->fw_restore) { spin_lock_irqsave(&isp->buf_lock, flags); for (int i = 0; i < ARRAY_SIZE(isp->meta_surfs); i++) isp->meta_surfs[i]->submitted = false; @@ -484,12 +593,14 @@ static int isp_vb2_start_streaming(struct vb2_queue *q, unsigned int count) isp->sequence = 0; - /* The exposure priority is applied when the stream starts. */ + /* The exposure controls are applied when the stream starts. */ v4l2_ctrl_grab(isp->exposure_priority, true); + v4l2_ctrl_grab(isp->power_line_frequency, true); err = apple_isp_start_streaming(isp); if (err) { v4l2_ctrl_grab(isp->exposure_priority, false); + v4l2_ctrl_grab(isp->power_line_frequency, false); isp_vb2_release_buffers(isp, VB2_BUF_STATE_QUEUED); } @@ -503,6 +614,7 @@ static void isp_vb2_stop_streaming(struct vb2_queue *q) apple_isp_stop_streaming(isp); isp_vb2_release_buffers(isp, VB2_BUF_STATE_ERROR); v4l2_ctrl_grab(isp->exposure_priority, false); + v4l2_ctrl_grab(isp->power_line_frequency, false); } int apple_isp_video_suspend(struct apple_isp *isp) @@ -565,18 +677,23 @@ static const struct vb2_ops isp_vb2_ops = { }; static int isp_set_preset(struct apple_isp *isp, struct isp_format *fmt, - struct isp_preset *preset) + struct isp_preset *preset, u32 pixelformat) { + unsigned int bytes_per_sample; int i; size_t total_size; fmt->preset = preset; - /* I really fucking hope they all use NV12. */ + /* P010 has MSB-aligned 10-bit samples in little-endian 16-bit words. */ + fmt->pixelformat = pixelformat == V4L2_PIX_FMT_P010 && + isp_supports_p010(isp) && preset->p010 ? + V4L2_PIX_FMT_P010 : V4L2_PIX_FMT_NV12; + bytes_per_sample = fmt->pixelformat == V4L2_PIX_FMT_P010 ? 2 : 1; fmt->num_planes = 2; - fmt->strides[0] = ALIGN(preset->output_dim.x, ISP_STRIDE_ALIGNMENT); - /* UV subsampled interleaved */ - fmt->strides[1] = ALIGN(preset->output_dim.x, ISP_STRIDE_ALIGNMENT); + fmt->strides[0] = ALIGN(preset->output_dim.x * bytes_per_sample, + ISP_STRIDE_ALIGNMENT); + fmt->strides[1] = fmt->strides[0]; fmt->plane_size[0] = fmt->strides[0] * preset->output_dim.y; fmt->plane_size[1] = fmt->strides[1] * preset->output_dim.y / 2; @@ -589,17 +706,25 @@ static int isp_set_preset(struct apple_isp *isp, struct isp_format *fmt, } static struct isp_preset *isp_select_preset(struct apple_isp *isp, u32 width, - u32 height) + u32 height, u32 pixelformat) { struct isp_preset *preset, *best = &isp->presets[0]; int i, score, best_score = INT_MAX; - /* Default if no dimensions */ - if (width == 0 || height == 0) - return &isp->presets[0]; + bool p010 = pixelformat == V4L2_PIX_FMT_P010 && isp_has_p010(isp); + + /* An unspecified P010 size selects the processed 720p preview first. */ + if (width == 0 || height == 0) { + if (!p010) + return &isp->presets[0]; + width = 1280; + height = 720; + } for (i = 0; i < isp->num_presets; i++) { preset = &isp->presets[i]; + if (p010 && !preset->p010) + continue; score = abs((int)preset->output_dim.x - (int)width) + abs((int)preset->output_dim.y - (int)height); if (score < best_score) { @@ -623,44 +748,47 @@ static int isp_vidioc_querycap(struct file *file, void *priv, return 0; } -static int isp_vidioc_enum_format(struct file *file, void *fh, - struct v4l2_fmtdesc *f) +static int isp_enum_pixelformat(struct apple_isp *isp, struct v4l2_fmtdesc *f) { - struct apple_isp *isp = video_drvdata(file); - - if (f->index >= ISP_MAX_PIX_FORMATS) - return -EINVAL; - - switch (f->index) { - case 0: + /* Browser/WebRTC compatibility: the shipped first format remains NV12. */ + if (!f->index) f->pixelformat = V4L2_PIX_FMT_NV12; - break; - case 1: - if (!isp->multiplanar) - return -EINVAL; - f->pixelformat = V4L2_PIX_FMT_NV12M; - break; - default: + else if (f->index == 1 && isp_has_p010(isp)) + f->pixelformat = V4L2_PIX_FMT_P010; + else return -EINVAL; - } - return 0; } +static int isp_vidioc_enum_format(struct file *file, void *fh, + struct v4l2_fmtdesc *f) +{ + return isp_enum_pixelformat(video_drvdata(file), f); +} + static int isp_vidioc_enum_framesizes(struct file *file, void *fh, struct v4l2_frmsizeenum *f) { struct apple_isp *isp = video_drvdata(file); + struct isp_preset *preset = NULL; + u32 index = 0; - if (f->index >= isp->num_presets) + if (f->pixel_format != V4L2_PIX_FMT_NV12 && + !(f->pixel_format == V4L2_PIX_FMT_P010 && isp_has_p010(isp))) return -EINVAL; - if ((f->pixel_format != V4L2_PIX_FMT_NV12) && - (f->pixel_format != V4L2_PIX_FMT_NV12M)) + for (int i = 0; i < isp->num_presets; i++) { + if (f->pixel_format == V4L2_PIX_FMT_P010 && !isp->presets[i].p010) + continue; + if (index++ == f->index) { + preset = &isp->presets[i]; + break; + } + } + if (!preset) return -EINVAL; - - f->discrete.width = isp->presets[f->index].output_dim.x; - f->discrete.height = isp->presets[f->index].output_dim.y; + f->discrete.width = preset->output_dim.x; + f->discrete.height = preset->output_dim.y; f->type = V4L2_FRMSIZE_TYPE_DISCRETE; return 0; @@ -676,10 +804,12 @@ static int isp_vidioc_enum_frameintervals(struct file *file, void *fh, return -EINVAL; if (interval->pixel_format != V4L2_PIX_FMT_NV12 && - interval->pixel_format != V4L2_PIX_FMT_NV12M) + !(interval->pixel_format == V4L2_PIX_FMT_P010 && isp_has_p010(isp))) return -EINVAL; for (i = 0; i < isp->num_presets; i++) { + if (interval->pixel_format == V4L2_PIX_FMT_P010 && !isp->presets[i].p010) + continue; if (isp->presets[i].output_dim.x == interval->width && isp->presets[i].output_dim.y == interval->height) break; @@ -726,29 +856,12 @@ static inline void isp_get_sp_pix_format(struct apple_isp *isp, f->fmt.pix.sizeimage = fmt->total_size; f->fmt.pix.field = V4L2_FIELD_NONE; - f->fmt.pix.pixelformat = V4L2_PIX_FMT_NV12; + f->fmt.pix.pixelformat = fmt->pixelformat; f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709; f->fmt.pix.ycbcr_enc = V4L2_YCBCR_ENC_709; f->fmt.pix.xfer_func = V4L2_XFER_FUNC_709; -} - -static inline void isp_get_mp_pix_format(struct apple_isp *isp, - struct v4l2_format *f, - struct isp_format *fmt) -{ - f->fmt.pix_mp.width = fmt->preset->output_dim.x; - f->fmt.pix_mp.height = fmt->preset->output_dim.y; - f->fmt.pix_mp.num_planes = fmt->num_planes; - for (int i = 0; i < fmt->num_planes; i++) { - f->fmt.pix_mp.plane_fmt[i].sizeimage = fmt->plane_size[i]; - f->fmt.pix_mp.plane_fmt[i].bytesperline = fmt->strides[i]; - } - - f->fmt.pix_mp.field = V4L2_FIELD_NONE; - f->fmt.pix_mp.pixelformat = V4L2_PIX_FMT_NV12M; - f->fmt.pix_mp.colorspace = V4L2_COLORSPACE_REC709; - f->fmt.pix_mp.ycbcr_enc = V4L2_YCBCR_ENC_709; - f->fmt.pix_mp.xfer_func = V4L2_XFER_FUNC_709; + if (fmt->pixelformat == V4L2_PIX_FMT_P010) + f->fmt.pix.quantization = V4L2_QUANTIZATION_LIM_RANGE; } static int isp_vidioc_get_format(struct file *file, void *fh, @@ -774,14 +887,16 @@ static int isp_vidioc_set_format(struct file *file, void *fh, if (vb2_is_busy(&isp->vbq)) return -EBUSY; - preset = isp_select_preset(isp, f->fmt.pix.width, f->fmt.pix.height); - err = isp_set_preset(isp, fmt, preset); + preset = isp_select_preset(isp, f->fmt.pix.width, f->fmt.pix.height, + f->fmt.pix.pixelformat); + err = isp_set_preset(isp, fmt, preset, f->fmt.pix.pixelformat); if (err) return err; isp_get_sp_pix_format(isp, f, fmt); isp->vbq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + isp_vb2_set_min_buffers(isp); return 0; } @@ -794,8 +909,9 @@ static int isp_vidioc_try_format(struct file *file, void *fh, struct isp_preset *preset; int err; - preset = isp_select_preset(isp, f->fmt.pix.width, f->fmt.pix.height); - err = isp_set_preset(isp, &fmt, preset); + preset = isp_select_preset(isp, f->fmt.pix.width, f->fmt.pix.height, + f->fmt.pix.pixelformat); + err = isp_set_preset(isp, &fmt, preset, f->fmt.pix.pixelformat); if (err) return err; @@ -804,69 +920,6 @@ static int isp_vidioc_try_format(struct file *file, void *fh, return 0; } -static int isp_vidioc_get_format_mplane(struct file *file, void *fh, - struct v4l2_format *f) -{ - struct apple_isp *isp = video_drvdata(file); - struct isp_format *fmt = isp_get_current_format(isp); - - if (!isp->multiplanar) - return -ENOTTY; - - isp_get_mp_pix_format(isp, f, fmt); - - return 0; -} - -static int isp_vidioc_set_format_mplane(struct file *file, void *fh, - struct v4l2_format *f) -{ - struct apple_isp *isp = video_drvdata(file); - struct isp_format *fmt = isp_get_current_format(isp); - struct isp_preset *preset; - int err; - - if (!isp->multiplanar) - return -ENOTTY; - - if (vb2_is_busy(&isp->vbq)) - return -EBUSY; - - preset = isp_select_preset(isp, f->fmt.pix_mp.width, - f->fmt.pix_mp.height); - err = isp_set_preset(isp, fmt, preset); - if (err) - return err; - - isp_get_mp_pix_format(isp, f, fmt); - - isp->vbq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; - - return 0; -} - -static int isp_vidioc_try_format_mplane(struct file *file, void *fh, - struct v4l2_format *f) -{ - struct apple_isp *isp = video_drvdata(file); - struct isp_format fmt = *isp_get_current_format(isp); - struct isp_preset *preset; - int err; - - if (!isp->multiplanar) - return -ENOTTY; - - preset = isp_select_preset(isp, f->fmt.pix_mp.width, - f->fmt.pix_mp.height); - err = isp_set_preset(isp, &fmt, preset); - if (err) - return err; - - isp_get_mp_pix_format(isp, f, &fmt); - - return 0; -} - static int isp_vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *inp) { @@ -899,9 +952,7 @@ static int isp_vidioc_get_param(struct file *file, void *fh, { struct apple_isp *isp = video_drvdata(file); - if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && - (!isp->multiplanar || - a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)) + if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) return -EINVAL; a->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; @@ -917,9 +968,7 @@ static int isp_vidioc_set_param(struct file *file, void *fh, struct apple_isp *isp = video_drvdata(file); struct v4l2_fract *tpf = &a->parm.capture.timeperframe; - if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && - (!isp->multiplanar || - a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)) + if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) return -EINVAL; /* The rate is configured when the stream starts. */ @@ -940,6 +989,27 @@ static int isp_vidioc_set_param(struct file *file, void *fh, return 0; } +static int isp_vidioc_log_status(struct file *file, void *fh) +{ + struct apple_isp *isp = video_drvdata(file); + + v4l2_ctrl_log_status(file, fh); + for (unsigned int i = 0; i < isp->num_sensor_configs; i++) { + const struct isp_sensor_config *config = &isp->sensor_configs[i]; + + v4l2_info(&isp->v4l2_dev, + "sensor config %u: input %ux%u output %ux%u clock %u%s\n", + i, config->input_dim.x, config->input_dim.y, + config->output_dim.x, config->output_dim.y, + config->sensor_clk, + config->usable ? "" : " (unverified geometry)"); + /* This explicit diagnostic ioctl replaces a probe-time parameter. */ + print_hex_dump(KERN_INFO, "apple-isp config: ", DUMP_PREFIX_OFFSET, + 16, 4, config->reply, sizeof(config->reply), false); + } + return 0; +} + static const struct v4l2_ioctl_ops isp_v4l2_ioctl_ops = { .vidioc_querycap = isp_vidioc_querycap, @@ -947,9 +1017,6 @@ static const struct v4l2_ioctl_ops isp_v4l2_ioctl_ops = { .vidioc_g_fmt_vid_cap = isp_vidioc_get_format, .vidioc_s_fmt_vid_cap = isp_vidioc_set_format, .vidioc_try_fmt_vid_cap = isp_vidioc_try_format, - .vidioc_g_fmt_vid_cap_mplane = isp_vidioc_get_format_mplane, - .vidioc_s_fmt_vid_cap_mplane = isp_vidioc_set_format_mplane, - .vidioc_try_fmt_vid_cap_mplane = isp_vidioc_try_format_mplane, .vidioc_enum_framesizes = isp_vidioc_enum_framesizes, .vidioc_enum_frameintervals = isp_vidioc_enum_frameintervals, @@ -969,7 +1036,7 @@ static const struct v4l2_ioctl_ops isp_v4l2_ioctl_ops = { .vidioc_streamon = vb2_ioctl_streamon, .vidioc_streamoff = vb2_ioctl_streamoff, - .vidioc_log_status = v4l2_ctrl_log_status, + .vidioc_log_status = isp_vidioc_log_status, .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, .vidioc_unsubscribe_event = v4l2_event_unsubscribe, }; @@ -1001,6 +1068,7 @@ static void apple_isp_release(struct v4l2_device *v4l2_dev) v4l2_ctrl_handler_free(&isp->ctrl_handler); media_device_cleanup(&isp->mdev); + kfree(isp->sensor_configs); kfree(isp); } @@ -1019,6 +1087,22 @@ static void isp_free_meta_surfaces(struct apple_isp *isp) } } +/* + * vb2 allocates at least min_queued_buffers + 1 buffers, and the queue may + * hold no more than the rendered pool (isp_vb2_queue_setup()). The P010 pool + * has two slots, so a P010 stream starts with one queued buffer; otherwise + * REQBUFS can never get the three buffers vb2 asks for and fails with ENOMEM. + * Only called while the queue has no buffers. + */ +static void isp_vb2_set_min_buffers(struct apple_isp *isp) +{ + struct vb2_queue *vbq = &isp->vbq; + + vbq->min_queued_buffers = min_t(unsigned int, ISP_MIN_FRAMES, + isp_num_rendered(isp) - 1); + vbq->min_reqbufs_allocation = vbq->min_queued_buffers + 1; +} + static int isp_vb2_queue_init(struct apple_isp *isp) { struct vb2_queue *vbq = &isp->vbq; @@ -1037,6 +1121,53 @@ static int isp_vb2_queue_init(struct apple_isp *isp) return vb2_queue_init(vbq); } +static int isp_g_volatile_ctrl(struct v4l2_ctrl *ctrl) +{ + struct apple_isp *isp = + container_of(ctrl->handler, struct apple_isp, ctrl_handler); + + switch (ctrl->id) { + case V4L2_CID_GAIN: + ctrl->val = READ_ONCE(isp->frame_gain); + return 0; + case V4L2_CID_EXPOSURE_ABSOLUTE: + /* in 100 us units */ + ctrl->val = DIV_ROUND_CLOSEST(READ_ONCE(isp->frame_exposure_us), + 100); + return 0; + } + + return -EINVAL; +} + +static const struct v4l2_ctrl_ops isp_exposure_ctrl_ops = { + .g_volatile_ctrl = isp_g_volatile_ctrl, +}; + +/* + * Auto exposure picks the gain and exposure of each frame. Report the last + * frame's values read-only, so that userspace can follow the scene light, for + * example to decide when to denoise. The gain is the firmware's total sensor + * gain in 1/256 steps. + */ +static void isp_init_exposure_ctrls(struct apple_isp *isp) +{ + isp->frame_gain = 256; + isp->gain = v4l2_ctrl_new_std(&isp->ctrl_handler, + &isp_exposure_ctrl_ops, V4L2_CID_GAIN, + 0, U16_MAX, 1, 256); + isp->exposure = v4l2_ctrl_new_std(&isp->ctrl_handler, + &isp_exposure_ctrl_ops, + V4L2_CID_EXPOSURE_ABSOLUTE, + 0, 10000, 1, 0); + if (isp->gain) + isp->gain->flags |= V4L2_CTRL_FLAG_READ_ONLY | + V4L2_CTRL_FLAG_VOLATILE; + if (isp->exposure) + isp->exposure->flags |= V4L2_CTRL_FLAG_READ_ONLY | + V4L2_CTRL_FLAG_VOLATILE; +} + int apple_isp_setup_video(struct apple_isp *isp) { struct video_device *vdev = &isp->vdev; @@ -1044,7 +1175,7 @@ int apple_isp_setup_video(struct apple_isp *isp) struct isp_format *fmt = isp_get_current_format(isp); int err; - err = isp_set_preset(isp, fmt, &isp->presets[0]); + err = isp_set_preset(isp, fmt, &isp->presets[0], V4L2_PIX_FMT_NV12); if (err) { dev_err(isp->dev, "failed to set default preset: %d\n", err); return err; @@ -1054,7 +1185,8 @@ int apple_isp_setup_video(struct apple_isp *isp) for (int i = 0; i < ARRAY_SIZE(isp->meta_surfs); i++) { isp->meta_surfs[i] = - isp_alloc_surface_vmap(isp, isp->hw->meta_size); + isp_alloc_surface_vmap(isp, isp_has_p010(isp) ? 0x8000 : + isp->hw->meta_size); if (!isp->meta_surfs[i]) { isp_err(isp, "failed to alloc meta surface\n"); err = -ENOMEM; @@ -1086,16 +1218,28 @@ int apple_isp_setup_video(struct apple_isp *isp) goto media_cleanup; } - isp->multiplanar = multiplanar; - /* * Auto exposure is always on. By default it holds the frame rate, as * V4L2 specifies; with exposure priority it may slow down in low light. */ - v4l2_ctrl_handler_init(&isp->ctrl_handler, 1); + v4l2_ctrl_handler_init(&isp->ctrl_handler, 4); isp->exposure_priority = v4l2_ctrl_new_std(&isp->ctrl_handler, NULL, V4L2_CID_EXPOSURE_AUTO_PRIORITY, 0, 1, 1, 0); + /* + * The H17 firmware's auto exposure avoids mains flicker at the given + * frequency. 50 Hz is the default, as on macOS when it does not know + * the country; userspace sets 60 Hz where the mains runs at 60 Hz. + */ + if (isp->hw->fw_abi == ISP_FW_ABI_H17) + isp->power_line_frequency = + v4l2_ctrl_new_std_menu(&isp->ctrl_handler, NULL, + V4L2_CID_POWER_LINE_FREQUENCY, + V4L2_CID_POWER_LINE_FREQUENCY_60HZ, + BIT(V4L2_CID_POWER_LINE_FREQUENCY_DISABLED), + V4L2_CID_POWER_LINE_FREQUENCY_50HZ); + if (isp->hw->meta_exposure) + isp_init_exposure_ctrls(isp); if (isp->ctrl_handler.error) { err = isp->ctrl_handler.error; dev_err(isp->dev, "failed to create controls: %d\n", err); @@ -1119,8 +1263,6 @@ int apple_isp_setup_video(struct apple_isp *isp) vdev->fops = &isp_v4l2_fops; vdev->ioctl_ops = &isp_v4l2_ioctl_ops; vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; - if (isp->multiplanar) - vdev->device_caps |= V4L2_CAP_VIDEO_CAPTURE_MPLANE; vdev->entity.flags = MEDIA_ENT_FL_DEFAULT; vdev->v4l2_dev = &isp->v4l2_dev; vdev->vfl_type = VFL_TYPE_VIDEO; diff --git a/drivers/media/platform/apple/isp/isp-v4l2.h b/drivers/media/platform/apple/isp/isp-v4l2.h index 622288296aaae0..55135594576b2e 100644 --- a/drivers/media/platform/apple/isp/isp-v4l2.h +++ b/drivers/media/platform/apple/isp/isp-v4l2.h @@ -9,6 +9,7 @@ int apple_isp_setup_video(struct apple_isp *isp); void apple_isp_remove_video(struct apple_isp *isp); void apple_isp_free_video(struct apple_isp *isp); +void ipc_bt_complete(struct apple_isp *isp); int ipc_bt_handle(struct apple_isp *isp, struct isp_channel *chan); int apple_isp_video_suspend(struct apple_isp *isp); diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index d3ef47fa840e49..c2921f1070d6a0 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -198,6 +198,8 @@ struct apple_nvme_hw { bool has_queue_count; bool has_separate_nvmmu; bool needs_ioq_registers; + /* Enable with the firmware's CC fields (128-byte SQ entries) instead of the core's. */ + bool keep_cc_fields; u32 max_queue_depth; unsigned long quirks; }; @@ -343,6 +345,13 @@ static bool apple_nvme_can_adopt_rtkit(struct apple_nvme *anv) * and ready identifies a live session. Borrowed buffers still require * reserved RAM and protected SART ranges. */ + /* + * T6050: the loader hands over the controller disabled with the RTKit + * session live (it cannot be restarted after a stop). Adopt on RUN and + * BOOT_STATUS alone there; the enable below starts the controller. + */ + if (anv->hw->keep_cc_fields && (cc & NVME_CC_ENABLE)) + return !(csts & NVME_CSTS_CFS); return (cc & NVME_CC_ENABLE) && (csts & NVME_CSTS_RDY) && !(csts & NVME_CSTS_CFS); } @@ -360,7 +369,8 @@ static unsigned int apple_nvme_queue_depth(struct apple_nvme_queue *q) struct apple_nvme *anv = queue_to_apple_nvme(q); if (q->is_adminq) - return APPLE_NVME_AQ_DEPTH; + return anv->hw->keep_cc_fields ? anv->hw->max_queue_depth : + APPLE_NVME_AQ_DEPTH; return anv->hw->max_queue_depth; } @@ -1535,6 +1545,31 @@ static void apple_nvme_wait_freeze(struct apple_nvme *anv) } } +/* + * T6050: the controller only reports ready when CC keeps the entry-size fields + * the firmware set (IOSQES 7, 128-byte entries), as the loader does. The core's + * nvme_enable_ctrl composes CC with the standard IOSQES 6. + */ +static int apple_nvme_enable_ctrl_keep_cc(struct apple_nvme *anv) +{ + u32 cc, csts, timeout_ms; + + anv->ctrl.cap = readq(anv->mmio_nvme + NVME_REG_CAP); + cc = readl(anv->mmio_nvme + NVME_REG_CC); + cc &= ~(NVME_CC_SHN_MASK | NVME_CC_ENABLE); + cc |= NVME_CC_ENABLE; + anv->ctrl.ctrl_config = cc; + writel(cc, anv->mmio_nvme + NVME_REG_CC); + timeout_ms = clamp_t(u32, (NVME_CAP_TIMEOUT(anv->ctrl.cap) + 1) * 500, 1000, 10000); + if (readl_poll_timeout(anv->mmio_nvme + NVME_REG_CSTS, csts, + csts & NVME_CSTS_RDY, 100, timeout_ms * 1000)) { + dev_err(anv->dev, "controller not ready after enable, CC=%#x CSTS=%#x\n", + readl(anv->mmio_nvme + NVME_REG_CC), readl(anv->mmio_nvme + NVME_REG_CSTS)); + return -ENODEV; + } + return 0; +} + static void apple_nvme_reset_work(struct work_struct *work) { unsigned int nr_io_queues = 1; @@ -1710,8 +1745,13 @@ static void apple_nvme_reset_work(struct work_struct *work) * Enable NVMMU and linear submission queues which is required * since T6000. */ - writel(APPLE_ANS_LINEAR_SQ_EN, - anv->mmio_nvme + APPLE_ANS_LINEAR_SQ_CTRL); + if (anv->hw->keep_cc_fields) + writel(readl(anv->mmio_nvme + APPLE_ANS_LINEAR_SQ_CTRL) | + APPLE_ANS_LINEAR_SQ_EN, + anv->mmio_nvme + APPLE_ANS_LINEAR_SQ_CTRL); + else + writel(APPLE_ANS_LINEAR_SQ_EN, + anv->mmio_nvme + APPLE_ANS_LINEAR_SQ_CTRL); if (anv->hw->needs_ioq_registers) { u32 lsq_ctrl = readl(anv->mmio_nvme + APPLE_ANS_LINEAR_SQ_CTRL); @@ -1750,15 +1790,28 @@ static void apple_nvme_reset_work(struct work_struct *work) } /* Setup the admin queue */ - aqa = APPLE_NVME_AQ_DEPTH - 1; + aqa = apple_nvme_queue_depth(&anv->adminq) - 1; aqa |= aqa << 16; - writel(aqa, anv->mmio_nvme + NVME_REG_AQA); - apple_nvme_writeq(anv, anv->adminq.sq_dma_addr, - anv->mmio_nvme + NVME_REG_ASQ); - apple_nvme_writeq(anv, anv->adminq.cq_dma_addr, - anv->mmio_nvme + NVME_REG_ACQ); + if (anv->hw->keep_cc_fields) { + /* T6050: the loader's order, NVMMU TCB bases, ASQ, ACQ, then AQA. */ + apple_nvme_writeq(anv, anv->adminq.tcb_dma_addr, + anv->mmio_nvmmu + APPLE_NVMMU_ASQ_TCB_BASE); + apple_nvme_writeq(anv, anv->ioq.tcb_dma_addr, + anv->mmio_nvmmu + APPLE_NVMMU_IOSQ_TCB_BASE); + apple_nvme_writeq(anv, anv->adminq.sq_dma_addr, + anv->mmio_nvme + NVME_REG_ASQ); + apple_nvme_writeq(anv, anv->adminq.cq_dma_addr, + anv->mmio_nvme + NVME_REG_ACQ); + writel(aqa, anv->mmio_nvme + NVME_REG_AQA); + } else { + writel(aqa, anv->mmio_nvme + NVME_REG_AQA); + apple_nvme_writeq(anv, anv->adminq.sq_dma_addr, + anv->mmio_nvme + NVME_REG_ASQ); + apple_nvme_writeq(anv, anv->adminq.cq_dma_addr, + anv->mmio_nvme + NVME_REG_ACQ); + } - if (anv->hw->has_lsq_nvmmu) { + if (anv->hw->has_lsq_nvmmu && !anv->hw->keep_cc_fields) { /* Setup NVMMU for both queues */ apple_nvme_writeq(anv, anv->adminq.tcb_dma_addr, anv->mmio_nvmmu + APPLE_NVMMU_ASQ_TCB_BASE); @@ -1771,7 +1824,8 @@ static void apple_nvme_reset_work(struct work_struct *work) anv->ctrl.cap = readq(anv->mmio_nvme + NVME_REG_CAP); dev_dbg(anv->dev, "Enabling controller now"); - ret = nvme_enable_ctrl(&anv->ctrl); + ret = anv->hw->keep_cc_fields ? apple_nvme_enable_ctrl_keep_cc(anv) : + nvme_enable_ctrl(&anv->ctrl); if (ret) goto out; @@ -2642,11 +2696,27 @@ static const struct apple_nvme_hw apple_nvme_t8140_hw = { .quirks = NVME_QUIRK_BROKEN_FUA, }; +/* T6050: T8140 queue setup, with the CC fields the firmware sets. */ +static const struct apple_nvme_hw apple_nvme_t6050_hw = { + .has_lsq_nvmmu = true, + .has_separate_nvmmu = true, + .needs_ioq_registers = true, + .max_queue_depth = 64, + /* + * An fsynced overwrite completed and later reverted after an abrupt + * reset; explicit flushes persisted the preceding data. Let the block + * layer follow each FUA write with a flush. + */ + .quirks = NVME_QUIRK_BROKEN_FUA, + .keep_cc_fields = true, +}; + static const struct of_device_id apple_nvme_of_match[] = { { .compatible = "apple,t8015-nvme-ans2", .data = &apple_nvme_t8015_hw }, { .compatible = "apple,t8103-nvme-ans2", .data = &apple_nvme_t8103_hw }, { .compatible = "apple,t8132-nvme-ans2", .data = &apple_nvme_t8132_hw }, { .compatible = "apple,t8140-nvme-ans2", .data = &apple_nvme_t8140_hw }, + { .compatible = "apple,t6050-nvme-ans2", .data = &apple_nvme_t6050_hw }, { .compatible = "apple,nvme-ans2", .data = &apple_nvme_t8103_hw }, {}, }; diff --git a/drivers/power/supply/macsmc-power.c b/drivers/power/supply/macsmc-power.c index aec59fe13483c4..9e8388f9a824b4 100644 --- a/drivers/power/supply/macsmc-power.c +++ b/drivers/power/supply/macsmc-power.c @@ -1000,11 +1000,18 @@ static int macsmc_power_probe(struct platform_device *pdev) return ret; dev_set_drvdata(dev, power); - INIT_WORK(&power->critical_work, macsmc_power_critical_work); + /* devm_work_autocancel() initialises critical_work */ ret = devm_work_autocancel(dev, &power->critical_work, macsmc_power_critical_work); if (ret) return ret; + /* + * Must be ready before the notifier is registered below: an SMC event + * can arrive as soon as it is, and re-initialising a work item that + * is already queued corrupts the workqueue. + */ + INIT_DELAYED_WORK(&power->dbg_log_work, macsmc_dbg_work); + /* * Check for battery presence. * B0AV is a fundamental key. @@ -1209,9 +1216,6 @@ static int macsmc_power_probe(struct platform_device *pdev) power->nb.notifier_call = macsmc_power_event; blocking_notifier_chain_register(&smc->event_handlers, &power->nb); - INIT_WORK(&power->critical_work, macsmc_power_critical_work); - INIT_DELAYED_WORK(&power->dbg_log_work, macsmc_dbg_work); - g_power = power; if (log_power) diff --git a/drivers/soc/apple/rtkit-helper.c b/drivers/soc/apple/rtkit-helper.c index 5f03bed772f264..d5d2b473219f21 100644 --- a/drivers/soc/apple/rtkit-helper.c +++ b/drivers/soc/apple/rtkit-helper.c @@ -169,7 +169,8 @@ static int apple_rtkit_helper_probe(struct platform_device *pdev) helper->asc_base + APPLE_ASC_CPU_CONTROL); /* Works for both wake and boot */ - if (of_device_is_compatible(dev->of_node, "apple,t8142-mtp")) + if (of_device_is_compatible(dev->of_node, "apple,t8142-mtp") || + of_device_is_compatible(dev->of_node, "apple,t6050-mtp")) ret = apple_rtkit_wake_early_ap(helper->rtk); else ret = apple_rtkit_wake(helper->rtk); diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index 11334b3f68faa5..c37008e2d86e79 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -190,7 +190,13 @@ static void apple_rtkit_management_rx_hello(struct apple_rtkit *rtk, u64 msg) static void apple_rtkit_management_rx_epmap(struct apple_rtkit *rtk, u64 msg) { - int i, ep, ret; + /* T6050: the system endpoints start in the loader's order, 3 1 2 4 8. */ + static const u8 t6050_order[] = { APPLE_RTKIT_EP_DEBUG, APPLE_RTKIT_EP_CRASHLOG, + APPLE_RTKIT_EP_SYSLOG, APPLE_RTKIT_EP_IOREPORT, + APPLE_RTKIT_EP_OSLOG }; + bool loader_order = of_machine_is_compatible("apple,t6050"); + int count = loader_order ? ARRAY_SIZE(t6050_order) : APPLE_RTKIT_APP_ENDPOINT_START; + int i, oi, ep, ret; u64 reply; unsigned long bitmap = FIELD_GET(APPLE_RTKIT_MGMT_EPMAP_BITMAP, msg); u32 base = FIELD_GET(APPLE_RTKIT_MGMT_EPMAP_BASE, msg); @@ -230,7 +236,10 @@ static void apple_rtkit_management_rx_epmap(struct apple_rtkit *rtk, u64 msg) if (!(msg & APPLE_RTKIT_MGMT_EPMAP_LAST)) return; - for_each_set_bit(ep, rtk->endpoints, APPLE_RTKIT_APP_ENDPOINT_START) { + for (oi = 0; oi < count; oi++) { + ep = loader_order ? t6050_order[oi] : oi; + if (!test_bit(ep, rtk->endpoints)) + continue; switch (ep) { /* the management endpoint is started by default */ case APPLE_RTKIT_EP_MGMT: @@ -756,7 +765,8 @@ static void apple_rtkit_oslog_rx(struct apple_rtkit *rtk, u64 msg) /* Preserve the tested Neo/M5 and synchronous-log no-ACK policy. */ if (type == APPLE_RTKIT_OSLOG_LOG && (rtk->sync_syslog_ack || of_machine_is_compatible("apple,t8140") || - of_machine_is_compatible("apple,t8142"))) { + of_machine_is_compatible("apple,t8142") || + of_machine_is_compatible("apple,t6050"))) { dev_dbg(rtk->dev, "RTKit: oslog notification: %016llx\n", msg); return; } @@ -1313,6 +1323,18 @@ static int apple_rtkit_set_ap_power_state(struct apple_rtkit *rtk, if (ret) return ret; + /* + * T6050: the loader never waits for this acknowledgment, and not every + * coprocessor sends it. Give it a short window so a caller that starts an + * endpoint right away (macsmc) sees the AP state; carry on without it. + */ + if (of_machine_is_compatible("apple,t6050")) { + if (!wait_for_completion_timeout(&rtk->ap_pwr_ack_completion, + msecs_to_jiffies(200))) + dev_dbg(rtk->dev, "RTKit: no AP power state ACK\n"); + return 0; + } + ret = apple_rtkit_wait(rtk, &rtk->ap_pwr_ack_completion); if (ret) return ret; @@ -1379,6 +1401,28 @@ static int apple_rtkit_boot_common(struct apple_rtkit *rtk, bool early_ap_power) return ret; } + /* + * T6050: the loader only proceeds once the IOP reports ON, and + * intermediate states can be acknowledged first. Wait for ON here too. + */ + if (of_machine_is_compatible("apple,t6050")) { + int tries = 10; + + while ((rtk->iop_power_state & 0xff) != APPLE_RTKIT_PWR_STATE_ON && tries--) { + dev_dbg(rtk->dev, "RTKit: IOP power state 0x%x, waiting for ON\n", + rtk->iop_power_state); + reinit_completion(&rtk->iop_pwr_ack_completion); + if ((rtk->iop_power_state & 0xff) == APPLE_RTKIT_PWR_STATE_ON) + break; + ret = apple_rtkit_wait(rtk, &rtk->iop_pwr_ack_completion); + if (ret) { + dev_err(rtk->dev, "RTKit: IOP never reached ON (state 0x%x): %d\n", + rtk->iop_power_state, ret); + return ret; + } + } + } + return early_ap_power ? 0 : apple_rtkit_set_ap_power_state(rtk, APPLE_RTKIT_PWR_STATE_ON); } diff --git a/drivers/soc/apple/sart.c b/drivers/soc/apple/sart.c index b0b208c92741dc..e2450cbfa09bc4 100644 --- a/drivers/soc/apple/sart.c +++ b/drivers/soc/apple/sart.c @@ -62,6 +62,18 @@ #define APPLE_SART3_FLAGS_ALLOW 0xff +/* SARTv4: the T6050 layout, config at 0x00, paddr at 0x60, size at 0xc0 */ +#define APPLE_SART4_CONFIG(idx) (0x00 + 4 * (idx)) + +#define APPLE_SART4_PADDR(idx) (0x60 + 4 * (idx)) +#define APPLE_SART4_PADDR_SHIFT 12 + +#define APPLE_SART4_SIZE(idx) (0xc0 + 4 * (idx)) +#define APPLE_SART4_SIZE_SHIFT 12 +#define APPLE_SART4_SIZE_MAX GENMASK(29, 0) + +#define APPLE_SART4_FLAGS_ALLOW 0xff + struct apple_sart_ops { void (*get_entry)(struct apple_sart *sart, int index, u8 *flags, phys_addr_t *paddr, size_t *size); @@ -178,6 +190,34 @@ static struct apple_sart_ops sart_ops_v3 = { .size_max = APPLE_SART3_SIZE_MAX, }; +static void sart4_get_entry(struct apple_sart *sart, int index, u8 *flags, + phys_addr_t *paddr, size_t *size) +{ + phys_addr_t paddr_ = readl(sart->regs + APPLE_SART4_PADDR(index)); + size_t size_ = readl(sart->regs + APPLE_SART4_SIZE(index)); + + *flags = readl(sart->regs + APPLE_SART4_CONFIG(index)); + *size = size_ << APPLE_SART4_SIZE_SHIFT; + *paddr = paddr_ << APPLE_SART4_PADDR_SHIFT; +} + +static void sart4_set_entry(struct apple_sart *sart, int index, u8 flags, + phys_addr_t paddr_shifted, size_t size_shifted) +{ + writel(paddr_shifted, sart->regs + APPLE_SART4_PADDR(index)); + writel(size_shifted, sart->regs + APPLE_SART4_SIZE(index)); + writel(flags, sart->regs + APPLE_SART4_CONFIG(index)); +} + +static struct apple_sart_ops sart_ops_v4 = { + .get_entry = sart4_get_entry, + .set_entry = sart4_set_entry, + .flags_allow = APPLE_SART4_FLAGS_ALLOW, + .size_shift = APPLE_SART4_SIZE_SHIFT, + .paddr_shift = APPLE_SART4_PADDR_SHIFT, + .size_max = APPLE_SART4_SIZE_MAX, +}; + static int apple_sart_probe(struct platform_device *pdev) { int i; @@ -372,6 +412,10 @@ static void apple_sart_shutdown(struct platform_device *pdev) } static const struct of_device_id apple_sart_of_match[] = { + { + .compatible = "apple,t6050-sart", + .data = &sart_ops_v4, + }, { .compatible = "apple,t6000-sart", .data = &sart_ops_v3,