Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions arch/arm64/boot/dts/apple/t6020-j474s.dts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
/ {
compatible = "apple,j474s", "apple,t6020", "apple,arm-platform";
model = "Apple Mac mini (M2 Pro, 2023)";

aliases {
sep = &sep;
};
};

/* PCIe devices */
Expand Down
4 changes: 4 additions & 0 deletions arch/arm64/boot/dts/apple/t6021-j475c.dts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
/ {
compatible = "apple,j475c", "apple,t6021", "apple,arm-platform";
model = "Apple Mac Studio (M2 Max, 2023)";

aliases {
sep = &sep;
};
};

&wifi0 {
Expand Down
9 changes: 9 additions & 0 deletions arch/arm64/boot/dts/apple/t602x-die0.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,15 @@
status = "disabled";
};

/*
* Disabled here on every board by design. The SEP is already
* running when Linux starts (warm attach: one shared-memory
* registration, no cold boot), so apple_sep enables this node
* and sep_dart with a changeset at module load, once it has
* picked this SoC's profile and before the DART probes. A
* board with the enclave only needs the sep alias, which m1n1
* uses to add the sepfw region and the boot manifests.
*/
sep: sep@396400000 {
compatible = "apple,sep";
reg = <0x3 0x96400000 0x0 0x6C000>;
Expand Down
1 change: 1 addition & 0 deletions arch/arm64/boot/dts/apple/t8112-j473.dts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
ethernet0 = &ethernet0;
rtc0 = &smc_rtc;
rtc1 = &pmu_rtc;
sep = &sep;
wifi0 = &wifi0;
};
};
Expand Down
9 changes: 9 additions & 0 deletions arch/arm64/boot/dts/apple/t8112.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,15 @@
status = "disabled";
};

