Skip to content
Merged
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
19 changes: 11 additions & 8 deletions Documentation/devicetree/bindings/usb/apple,sn201202x.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ description: |

The controller can be polled when interrupt resources are not supplied.

T8132 omits the register-selection interrupt, so selection is polled while
event, standby and wakeup notifications use interrupts. The T8152
controllers work as the T8132 ones do: no register-selection interrupt, and
the payload length of a selected register in register 0x1f.
Controllers that omit the register-selection interrupt poll register
selection and read the payload length of a selected register from register
0x1f, while event, standby and wakeup notifications use interrupts. Legacy
device trees also carry `apple,t8132-sn201202x` or `apple,t8152-sn201202x`
compatibles for those controllers.

properties:
compatible:
Expand Down Expand Up @@ -129,34 +130,36 @@ required:

allOf:
- if:
required:
- interrupt-names
properties:
compatible:
interrupt-names:
contains:
const: apple,t8132-sn201202x
const: select
then:
properties:
interrupts:
items:
- description: Primary irq used for tps6598x events
- description: Logical register selection completed
- description: Standby command completed
- description: Wakeup command completed
interrupt-names:
items:
- const: irq
- const: select
- const: sleep
- const: wake
else:
properties:
interrupts:
items:
- description: Primary irq used for tps6598x events
- description: Logical register selection completed
- description: Standby command completed
- description: Wakeup command completed
interrupt-names:
items:
- const: irq
- const: select
- const: sleep
- const: wake

Expand Down
11 changes: 8 additions & 3 deletions arch/arm64/boot/dts/apple/t6050-die0.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,17 @@
};

/*
* /arm-io/nub-spmi-a0: reg[0] 0x8a188000, generation 4, a bus of the USB-C PD controllers
* (HPMs, the board's). They are polled (no interrupts), so the bus needs none either.
* /arm-io/nub-spmi-a0: reg[0] 0x8a188000, reg[1] 0x8a184000 (fault queue), generation 4,
* interrupt 761, a bus of the USB-C PD controllers (HPMs, the board's).
*/
nub_spmi_a0: spmi@28a188000 {
compatible = "apple,t6050-spmi", "apple,t8142-spmi";
reg = <0x2 0x8a188000 0x0 0x4000>;
reg = <0x2 0x8a188000 0x0 0x4000>,
<0x2 0x8a184000 0x0 0x4000>;
interrupt-controller;
#interrupt-cells = <2>;
interrupt-parent = <&aic>;
interrupts = <AIC_IRQ 0 761 IRQ_TYPE_LEVEL_HIGH>;
#address-cells = <2>;
#size-cells = <0>;
};
Expand Down
40 changes: 38 additions & 2 deletions arch/arm64/boot/dts/apple/t6050-j716c.dts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
};
};

/* ATC1, ATC3 and the PD controller buses nub-spmi-a0 and -a2: not yet described for this board */
/* ATC1, ATC3 and the PD controller bus nub-spmi-a2: not yet described for this board */
&nub_spmi_a0 {
status = "disabled";
};
Expand Down Expand Up @@ -205,6 +205,26 @@
apple,fan-mode = "F1md";
apple,fan-manual-control;
};

power-PSTR {
apple,key-id = "PSTR";
label = "Total System Power";
};

power-PHPC {
apple,key-id = "PHPC";
label = "Heatpipe Power";
};

power-PDTR {
apple,key-id = "PDTR";
label = "AC Input Power";
};

voltage-SBAV {
apple,key-id = "SBAV";
label = "Battery Voltage";
};
};

/*
Expand Down Expand Up @@ -334,19 +354,35 @@
*/
#include "t6050-j714s-ane.dtsi"

/* The port controllers follow the sleep's command rules (tipd: woken first, read at intervals) */
/* The port controllers follow the sleep's command rules and use SPMI event/sleep/wake IRQs. */
&hpm0 {
interrupts = <11 IRQ_TYPE_EDGE_RISING>,
<17 IRQ_TYPE_EDGE_RISING>,
<19 IRQ_TYPE_EDGE_RISING>;
interrupt-names = "irq", "sleep", "wake";
apple,sleep-ssps-rules;
};

