From: Andreas Noever <andreas.noever@gmail.com>
To: linux-kernel@vger.kernel.org,
Matthew Garrett <matthew.garrett@nebula.com>,
Greg KH <greg@kroah.com>, Bjorn Helgaas <bhelgaas@google.com>,
linux-pci@vger.kernel.org
Cc: Andreas Noever <andreas.noever@gmail.com>
Subject: [PATCH v3 07/15] thunderbolt: Enable plug events
Date: Mon, 26 May 2014 17:18:04 +0200 [thread overview]
Message-ID: <1401117492-2870-8-git-send-email-andreas.noever@gmail.com> (raw)
In-Reply-To: <1401117492-2870-1-git-send-email-andreas.noever@gmail.com>
Thunderbolt switches have a plug events capability. This patch adds the
tb_plug_events_active method and uses it to activate plug events during
switch allocation.
Signed-off-by: Andreas Noever <andreas.noever@gmail.com>
---
drivers/thunderbolt/switch.c | 46 ++++++++++++++++++++++++++++++++++++++++++++
drivers/thunderbolt/tb.h | 1 +
2 files changed, 47 insertions(+)
diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
index e89121f..21457cc 100644
--- a/drivers/thunderbolt/switch.c
+++ b/drivers/thunderbolt/switch.c
@@ -99,6 +99,39 @@ static void tb_dump_switch(struct tb *tb, struct tb_regs_switch_header *sw)
}
/**
+ * tb_plug_events_active() - enable/disable plug events on a switch
+ *
+ * Also configures a sane plug_events_delay of 255ms.
+ *
+ * Return: Returns 0 on success or an error code on failure.
+ */
+static int tb_plug_events_active(struct tb_switch *sw, bool active)
+{
+ u32 data;
+ int res;
+
+ sw->config.plug_events_delay = 0xff;
+ res = tb_sw_write(sw, ((u32 *) &sw->config) + 4, TB_CFG_SWITCH, 4, 1);
+ if (res)
+ return res;
+
+ res = tb_sw_read(sw, &data, TB_CFG_SWITCH, sw->cap_plug_events + 1, 1);
+ if (res)
+ return res;
+
+ if (active) {
+ data = data & 0xFFFFFF83;
+ if (sw->config.device_id == 0x1547)
+ data |= 4;
+ } else {
+ data = data | 0x7c;
+ }
+ return tb_sw_write(sw, &data, TB_CFG_SWITCH,
+ sw->cap_plug_events + 1, 1);
+}
+
+
+/**
* tb_switch_free() - free a tb_switch and all downstream switches
*/
void tb_switch_free(struct tb_switch *sw)
@@ -113,6 +146,8 @@ void tb_switch_free(struct tb_switch *sw)
sw->ports[i].remote = NULL;
}
+ tb_plug_events_active(sw, false);
+
kfree(sw->ports);
kfree(sw);
}
@@ -125,6 +160,7 @@ void tb_switch_free(struct tb_switch *sw)
struct tb_switch *tb_switch_alloc(struct tb *tb, u64 route)
{
int i;
+ int cap;
struct tb_switch *sw;
int upstream_port = tb_cfg_get_upstream_port(tb->ctl, route);
if (upstream_port < 0)
@@ -177,6 +213,16 @@ struct tb_switch *tb_switch_alloc(struct tb *tb, u64 route)
/* TODO: I2C, IECS, EEPROM, link controller */
+ cap = tb_find_cap(&sw->ports[0], TB_CFG_SWITCH, TB_CAP_PLUG_EVENTS);
+ if (cap < 0) {
+ tb_sw_warn(sw, "cannot find TB_CAP_PLUG_EVENTS aborting\n");
+ goto err;
+ }
+ sw->cap_plug_events = cap;
+
+ if (tb_plug_events_active(sw, true))
+ goto err;
+
return sw;
err:
kfree(sw->ports);
diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h
index 38e4c23..af123c4 100644
--- a/drivers/thunderbolt/tb.h
+++ b/drivers/thunderbolt/tb.h
@@ -19,6 +19,7 @@ struct tb_switch {
struct tb_regs_switch_header config;
struct tb_port *ports;
struct tb *tb;
+ int cap_plug_events; /* offset, zero if not found */
};
/**
--
1.9.3
next prev parent reply other threads:[~2014-05-26 15:18 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-26 15:17 [PATCH v3 00/15] Thunderbolt driver for Apple MacBooks Andreas Noever
2014-05-26 15:17 ` [PATCH v3 01/15] thunderbolt: Add initial cactus ridge NHI support Andreas Noever
2014-05-26 15:17 ` [PATCH v3 02/15] thunderbolt: Add control channel interface Andreas Noever
2014-05-26 15:18 ` [PATCH v3 03/15] thunderbolt: Setup control channel Andreas Noever
2014-05-26 15:18 ` [PATCH v3 04/15] thunderbolt: Add tb_regs.h Andreas Noever
2014-05-26 15:18 ` [PATCH v3 05/15] thunderbolt: Initialize root switch and ports Andreas Noever
2014-05-26 15:18 ` [PATCH v3 06/15] thunderbolt: Add thunderbolt capability handling Andreas Noever
2014-05-26 15:18 ` Andreas Noever [this message]
2014-05-26 15:18 ` [PATCH v3 08/15] thunderbolt: Scan for downstream switches Andreas Noever
2014-05-26 15:18 ` [PATCH v3 09/15] thunderbolt: Handle hotplug events Andreas Noever
2014-05-28 22:26 ` Bjorn Helgaas
2014-05-26 15:18 ` [PATCH v3 10/15] thunderbolt: Add path setup code Andreas Noever
2014-05-28 22:30 ` Bjorn Helgaas
2014-05-26 15:18 ` [PATCH v3 11/15] thunderbolt: Add support for simple pci tunnels Andreas Noever
2014-05-26 15:18 ` [PATCH v3 12/15] pci: Add pci_fixup_suspend_late quirk pass Andreas Noever
2014-05-28 22:36 ` Bjorn Helgaas
2014-05-30 14:33 ` Andreas Noever
2014-05-30 16:09 ` Greg KH
2014-05-26 15:18 ` [PATCH v3 13/15] pci: Suspend/resume quirks for appel thunderbolt Andreas Noever
2014-05-27 14:07 ` Matthew Garrett
2014-05-28 22:43 ` Bjorn Helgaas
2014-05-26 15:18 ` [PATCH v3 14/15] thunderbolt: Read switch uid from EEPROM Andreas Noever
2014-05-26 15:18 ` [PATCH v3 15/15] thunderbolt: Add suspend/hibernate support Andreas Noever
2014-05-27 14:09 ` [PATCH v3 00/15] Thunderbolt driver for Apple MacBooks Matthew Garrett
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1401117492-2870-8-git-send-email-andreas.noever@gmail.com \
--to=andreas.noever@gmail.com \
--cc=bhelgaas@google.com \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=matthew.garrett@nebula.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).