/*
* Disabled here on every board by design. The SEP is already
* running when Linux starts (warm attach: one shared-memory
* registration, no cold boot), so apple_sep enables this node
* and sep_dart with a changeset at module load, once it has
* picked this SoC's profile and before the DART probes. A
* board with the enclave only needs the sep alias, which m1n1
* uses to add the sepfw region and the boot manifests.
*/
sep: sep@25e400000 {
compatible = "apple,sep";
reg = <0x2 0x5e400000 0x0 0x6C000>;
Expand Down
3 changes: 0 additions & 3 deletions drivers/soc/apple/sensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ impl CsTiming {
pub(crate) enum PowerSource {
None,
NodeProperty,
ChipLine,
/// Rails switched by the SMC on J700.
SmcRails,
}
Expand All @@ -100,7 +99,6 @@ impl PowerSource {
fn from_wire(v: c_int) -> PowerSource {
match v {
1 => PowerSource::NodeProperty,
2 => PowerSource::ChipLine,
3 => PowerSource::SmcRails,
_ => PowerSource::None,
}
Expand All @@ -110,7 +108,6 @@ impl PowerSource {
match self {
PowerSource::None => c"none — no power line was taken",
PowerSource::NodeProperty => c"the sensor node's own gpios property",
PowerSource::ChipLine => c"/soc/pinctrl@39b028000 line 122, taken by device-tree node",
PowerSource::SmcRails => c"the sensor node's SMC-switched rails (apple,smc-power-key)",
}
}
Expand Down
135 changes: 12 additions & 123 deletions drivers/soc/apple/sensor_shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include <linux/device.h>
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
#include <linux/gpio/driver.h>
#include <linux/gpio/machine.h>
#include <linux/interrupt.h>
#include <linux/mfd/macsmc.h>
#include <linux/of.h>
Expand Down Expand Up @@ -78,16 +76,9 @@ static struct spi_device *sep_spi;
static struct gpio_desc *sep_power;
static bool sep_registered;

/*
* Power line resolved by DT node path, not gpiochip index: registration order
* shifts, so an index would silently pick the wrong chip.
*/
#define SEP_SENSOR_GPIO_NODE "/soc/pinctrl@39b028000"
#define SEP_SENSOR_GPIO_LINE 122

/* Wire values shared with sensor.rs (PowerSource::from_wire). */
#define SEP_POWER_NONE 0
#define SEP_POWER_NODE_PROPERTY 1
#define SEP_POWER_CHIP_LINE 2
#define SEP_POWER_SMC_RAILS 3

static int sep_power_source;
Expand All @@ -102,12 +93,9 @@ static u32 sep_smc_rails[SEP_SMC_MAX_RAILS];
static int sep_smc_nrails;

/*
* Data-ready line for interrupt-driven capture. On j414s it is the pin adjacent
* to the power line (122) on the same controller; other boards describe it as
* the SPI node's interrupt, which the SPI core resolves into spi->irq.
* Data-ready line for interrupt-driven capture: the SPI node's interrupt, which
* the SPI core resolves into spi->irq.
*/
#define SEP_SENSOR_DRDY_LINE 121
static struct gpio_desc *sep_drdy; /* set only when we own the gpiochip line (j414s) */
static int sep_drdy_irq = -1;
static DECLARE_COMPLETION(sep_drdy_done);

Expand Down Expand Up @@ -244,10 +232,6 @@ static int sep_acquire_smc_power(struct spi_device *spi)
*/
static int sep_acquire_power(struct spi_device *spi)
{
struct device_node *np;
struct gpio_device *gdev;
struct gpio_chip *gc;

if (spi->dev.of_node &&
of_property_present(spi->dev.of_node, "apple,smc-power-key"))
return sep_acquire_smc_power(spi);
Expand All @@ -269,58 +253,9 @@ static int sep_acquire_power(struct spi_device *spi)
}
sep_power = NULL;

/*
* The fallback below is the j414s power line; a sibling board's sensor sits
* on a different pin, so only j414s may use it. Every other machine must
* describe enable-gpios in its device node.
*/
if (!of_machine_is_compatible("apple,j414s")) {
dev_warn(&spi->dev,
"sep sensor: no power GPIO in the device node; describe enable-gpios in DT\n");
return -ENODEV;
}

np = of_find_node_by_path(SEP_SENSOR_GPIO_NODE);
if (!np) {
dev_warn(&spi->dev,
"sep sensor: no DT node at %s, no power line\n",
SEP_SENSOR_GPIO_NODE);
return -ENODEV;
}

gdev = gpio_device_find_by_fwnode(of_fwnode_handle(np));
of_node_put(np);
if (!gdev) {
dev_warn(&spi->dev,
"sep sensor: %s has no registered GPIO device\n",
SEP_SENSOR_GPIO_NODE);
return -EPROBE_DEFER;
}

gc = gpio_device_get_chip(gdev);
if (gc)
sep_power = gpiochip_request_own_desc(gc,
SEP_SENSOR_GPIO_LINE,
"apple-mesa-power",
GPIO_LOOKUP_FLAGS_DEFAULT,
GPIOD_OUT_LOW);
if (!gc || IS_ERR(sep_power)) {
sep_power = NULL;
dev_warn(&spi->dev,
"sep sensor: could not take line %d on %s (%s)\n",
SEP_SENSOR_GPIO_LINE, SEP_SENSOR_GPIO_NODE,
gpio_device_get_label(gdev));
gpio_device_put(gdev);
return -ENODEV;
}

sep_power_source = SEP_POWER_CHIP_LINE;
dev_info(&spi->dev,
"sep sensor: power line %s line %d (%s), driven low\n",
SEP_SENSOR_GPIO_NODE, SEP_SENSOR_GPIO_LINE,
gpio_device_get_label(gdev));
gpio_device_put(gdev);
return 0;
dev_warn(&spi->dev,
"sep sensor: no power GPIO in the device node; describe enable-gpios in DT\n");
return -ENODEV;
}

static void sep_release_power(void)
Expand All @@ -335,10 +270,7 @@ static void sep_release_power(void)
if (!sep_power)
return;
gpiod_set_value_cansleep(sep_power, 0);
if (sep_power_source == SEP_POWER_CHIP_LINE)
gpiochip_free_own_desc(sep_power);
else
gpiod_put(sep_power);
gpiod_put(sep_power);
sep_power = NULL;
sep_power_source = SEP_POWER_NONE;
}
Expand Down Expand Up @@ -633,7 +565,7 @@ static int sep_sensor_power_cycle_locked(struct sep_sensor_lifetime *sensor)
return 0;
}

/* How the power line was obtained: none, the node's property, or chip+line. */
/* How the power line was obtained: none, the node's property, or SMC rails. */
static int sep_sensor_power_source_locked(void)
{
return sep_power_source;
Expand Down Expand Up @@ -699,51 +631,17 @@ static irqreturn_t sep_drdy_isr(int irq, void *dev_id)
*/
static int sep_sensor_irq_setup_locked(void)
{
struct device_node *np;
struct gpio_device *gdev;
struct gpio_chip *gc;
int irq, rc;

if (!sep_spi)
return -ENODEV;
if (sep_drdy_irq >= 0)
return 0;

if (sep_spi->irq > 0) {
/* A board that describes the data-ready line as the SPI node's
* interrupt gets it resolved by the SPI core. */
irq = sep_spi->irq;
} else if (of_machine_is_compatible("apple,j414s")) {
np = of_find_node_by_path(SEP_SENSOR_GPIO_NODE);
if (!np)
return -ENODEV;
gdev = gpio_device_find_by_fwnode(of_fwnode_handle(np));
of_node_put(np);
if (!gdev)
return -ENODEV;
gc = gpio_device_get_chip(gdev);
if (!gc) {
gpio_device_put(gdev);
return -ENODEV;
}
sep_drdy = gpiochip_request_own_desc(gc, SEP_SENSOR_DRDY_LINE,
"apple-mesa-drdy",
GPIO_LOOKUP_FLAGS_DEFAULT,
GPIOD_IN);
gpio_device_put(gdev);
if (IS_ERR(sep_drdy)) {
sep_drdy = NULL;
return -ENODEV;
}
irq = gpiod_to_irq(sep_drdy);
if (irq < 0) {
gpiochip_free_own_desc(sep_drdy);
sep_drdy = NULL;
return irq;
}
} else {
/* The board describes the data-ready line as the SPI node's interrupt. */
if (sep_spi->irq <= 0)
return -ENODEV;
}
irq = sep_spi->irq;

init_completion(&sep_drdy_done);
/*
Expand All @@ -756,13 +654,8 @@ static int sep_sensor_irq_setup_locked(void)
rc = request_threaded_irq(irq, NULL, sep_drdy_isr,
IRQF_ONESHOT | IRQF_TRIGGER_RISING,
"apple-mesa-drdy", sep_spi);
if (rc) {
if (sep_drdy) {
gpiochip_free_own_desc(sep_drdy);
sep_drdy = NULL;
}
if (rc)
return rc;
}
sep_drdy_irq = irq;
dev_info(&sep_spi->dev,
"sep sensor: data-ready IRQ %d configured for interrupt capture\n",
Expand All @@ -776,10 +669,6 @@ static void sep_sensor_irq_teardown_locked(void)
free_irq(sep_drdy_irq, sep_spi);
sep_drdy_irq = -1;
}
if (sep_drdy) {
gpiochip_free_own_desc(sep_drdy);
sep_drdy = NULL;
}
}

static int sep_sensor_irq_available_locked(void)
Expand Down
Loading