&hpm1 {
interrupts = <37 IRQ_TYPE_EDGE_RISING>,
<43 IRQ_TYPE_EDGE_RISING>,
<45 IRQ_TYPE_EDGE_RISING>;
interrupt-names = "irq", "sleep", "wake";
apple,sleep-ssps-rules;
};

&hpm2 {
interrupts = <11 IRQ_TYPE_EDGE_RISING>,
<17 IRQ_TYPE_EDGE_RISING>,
<19 IRQ_TYPE_EDGE_RISING>;
interrupt-names = "irq", "sleep", "wake";
apple,sleep-ssps-rules;
};

&hpm5 {
interrupts = <63 IRQ_TYPE_EDGE_RISING>,
<69 IRQ_TYPE_EDGE_RISING>,
<71 IRQ_TYPE_EDGE_RISING>;
interrupt-names = "irq", "sleep", "wake";
apple,sleep-ssps-rules;
};
13 changes: 9 additions & 4 deletions arch/arm64/boot/dts/apple/t6050-j716s.dts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,18 @@
/* A block t6050-die0.dtsi does not describe yet: the third HPM bus */
&die0 {
/*
* ADT nub-spmi-a1, the right-hand port's HPM bus (hpm2). Polled like a0:
* the generation 4 driver takes no interrupt. pmgr NUB_SPMI_A1 is
* critical, as NUB_SPMI_A0, so no power-domains.
* ADT nub-spmi-a1, the right-hand port's HPM bus (hpm2), with its fault-queue
* window and AIC 763 interrupt. pmgr NUB_SPMI_A1 is critical, as NUB_SPMI_A0, so
* no power-domains.
*/
nub_spmi_a1: spmi@28a1a8000 {
compatible = "apple,t6050-spmi", "apple,t8142-spmi";
reg = <0x2 0x8a1a8000 0x0 0x4000>;
reg = <0x2 0x8a1a8000 0x0 0x4000>,
<0x2 0x8a1a4000 0x0 0x4000>;
interrupt-controller;
#interrupt-cells = <2>;
interrupt-parent = <&aic>;
interrupts = <AIC_IRQ 0 763 IRQ_TYPE_LEVEL_HIGH>;
#address-cells = <2>;
#size-cells = <0>;
};
Expand Down
11 changes: 8 additions & 3 deletions arch/arm64/boot/dts/apple/t6050-max.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,17 @@

#if defined(T6050_J714C) || defined(T6050_J716C)
/*
* /arm-io/nub-spmi-a1: reg[0] 0x8a1a8000, generation 4, a bus of USB-C PD controllers (the
* board's). They are polled, as on nub-spmi-a0, so the bus takes no interrupt.
* /arm-io/nub-spmi-a1: reg[0] 0x8a1a8000, reg[1] 0x8a1a4000 (fault queue), generation 4,
* interrupt 763, a bus of USB-C PD controllers (the board's).
*/
nub_spmi_a1: spmi@28a1a8000 {
compatible = "apple,t6050-spmi", "apple,t8142-spmi";
reg = <0x2 0x8a1a8000 0x0 0x4000>;
reg = <0x2 0x8a1a8000 0x0 0x4000>,
<0x2 0x8a1a4000 0x0 0x4000>;
interrupt-controller;
#interrupt-cells = <2>;
interrupt-parent = <&aic>;
interrupts = <AIC_IRQ 0 763 IRQ_TYPE_LEVEL_HIGH>;
#address-cells = <2>;
#size-cells = <0>;
};
Expand Down
3 changes: 3 additions & 0 deletions arch/arm64/boot/dts/apple/t6050-peripherals.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,9 @@
reg = <0x2 0x8a1a8000 0x0 0x4000>,
<0x2 0x8a1a4000 0x0 0x4000>,
<0x2 0x8a1a0000 0x0 0x4000>;
interrupt-controller;
#interrupt-cells = <2>;
interrupt-parent = <&aic>;
interrupts = <AIC_IRQ 0 763 IRQ_TYPE_LEVEL_HIGH>;
#address-cells = <2>;
#size-cells = <0>;
Expand Down
146 changes: 146 additions & 0 deletions drivers/usb/typec/tipd/sn201202x-pm-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
*/

#include <kunit/device.h>
#include <kunit/of.h>
#include <kunit/test.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/irqdomain.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/pm_runtime.h>
#include <linux/pm_wakeup.h>
#include <linux/regmap.h>
Expand Down Expand Up @@ -1032,6 +1035,148 @@ static void sn201202x_ldcm_stop_requeue_test(struct kunit *test)
KUNIT_EXPECT_FALSE(test, delayed_work_pending(&t->sn.ldcm_work));
}

