Skip to content

pwm: Add new pwm driver for ARM Macs#57

Closed
WhatAmISupposedToPutHere wants to merge 278 commits into
AsahiLinux:asahi-wipfrom
WhatAmISupposedToPutHere:asahi
Closed

pwm: Add new pwm driver for ARM Macs#57
WhatAmISupposedToPutHere wants to merge 278 commits into
AsahiLinux:asahi-wipfrom
WhatAmISupposedToPutHere:asahi

Conversation

@WhatAmISupposedToPutHere
Copy link
Copy Markdown
Member

Arm macs have a PWM controller that is hooked up to the keyboard backlight. This patch adds the controller driver and device tree bindings using pwm-leds.

Comment thread drivers/pwm/pwm-apple.c Outdated
Comment thread Documentation/devicetree/bindings/pwm/pwm-apple.yaml Outdated
Comment thread drivers/pwm/pwm-apple.c Outdated
Comment thread drivers/pwm/pwm-apple.c Outdated
Copy link
Copy Markdown
Member

@jannau jannau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks overall good, left some small remarks as commits. Tested on j493 (M2 Macbook pro 13") against asahi-wip

Please split the commit into multiple commits. A good split would be

  1. dt-bindings
  2. PWM driver
  3. dts changes (probably best splitted into 3 commits for t8103, t600x and t8110)

It misses a MAINTAINER update. Upstream wants that in the commit with the driver but @marcan prefers it as separate commit to make rebasing simpler

Comment thread Documentation/devicetree/bindings/pwm/pwm-apple.yaml Outdated
Comment thread Documentation/devicetree/bindings/pwm/pwm-apple.yaml Outdated
Comment thread Documentation/devicetree/bindings/pwm/pwm-apple.yaml Outdated
Comment thread arch/arm64/boot/dts/apple/t8103.dtsi Outdated
Comment thread drivers/pwm/pwm-apple.c
Comment thread drivers/pwm/pwm-apple.c Outdated
Comment thread drivers/pwm/pwm-apple.c Outdated
Comment thread Documentation/devicetree/bindings/pwm/pwm-apple.yaml Outdated
Copy link
Copy Markdown

@marcan marcan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks generally good, just a few comments. You also need to sign off your commits for upstreaming (the DCO bot tells you how).

Comment thread drivers/pwm/pwm-apple.c Outdated
Comment thread drivers/pwm/pwm-apple.c Outdated
Comment thread Documentation/devicetree/bindings/pwm/pwm-apple.yaml
povik and others added 12 commits October 24, 2022 19:04
Signed-off-by: Martin Povišer <povik+lin@cutebit.org>
Even though my preference would be to keep it in, the long name crops in
a bunch of places and the verbiage at the end needs to go.

Signed-off-by: Martin Povišer <povik+lin@cutebit.org>
Signed-off-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Hector Martin <marcan@marcan.st>
Signed-off-by: Hector Martin <marcan@marcan.st>
The Mac Studio M1 Max (t6001) model has a built-in USB3 hub. This hub
has a firmware flash which is also connected to an AP SPI controller.
The hub starts out in reset and the host is expected to bring it out of
reset, potentially after upgrading/validating the firmware.

We won't be doing anything with the firmware, so just use gpio-hog to
flip the two GPIOs needed to bring up the hub chip.

Signed-off-by: Hector Martin <marcan@marcan.st>
Values were determined using the microjoule counters
found in the Firestorm and Icestorm cores. Includes
core cluster static power.

Signed-off-by: James Calligeros <jcalligeros99@gmail.com>
Since the cores are identical across the M1 range, their power
consumption should be too. Use the experimentally-derived power
consumption values from t600x to enable EAS on t8103.

Signed-off-by: James Calligeros <jcalligeros99@gmail.com>
The dcp co-processor crashes on HDMI unplug while it apparently tries
to notify pmp. Handle "notify_pmp" as a parent dependency for
"ps_disp0_fe" and "ps_dispext_fe".

Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Janne Grunau <j@jannau.net>
The display system is initialized by the bootloader to provide a simple
framebuffer at startup. Memory for the framebuffer and heap for the
display co-processor are alreay mapped through the IOMMU. IOMMU
intialization must preserve this mappings to avoid crashing the display
co-processor. The exisitng mappings are caried in the devicetree. They
are applied during device attach to ensure the IOMMU framework is aware
of these mapping.

Mappings are filled by m1n1 during boot.

Based on https://lore.kernel.org/asahi/20220923123557.866972-1-thierry.reding@gmail.com

Signed-off-by: Janne Grunau <j@jannau.net>
… nodes

The display system is initialized by the bootloader to provide a simple
framebuffer at startup. Memory for the framebuffer and heap for the
display co-processor are alreay mapped through the IOMMU. IOMMU
intialization must preserve this mappings to avoid crashing the display
co-processor. The exisitng mappings are caried in the devicetree. They
are applied during device attach to ensure the IOMMU framework is aware
of these mapping.

Mappings are filled by m1n1 during boot.

Based on https://lore.kernel.org/asahi/20220923123557.866972-1-thierry.reding@gmail.com

Signed-off-by: Janne Grunau <j@jannau.net>
Adds the Apple PWM controller driver.

Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com>
Adds PWM controller and keyboard backlight bindings for M1 Pro/Max MacBook Pros

Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com>
Adds PWM controller and keyboard backlight bindings for M2 MacBooks

Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com>
Adds PWM controller and keyboard backlight bindings for M1 MacBooks

Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com>
Add the MAINTAINERS entries for the driver

Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com>
@WhatAmISupposedToPutHere
Copy link
Copy Markdown
Member Author

this was merged

marcan pushed a commit that referenced this pull request Jan 19, 2024
We need to probe for IOCP only once during boot stage, as we were probing
for IOCP for all the stages this caused the below issue during module-init
stage,

[9.019104] Unable to handle kernel paging request at virtual address ffffffff8100d3a0
[9.027153] Oops [#1]
[9.029421] Modules linked in: rcar_canfd renesas_usbhs i2c_riic can_dev spi_rspi i2c_core
[9.037686] CPU: 0 PID: 90 Comm: udevd Not tainted 6.7.0-rc1+ #57
[9.043756] Hardware name: Renesas SMARC EVK based on r9a07g043f01 (DT)
[9.050339] epc : riscv_noncoherent_supported+0x10/0x3e
[9.055558]  ra : andes_errata_patch_func+0x4a/0x52
[9.060418] epc : ffffffff8000d8c2 ra : ffffffff8000d95c sp : ffffffc8003abb00
[9.067607]  gp : ffffffff814e25a0 tp : ffffffd80361e540 t0 : 0000000000000000
[9.074795]  t1 : 000000000900031e t2 : 0000000000000001 s0 : ffffffc8003abb20
[9.081984]  s1 : ffffffff015b57c7 a0 : 0000000000000000 a1 : 0000000000000001
[9.089172]  a2 : 0000000000000000 a3 : 0000000000000000 a4 : ffffffff8100d8be
[9.096360]  a5 : 0000000000000001 a6 : 0000000000000001 a7 : 000000000900031e
[9.103548]  s2 : ffffffff015b57d7 s3 : 0000000000000001 s4 : 000000000000031e
[9.110736]  s5 : 8000000000008a45 s6 : 0000000000000500 s7 : 000000000000003f
[9.117924]  s8 : ffffffc8003abd48 s9 : ffffffff015b1140 s10: ffffffff8151a1b0
[9.125113]  s11: ffffffff015b1000 t3 : 0000000000000001 t4 : fefefefefefefeff
[9.132301]  t5 : ffffffff015b57c7 t6 : ffffffd8b63a6000
[9.137587] status: 0000000200000120 badaddr: ffffffff8100d3a0 cause: 000000000000000f
[9.145468] [<ffffffff8000d8c2>] riscv_noncoherent_supported+0x10/0x3e
[9.151972] [<ffffffff800027e8>] _apply_alternatives+0x84/0x86
[9.157784] [<ffffffff800029be>] apply_module_alternatives+0x10/0x1a
[9.164113] [<ffffffff80008fcc>] module_finalize+0x5e/0x7a
[9.169583] [<ffffffff80085cd6>] load_module+0xfd8/0x179c
[9.174965] [<ffffffff80086630>] init_module_from_file+0x76/0xaa
[9.180948] [<ffffffff800867f6>] __riscv_sys_finit_module+0x176/0x2a8
[9.187365] [<ffffffff80889862>] do_trap_ecall_u+0xbe/0x130
[9.192922] [<ffffffff808920bc>] ret_from_exception+0x0/0x64
[9.198573] Code: 0009 b7e9 6797 014d a783 85a7 c799 4785 0717 0100 (0123) aef7
[9.205994] ---[ end trace 0000000000000000 ]---

This is because we called riscv_noncoherent_supported() for all the stages
during IOCP probe. riscv_noncoherent_supported() function sets
noncoherent_supported variable to true which has an annotation set to
"__ro_after_init" due to which we were seeing the above splat. Fix this by
probing for IOCP only once in boot stage by having a boolean variable
"done" which will be set to true upon IOCP probe in errata_probe_iocp()
and we bail out early if "done" is set to true.

While at it make return type of errata_probe_iocp() to void as we were
not checking the return value in andes_errata_patch_func().

Fixes: e021ae7 ("riscv: errata: Add Andes alternative ports")
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Yu Chien Peter Lin <peterlin@andestech.com>
Link: https://lore.kernel.org/r/20231130212647.108746-1-prabhakar.mahadev-lad.rj@bp.renesas.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
jannau pushed a commit that referenced this pull request May 5, 2024
[ Upstream commit f221033 ]

During the removal of the idxd driver, registered offline callback is
invoked as part of the clean up process. However, on systems with only
one CPU online, no valid target is available to migrate the
perf context, resulting in a kernel oops:

    BUG: unable to handle page fault for address: 000000000002a2b8
    #PF: supervisor write access in kernel mode
    #PF: error_code(0x0002) - not-present page
    PGD 1470e1067 P4D 0
    Oops: 0002 [#1] PREEMPT SMP NOPTI
    CPU: 0 PID: 20 Comm: cpuhp/0 Not tainted 6.8.0-rc6-dsa+ #57
    Hardware name: Intel Corporation AvenueCity/AvenueCity, BIOS BHSDCRB1.86B.2492.D03.2307181620 07/18/2023
    RIP: 0010:mutex_lock+0x2e/0x50
    ...
    Call Trace:
    <TASK>
    __die+0x24/0x70
    page_fault_oops+0x82/0x160
    do_user_addr_fault+0x65/0x6b0
    __pfx___rdmsr_safe_on_cpu+0x10/0x10
    exc_page_fault+0x7d/0x170
    asm_exc_page_fault+0x26/0x30
    mutex_lock+0x2e/0x50
    mutex_lock+0x1e/0x50
    perf_pmu_migrate_context+0x87/0x1f0
    perf_event_cpu_offline+0x76/0x90 [idxd]
    cpuhp_invoke_callback+0xa2/0x4f0
    __pfx_perf_event_cpu_offline+0x10/0x10 [idxd]
    cpuhp_thread_fun+0x98/0x150
    smpboot_thread_fn+0x27/0x260
    smpboot_thread_fn+0x1af/0x260
    __pfx_smpboot_thread_fn+0x10/0x10
    kthread+0x103/0x140
    __pfx_kthread+0x10/0x10
    ret_from_fork+0x31/0x50
    __pfx_kthread+0x10/0x10
    ret_from_fork_asm+0x1b/0x30
    <TASK>

Fix the issue by preventing the migration of the perf context to an
invalid target.

Fixes: 81dd4d4 ("dmaengine: idxd: Add IDXD performance monitor support")
Reported-by: Terrence Xu <terrence.xu@intel.com>
Tested-by: Terrence Xu <terrence.xu@intel.com>
Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
Link: https://lore.kernel.org/r/20240313214031.1658045-1-fenghua.yu@intel.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
asdfugil pushed a commit to HoolockLinux/linux that referenced this pull request Jun 3, 2026
Prevent a crash from happening as the first serial port is initialised:

  Console: switching to mono frame buffer device 160x64
  fb0: PMAG-AA frame buffer device at tc0
  DECstation Z85C30 serial driver version 0.10
  CPU 0 Unable to handle kernel paging request at virtual address 0000002c, epc == 803ab00c, ra == 803aafe0
  Oops[#1]:
  CPU: 0 PID: 1 Comm: swapper Not tainted 6.4.0-rc3-00031-g84a9582fd203-dirty AsahiLinux#57
  $ 0   : 00000000 10012c00 803aaeb0 00000000
  $ 4   : 80e12f60 80e12f50 80e12f58 81000030
  $ 8   : 00000000 805ff37c 00000000 33433538
  $12   : 65732030 00000006 80c2915d 6c616972
  $16   : 80e12f00 807b7630 00000000 00000000
  $20   : 00000004 00000348 000001a0 807623b8
  $24   : 00000018 00000000
  $28   : 80c24000 80c25d6 8078b148 803aafe0
  Hi    : 00000000
  Lo    : 00000000
  epc   : 803ab00c serial_base_ctrl_add+0x78/0xf4
  ra    : 803aafe0 serial_base_ctrl_add+0x4c/0xf4
  Status: 10012c0	KERNEL EXL IE
  Cause : 00000008 (ExcCode 02)
  BadVA : 0000002c
  PrId  : 00000440 (R4400SC)
  Modules linked in:
  Process swapper (pid: 1, threadinfo=(ptrval), task=(ptrval), tls=00000000)
  Stack : 80760000 00000cc0 00400044 00400040 803aa02c 80d61ab8 00000000 807b7630
          80760000 807623b8 807b7628 803aa644 80386998 00000000 80e17780 80220f68
          80e17780 80d61ab8 80c17d80 80e17780 80e17780 8063c798 80e17780 80383fa0
          00000010 80e17780 00000000 80386998 807a0000 00000000 00400040 8038f848
          807623b8 80d61ab8 00000004 80e17780 00000000 803a68e4 80c25e2c 803bb884
          ...
  Call Trace:
  [<803ab00c>] serial_base_ctrl_add+0x78/0xf4
  [<803aa644>] serial_core_register_port+0x174/0x69c
  [<8077e9ac>] zs_init+0xc8/0xfc
  [<800404d4>] do_one_initcall+0x40/0x2ac
  [<8076cecc>] kernel_init_freeable+0x1e4/0x270
  [<80605bec>] kernel_init+0x20/0x108
  [<800431e8>] ret_from_kernel_thread+0x14/0x1c

  Code: 2442aeb  ae120024  ae0200d0 <8c67002c> 50e00001  8c670000  3c06806  3c05806e  afb30010

  ---[ end trace 0000000000000000 ]---

(report at the offending commit) -- where a pointer is dereferenced that
has been derived from a null pointer to the port's parent device.

Since no device is available with legacy probing and it's not anymore a
preferable way to discover devices anyway, switch the driver to using a
platform device and use it as the port's parent device.  Update resource
handling accordingly and only request the actual span of addresses used
within the slot, which will have had its resource already requested by
generic platform device code.

Use platform_driver_probe() not just because SCC devices are fixed with
solder on board and not straightforward to remove, but foremost because
the associated TTY's major device number is the same as used by the dz
driver and the first driver to claim it will prevent the other one from
using it.  Either one DZ device or some SCC devices will be present in a
given system but never both at a time, and therefore we want the major
device number to be claimed by the first driver to actually successfully
bind to its device and platform_driver_probe() is a way to fulfil that.

An unfortunate consequence of the switch to a platform device is we now
hand the console over from the bootconsole much later in the bootstrap.
The firmware console handler appears good enough though to work so late
and in particular with interrupts enabled.

Since there is one way only remaining to reach zs_reset() now, remove
the port initialisation marker as no longer needed and go through the
channel reset unconditionally.

Fixes: 84a9582 ("serial: core: Start managing serial controllers to enable runtime PM")
Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
Cc: stable@vger.kernel.org # needs to use .remove_new for <= 6.10
Link: https://patch.msgid.link/alpine.DEB.2.21.2605062328480.46195@angie.orcam.me.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.