#ifdef CONFIG_OF_DYNAMIC
static void sn201202x_test_changeset_cleanup(void *data)
{
struct of_changeset *cs = data;

of_changeset_revert(cs);
of_changeset_destroy(cs);
}

static void sn201202x_test_irq_domain_remove(void *data)
{
irq_domain_remove(data);
}
#endif

static void sn201202x_select_irq_test(struct kunit *test)
{
#ifndef CONFIG_OF_DYNAMIC
kunit_skip(test, "requires CONFIG_OF_DYNAMIC");
#else
static const char * const names_3irq[] = { "irq", "sleep", "wake" };
static const char * const names_4irq[] = { "irq", "select", "sleep", "wake" };
static const u32 irqs_3irq[] = { 1, 0, 2, 0, 3, 0 };
static const u32 irqs_4irq[] = { 1, 0, 2, 0, 3, 0, 4, 0 };
static const u32 irqs_bad_phandle[] = {
0xffffffff, 0, 0xffffffff, 1, 0xffffffff, 2, 0xffffffff, 3,
};
static const u32 irqs_trunc[] = { 1, 0 };
struct device_node *ic, *polled_3irq, *bad_spec, *trunc_spec, *valid_4irq;
struct of_changeset *cs;
struct irq_domain *domain;
bool select_polled;
int ret;

if (!of_root)
kunit_skip(test, "requires a device tree");

cs = kunit_kzalloc(test, sizeof(*cs), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, cs);
of_changeset_init(cs);

ic = of_changeset_create_node(cs, of_root, "sn201202x-irq-test");
KUNIT_ASSERT_NOT_NULL(test, ic);
KUNIT_ASSERT_EQ(test, of_changeset_add_prop_bool(cs, ic, "interrupt-controller"), 0);
KUNIT_ASSERT_EQ(test, of_changeset_add_prop_u32(cs, ic, "#interrupt-cells", 2), 0);

polled_3irq = of_changeset_create_node(cs, ic, "polled-select");
KUNIT_ASSERT_NOT_NULL(test, polled_3irq);
KUNIT_ASSERT_EQ(test, of_changeset_add_prop_string_array(cs, polled_3irq,
"interrupt-names",
names_3irq,
ARRAY_SIZE(names_3irq)), 0);
KUNIT_ASSERT_EQ(test, of_changeset_add_prop_u32_array(cs, polled_3irq,
"interrupts",
irqs_3irq,
ARRAY_SIZE(irqs_3irq)), 0);

bad_spec = of_changeset_create_node(cs, ic, "bad-select-spec");
KUNIT_ASSERT_NOT_NULL(test, bad_spec);
KUNIT_ASSERT_EQ(test, of_changeset_add_prop_string_array(cs, bad_spec,
"interrupt-names",
names_4irq,
ARRAY_SIZE(names_4irq)), 0);
KUNIT_ASSERT_EQ(test, of_changeset_add_prop_u32_array(cs, bad_spec,
"interrupts-extended",
irqs_bad_phandle,
ARRAY_SIZE(irqs_bad_phandle)), 0);

trunc_spec = of_changeset_create_node(cs, ic, "trunc-select-spec");
KUNIT_ASSERT_NOT_NULL(test, trunc_spec);
KUNIT_ASSERT_EQ(test, of_changeset_add_prop_string_array(cs, trunc_spec,
"interrupt-names",
names_4irq,
ARRAY_SIZE(names_4irq)), 0);
KUNIT_ASSERT_EQ(test, of_changeset_add_prop_u32_array(cs, trunc_spec,
"interrupts",
irqs_trunc,
ARRAY_SIZE(irqs_trunc)), 0);

valid_4irq = of_changeset_create_node(cs, ic, "valid-4irq");
KUNIT_ASSERT_NOT_NULL(test, valid_4irq);
KUNIT_ASSERT_EQ(test, of_changeset_add_prop_string_array(cs, valid_4irq,
"interrupt-names",
names_4irq,
ARRAY_SIZE(names_4irq)), 0);
KUNIT_ASSERT_EQ(test, of_changeset_add_prop_u32_array(cs, valid_4irq,
"interrupts",
irqs_4irq,
ARRAY_SIZE(irqs_4irq)), 0);

ret = of_changeset_apply(cs);
if (ret) {
of_node_put(valid_4irq);
of_node_put(trunc_spec);
of_node_put(bad_spec);
of_node_put(polled_3irq);
of_node_put(ic);
of_changeset_destroy(cs);
KUNIT_ASSERT_EQ(test, ret, 0);
}
KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, sn201202x_test_changeset_cleanup,
cs), 0);
of_node_put_kunit(test, ic);
of_node_put_kunit(test, polled_3irq);
of_node_put_kunit(test, bad_spec);
of_node_put_kunit(test, trunc_spec);
of_node_put_kunit(test, valid_4irq);

/* Absent "select" IRQ falls back to select-polled. */
select_polled = false;
KUNIT_EXPECT_EQ(test, sn201202x_select_irq_get(polled_3irq, &select_polled), 0);
KUNIT_EXPECT_TRUE(test, select_polled);

/* Declared "select" IRQ with unparseable specifier propagates -EINVAL. */
select_polled = true;
KUNIT_EXPECT_EQ(test, sn201202x_select_irq_get(bad_spec, &select_polled), -EINVAL);
KUNIT_EXPECT_FALSE(test, select_polled);

/* Declared "select" IRQ missing from interrupts array propagates -EOVERFLOW. */
select_polled = true;
KUNIT_EXPECT_EQ(test, sn201202x_select_irq_get(trunc_spec, &select_polled), -EOVERFLOW);
KUNIT_EXPECT_FALSE(test, select_polled);

/* Declared "select" IRQ without a registered domain propagates -EPROBE_DEFER. */
select_polled = true;
KUNIT_EXPECT_EQ(test, sn201202x_select_irq_get(valid_4irq, &select_polled), -EPROBE_DEFER);
KUNIT_EXPECT_FALSE(test, select_polled);

/* Declared "select" IRQ with a registered domain maps cleanly and disables polling. */
domain = irq_domain_create_linear(of_fwnode_handle(ic), 8, &irq_domain_simple_ops, NULL);
KUNIT_ASSERT_NOT_NULL(test, domain);
KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, sn201202x_test_irq_domain_remove,
domain), 0);
select_polled = true;
ret = sn201202x_select_irq_get(valid_4irq, &select_polled);
KUNIT_EXPECT_GT(test, ret, 0);
KUNIT_EXPECT_FALSE(test, select_polled);
if (ret > 0)
irq_dispose_mapping(ret);
#endif
}

static struct kunit_case sn201202x_pm_cases[] = {
KUNIT_CASE(sn201202x_sleep_cycle_test),
KUNIT_CASE(sn201202x_failed_wakeup_test),
Expand Down Expand Up @@ -1069,6 +1214,7 @@ static struct kunit_case sn201202x_pm_cases[] = {
KUNIT_CASE(sn201202x_sleep_from_idle_test),
KUNIT_CASE(sn201202x_sleep_from_idle_failed_wakeup_test),
KUNIT_CASE(sn201202x_watched_sleep_from_idle_test),
KUNIT_CASE(sn201202x_select_irq_test),
{}
};

Expand Down
Loading
Loading