lc.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Thunderbolt link controller support
  4. *
  5. * Copyright (C) 2019, Intel Corporation
  6. * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
  7. */
  8. #include <linux/delay.h>
  9. #include "tb.h"
  10. /**
  11. * tb_lc_read_uuid() - Read switch UUID from link controller common register
  12. * @sw: Switch whose UUID is read
  13. * @uuid: UUID is placed here
  14. */
  15. int tb_lc_read_uuid(struct tb_switch *sw, u32 *uuid)
  16. {
  17. if (!sw->cap_lc)
  18. return -EINVAL;
  19. return tb_sw_read(sw, uuid, TB_CFG_SWITCH, sw->cap_lc + TB_LC_FUSE, 4);
  20. }
  21. static int read_lc_desc(struct tb_switch *sw, u32 *desc)
  22. {
  23. if (!sw->cap_lc)
  24. return -EINVAL;
  25. return tb_sw_read(sw, desc, TB_CFG_SWITCH, sw->cap_lc + TB_LC_DESC, 1);
  26. }
  27. static int find_port_lc_cap(struct tb_port *port)
  28. {
  29. struct tb_switch *sw = port->sw;
  30. int start, phys, ret, size;
  31. u32 desc;
  32. ret = read_lc_desc(sw, &desc);
  33. if (ret)
  34. return ret;
  35. /* Start of port LC registers */
  36. start = (desc & TB_LC_DESC_SIZE_MASK) >> TB_LC_DESC_SIZE_SHIFT;
  37. size = (desc & TB_LC_DESC_PORT_SIZE_MASK) >> TB_LC_DESC_PORT_SIZE_SHIFT;
  38. phys = tb_phy_port_from_link(port->port);
  39. return sw->cap_lc + start + phys * size;
  40. }
  41. /**
  42. * tb_lc_reset_port() - Trigger downstream port reset through LC
  43. * @port: Port that is reset
  44. *
  45. * Triggers downstream port reset through link controller registers.
  46. * Returns %0 in case of success negative errno otherwise. Only supports
  47. * non-USB4 routers with link controller (that's Thunderbolt 2 and
  48. * Thunderbolt 3).
  49. */
  50. int tb_lc_reset_port(struct tb_port *port)
  51. {
  52. struct tb_switch *sw = port->sw;
  53. int cap, ret;
  54. u32 mode;
  55. if (sw->generation < 2)
  56. return -EINVAL;
  57. cap = find_port_lc_cap(port);
  58. if (cap < 0)
  59. return cap;
  60. ret = tb_sw_read(sw, &mode, TB_CFG_SWITCH, cap + TB_LC_PORT_MODE, 1);
  61. if (ret)
  62. return ret;
  63. mode |= TB_LC_PORT_MODE_DPR;
  64. ret = tb_sw_write(sw, &mode, TB_CFG_SWITCH, cap + TB_LC_PORT_MODE, 1);
  65. if (ret)
  66. return ret;
  67. fsleep(10000);
  68. ret = tb_sw_read(sw, &mode, TB_CFG_SWITCH, cap + TB_LC_PORT_MODE, 1);
  69. if (ret)
  70. return ret;
  71. mode &= ~TB_LC_PORT_MODE_DPR;
  72. return tb_sw_write(sw, &mode, TB_CFG_SWITCH, cap + TB_LC_PORT_MODE, 1);
  73. }
  74. static int tb_lc_set_port_configured(struct tb_port *port, bool configured)
  75. {
  76. bool upstream = tb_is_upstream_port(port);
  77. struct tb_switch *sw = port->sw;
  78. u32 ctrl, lane;
  79. int cap, ret;
  80. if (sw->generation < 2)
  81. return 0;
  82. cap = find_port_lc_cap(port);
  83. if (cap < 0)
  84. return cap;
  85. ret = tb_sw_read(sw, &ctrl, TB_CFG_SWITCH, cap + TB_LC_SX_CTRL, 1);
  86. if (ret)
  87. return ret;
  88. /* Resolve correct lane */
  89. if (port->port % 2)
  90. lane = TB_LC_SX_CTRL_L1C;
  91. else
  92. lane = TB_LC_SX_CTRL_L2C;
  93. if (configured) {
  94. ctrl |= lane;
  95. if (upstream)
  96. ctrl |= TB_LC_SX_CTRL_UPSTREAM;
  97. } else {
  98. ctrl &= ~lane;
  99. if (upstream)
  100. ctrl &= ~TB_LC_SX_CTRL_UPSTREAM;
  101. }
  102. return tb_sw_write(sw, &ctrl, TB_CFG_SWITCH, cap + TB_LC_SX_CTRL, 1);
  103. }
  104. /**
  105. * tb_lc_configure_port() - Let LC know about configured port
  106. * @port: Port that is set as configured
  107. *
  108. * Sets the port configured for power management purposes.
  109. */
  110. int tb_lc_configure_port(struct tb_port *port)
  111. {
  112. return tb_lc_set_port_configured(port, true);
  113. }
  114. /**
  115. * tb_lc_unconfigure_port() - Let LC know about unconfigured port
  116. * @port: Port that is set as configured
  117. *
  118. * Sets the port unconfigured for power management purposes.
  119. */
  120. void tb_lc_unconfigure_port(struct tb_port *port)
  121. {
  122. tb_lc_set_port_configured(port, false);
  123. }
  124. static int tb_lc_set_xdomain_configured(struct tb_port *port, bool configure)
  125. {
  126. struct tb_switch *sw = port->sw;
  127. u32 ctrl, lane;
  128. int cap, ret;
  129. if (sw->generation < 2)
  130. return 0;
  131. cap = find_port_lc_cap(port);
  132. if (cap < 0)
  133. return cap;
  134. ret = tb_sw_read(sw, &ctrl, TB_CFG_SWITCH, cap + TB_LC_SX_CTRL, 1);
  135. if (ret)
  136. return ret;
  137. /* Resolve correct lane */
  138. if (port->port % 2)
  139. lane = TB_LC_SX_CTRL_L1D;
  140. else
  141. lane = TB_LC_SX_CTRL_L2D;
  142. if (configure)
  143. ctrl |= lane;
  144. else
  145. ctrl &= ~lane;
  146. return tb_sw_write(sw, &ctrl, TB_CFG_SWITCH, cap + TB_LC_SX_CTRL, 1);
  147. }
  148. /**
  149. * tb_lc_configure_xdomain() - Inform LC that the link is XDomain
  150. * @port: Switch downstream port connected to another host
  151. *
  152. * Sets the lane configured for XDomain accordingly so that the LC knows
  153. * about this. Returns %0 in success and negative errno in failure.
  154. */
  155. int tb_lc_configure_xdomain(struct tb_port *port)
  156. {
  157. return tb_lc_set_xdomain_configured(port, true);
  158. }
  159. /**
  160. * tb_lc_unconfigure_xdomain() - Unconfigure XDomain from port
  161. * @port: Switch downstream port that was connected to another host
  162. *
  163. * Unsets the lane XDomain configuration.
  164. */
  165. void tb_lc_unconfigure_xdomain(struct tb_port *port)
  166. {
  167. tb_lc_set_xdomain_configured(port, false);
  168. }
  169. /**
  170. * tb_lc_start_lane_initialization() - Start lane initialization
  171. * @port: Device router lane 0 adapter
  172. *
  173. * Starts lane initialization for @port after the router resumed from
  174. * sleep. Should be called for those downstream lane adapters that were
  175. * not connected (tb_lc_configure_port() was not called) before sleep.
  176. *
  177. * Returns %0 in success and negative errno in case of failure.
  178. */
  179. int tb_lc_start_lane_initialization(struct tb_port *port)
  180. {
  181. struct tb_switch *sw = port->sw;
  182. int ret, cap;
  183. u32 ctrl;
  184. if (!tb_route(sw))
  185. return 0;
  186. if (sw->generation < 2)
  187. return 0;
  188. cap = find_port_lc_cap(port);
  189. if (cap < 0)
  190. return cap;
  191. ret = tb_sw_read(sw, &ctrl, TB_CFG_SWITCH, cap + TB_LC_SX_CTRL, 1);
  192. if (ret)
  193. return ret;
  194. ctrl |= TB_LC_SX_CTRL_SLI;
  195. return tb_sw_write(sw, &ctrl, TB_CFG_SWITCH, cap + TB_LC_SX_CTRL, 1);
  196. }
  197. /**
  198. * tb_lc_is_clx_supported() - Check whether CLx is supported by the lane adapter
  199. * @port: Lane adapter
  200. *
  201. * TB_LC_LINK_ATTR_CPS bit reflects if the link supports CLx including
  202. * active cables (if connected on the link).
  203. */
  204. bool tb_lc_is_clx_supported(struct tb_port *port)
  205. {
  206. struct tb_switch *sw = port->sw;
  207. int cap, ret;
  208. u32 val;
  209. cap = find_port_lc_cap(port);
  210. if (cap < 0)
  211. return false;
  212. ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, cap + TB_LC_LINK_ATTR, 1);
  213. if (ret)
  214. return false;
  215. return !!(val & TB_LC_LINK_ATTR_CPS);
  216. }
  217. /**
  218. * tb_lc_is_usb_plugged() - Is there USB device connected to port
  219. * @port: Device router lane 0 adapter
  220. *
  221. * Returns true if the @port has USB type-C device connected.
  222. */
  223. bool tb_lc_is_usb_plugged(struct tb_port *port)
  224. {
  225. struct tb_switch *sw = port->sw;
  226. int cap, ret;
  227. u32 val;
  228. if (sw->generation != 3)
  229. return false;
  230. cap = find_port_lc_cap(port);
  231. if (cap < 0)
  232. return false;
  233. ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, cap + TB_LC_CS_42, 1);
  234. if (ret)
  235. return false;
  236. return !!(val & TB_LC_CS_42_USB_PLUGGED);
  237. }
  238. /**
  239. * tb_lc_is_xhci_connected() - Is the internal xHCI connected
  240. * @port: Device router lane 0 adapter
  241. *
  242. * Returns true if the internal xHCI has been connected to @port.
  243. */
  244. bool tb_lc_is_xhci_connected(struct tb_port *port)
  245. {
  246. struct tb_switch *sw = port->sw;
  247. int cap, ret;
  248. u32 val;
  249. if (sw->generation != 3)
  250. return false;
  251. cap = find_port_lc_cap(port);
  252. if (cap < 0)
  253. return false;
  254. ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, cap + TB_LC_LINK_REQ, 1);
  255. if (ret)
  256. return false;
  257. return !!(val & TB_LC_LINK_REQ_XHCI_CONNECT);
  258. }
  259. static int __tb_lc_xhci_connect(struct tb_port *port, bool connect)
  260. {
  261. struct tb_switch *sw = port->sw;
  262. int cap, ret;
  263. u32 val;
  264. if (sw->generation != 3)
  265. return -EINVAL;
  266. cap = find_port_lc_cap(port);
  267. if (cap < 0)
  268. return cap;
  269. ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, cap + TB_LC_LINK_REQ, 1);
  270. if (ret)
  271. return ret;
  272. if (connect)
  273. val |= TB_LC_LINK_REQ_XHCI_CONNECT;
  274. else
  275. val &= ~TB_LC_LINK_REQ_XHCI_CONNECT;
  276. return tb_sw_write(sw, &val, TB_CFG_SWITCH, cap + TB_LC_LINK_REQ, 1);
  277. }
  278. /**
  279. * tb_lc_xhci_connect() - Connect internal xHCI
  280. * @port: Device router lane 0 adapter
  281. *
  282. * Tells LC to connect the internal xHCI to @port. Returns %0 on success
  283. * and negative errno in case of failure. Can be called for Thunderbolt 3
  284. * routers only.
  285. */
  286. int tb_lc_xhci_connect(struct tb_port *port)
  287. {
  288. int ret;
  289. ret = __tb_lc_xhci_connect(port, true);
  290. if (ret)
  291. return ret;
  292. tb_port_dbg(port, "xHCI connected\n");
  293. return 0;
  294. }
  295. /**
  296. * tb_lc_xhci_disconnect() - Disconnect internal xHCI
  297. * @port: Device router lane 0 adapter
  298. *
  299. * Tells LC to disconnect the internal xHCI from @port. Can be called
  300. * for Thunderbolt 3 routers only.
  301. */
  302. void tb_lc_xhci_disconnect(struct tb_port *port)
  303. {
  304. __tb_lc_xhci_connect(port, false);
  305. tb_port_dbg(port, "xHCI disconnected\n");
  306. }
  307. static int tb_lc_set_wake_one(struct tb_switch *sw, unsigned int offset,
  308. unsigned int flags)
  309. {
  310. u32 ctrl;
  311. int ret;
  312. /*
  313. * Enable wake on PCIe and USB4 (wake coming from another
  314. * router).
  315. */
  316. ret = tb_sw_read(sw, &ctrl, TB_CFG_SWITCH,
  317. offset + TB_LC_SX_CTRL, 1);
  318. if (ret)
  319. return ret;
  320. ctrl &= ~(TB_LC_SX_CTRL_WOC | TB_LC_SX_CTRL_WOD | TB_LC_SX_CTRL_WODPC |
  321. TB_LC_SX_CTRL_WODPD | TB_LC_SX_CTRL_WOP | TB_LC_SX_CTRL_WOU4);
  322. if (flags & TB_WAKE_ON_CONNECT)
  323. ctrl |= TB_LC_SX_CTRL_WOC | TB_LC_SX_CTRL_WOD;
  324. if (flags & TB_WAKE_ON_USB4)
  325. ctrl |= TB_LC_SX_CTRL_WOU4;
  326. if (flags & TB_WAKE_ON_PCIE)
  327. ctrl |= TB_LC_SX_CTRL_WOP;
  328. if (flags & TB_WAKE_ON_DP)
  329. ctrl |= TB_LC_SX_CTRL_WODPC | TB_LC_SX_CTRL_WODPD;
  330. return tb_sw_write(sw, &ctrl, TB_CFG_SWITCH, offset + TB_LC_SX_CTRL, 1);
  331. }
  332. /**
  333. * tb_lc_set_wake() - Enable/disable wake
  334. * @sw: Switch whose wakes to configure
  335. * @flags: Wakeup flags (%0 to disable)
  336. *
  337. * For each LC sets wake bits accordingly.
  338. */
  339. int tb_lc_set_wake(struct tb_switch *sw, unsigned int flags)
  340. {
  341. int start, size, nlc, ret, i;
  342. u32 desc;
  343. if (sw->generation < 2)
  344. return 0;
  345. if (!tb_route(sw))
  346. return 0;
  347. ret = read_lc_desc(sw, &desc);
  348. if (ret)
  349. return ret;
  350. /* Figure out number of link controllers */
  351. nlc = desc & TB_LC_DESC_NLC_MASK;
  352. start = (desc & TB_LC_DESC_SIZE_MASK) >> TB_LC_DESC_SIZE_SHIFT;
  353. size = (desc & TB_LC_DESC_PORT_SIZE_MASK) >> TB_LC_DESC_PORT_SIZE_SHIFT;
  354. /* For each link controller set sleep bit */
  355. for (i = 0; i < nlc; i++) {
  356. unsigned int offset = sw->cap_lc + start + i * size;
  357. ret = tb_lc_set_wake_one(sw, offset, flags);
  358. if (ret)
  359. return ret;
  360. }
  361. return 0;
  362. }
  363. /**
  364. * tb_lc_set_sleep() - Inform LC that the switch is going to sleep
  365. * @sw: Switch to set sleep
  366. *
  367. * Let the switch link controllers know that the switch is going to
  368. * sleep.
  369. */
  370. int tb_lc_set_sleep(struct tb_switch *sw)
  371. {
  372. int start, size, nlc, ret, i;
  373. u32 desc;
  374. if (sw->generation < 2)
  375. return 0;
  376. ret = read_lc_desc(sw, &desc);
  377. if (ret)
  378. return ret;
  379. /* Figure out number of link controllers */
  380. nlc = desc & TB_LC_DESC_NLC_MASK;
  381. start = (desc & TB_LC_DESC_SIZE_MASK) >> TB_LC_DESC_SIZE_SHIFT;
  382. size = (desc & TB_LC_DESC_PORT_SIZE_MASK) >> TB_LC_DESC_PORT_SIZE_SHIFT;
  383. /* For each link controller set sleep bit */
  384. for (i = 0; i < nlc; i++) {
  385. unsigned int offset = sw->cap_lc + start + i * size;
  386. u32 ctrl;
  387. ret = tb_sw_read(sw, &ctrl, TB_CFG_SWITCH,
  388. offset + TB_LC_SX_CTRL, 1);
  389. if (ret)
  390. return ret;
  391. ctrl |= TB_LC_SX_CTRL_SLP;
  392. ret = tb_sw_write(sw, &ctrl, TB_CFG_SWITCH,
  393. offset + TB_LC_SX_CTRL, 1);
  394. if (ret)
  395. return ret;
  396. }
  397. return 0;
  398. }
  399. /**
  400. * tb_lc_lane_bonding_possible() - Is lane bonding possible towards switch
  401. * @sw: Switch to check
  402. *
  403. * Checks whether conditions for lane bonding from parent to @sw are
  404. * possible.
  405. */
  406. bool tb_lc_lane_bonding_possible(struct tb_switch *sw)
  407. {
  408. struct tb_port *up;
  409. int cap, ret;
  410. u32 val;
  411. if (sw->generation < 2)
  412. return false;
  413. up = tb_upstream_port(sw);
  414. cap = find_port_lc_cap(up);
  415. if (cap < 0)
  416. return false;
  417. ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, cap + TB_LC_PORT_ATTR, 1);
  418. if (ret)
  419. return false;
  420. return !!(val & TB_LC_PORT_ATTR_BE);
  421. }
  422. static int tb_lc_dp_sink_from_port(const struct tb_switch *sw,
  423. struct tb_port *in)
  424. {
  425. struct tb_port *port;
  426. /* The first DP IN port is sink 0 and second is sink 1 */
  427. tb_switch_for_each_port(sw, port) {
  428. if (tb_port_is_dpin(port))
  429. return in != port;
  430. }
  431. return -EINVAL;
  432. }
  433. static int tb_lc_dp_sink_available(struct tb_switch *sw, int sink)
  434. {
  435. u32 val, alloc;
  436. int ret;
  437. ret = tb_sw_read(sw, &val, TB_CFG_SWITCH,
  438. sw->cap_lc + TB_LC_SNK_ALLOCATION, 1);
  439. if (ret)
  440. return ret;
  441. /*
  442. * Sink is available for CM/SW to use if the allocation valie is
  443. * either 0 or 1.
  444. */
  445. if (!sink) {
  446. alloc = val & TB_LC_SNK_ALLOCATION_SNK0_MASK;
  447. if (!alloc || alloc == TB_LC_SNK_ALLOCATION_SNK0_CM)
  448. return 0;
  449. } else {
  450. alloc = (val & TB_LC_SNK_ALLOCATION_SNK1_MASK) >>
  451. TB_LC_SNK_ALLOCATION_SNK1_SHIFT;
  452. if (!alloc || alloc == TB_LC_SNK_ALLOCATION_SNK1_CM)
  453. return 0;
  454. }
  455. return -EBUSY;
  456. }
  457. /**
  458. * tb_lc_dp_sink_query() - Is DP sink available for DP IN port
  459. * @sw: Switch whose DP sink is queried
  460. * @in: DP IN port to check
  461. *
  462. * Queries through LC SNK_ALLOCATION registers whether DP sink is available
  463. * for the given DP IN port or not.
  464. */
  465. bool tb_lc_dp_sink_query(struct tb_switch *sw, struct tb_port *in)
  466. {
  467. int sink;
  468. /*
  469. * For older generations sink is always available as there is no
  470. * allocation mechanism.
  471. */
  472. if (sw->generation < 3)
  473. return true;
  474. sink = tb_lc_dp_sink_from_port(sw, in);
  475. if (sink < 0)
  476. return false;
  477. return !tb_lc_dp_sink_available(sw, sink);
  478. }
  479. /**
  480. * tb_lc_dp_sink_alloc() - Allocate DP sink
  481. * @sw: Switch whose DP sink is allocated
  482. * @in: DP IN port the DP sink is allocated for
  483. *
  484. * Allocate DP sink for @in via LC SNK_ALLOCATION registers. If the
  485. * resource is available and allocation is successful returns %0. In all
  486. * other cases returs negative errno. In particular %-EBUSY is returned if
  487. * the resource was not available.
  488. */
  489. int tb_lc_dp_sink_alloc(struct tb_switch *sw, struct tb_port *in)
  490. {
  491. int ret, sink;
  492. u32 val;
  493. if (sw->generation < 3)
  494. return 0;
  495. sink = tb_lc_dp_sink_from_port(sw, in);
  496. if (sink < 0)
  497. return sink;
  498. ret = tb_lc_dp_sink_available(sw, sink);
  499. if (ret)
  500. return ret;
  501. ret = tb_sw_read(sw, &val, TB_CFG_SWITCH,
  502. sw->cap_lc + TB_LC_SNK_ALLOCATION, 1);
  503. if (ret)
  504. return ret;
  505. if (!sink) {
  506. val &= ~TB_LC_SNK_ALLOCATION_SNK0_MASK;
  507. val |= TB_LC_SNK_ALLOCATION_SNK0_CM;
  508. } else {
  509. val &= ~TB_LC_SNK_ALLOCATION_SNK1_MASK;
  510. val |= TB_LC_SNK_ALLOCATION_SNK1_CM <<
  511. TB_LC_SNK_ALLOCATION_SNK1_SHIFT;
  512. }
  513. ret = tb_sw_write(sw, &val, TB_CFG_SWITCH,
  514. sw->cap_lc + TB_LC_SNK_ALLOCATION, 1);
  515. if (ret)
  516. return ret;
  517. tb_port_dbg(in, "sink %d allocated\n", sink);
  518. return 0;
  519. }
  520. /**
  521. * tb_lc_dp_sink_dealloc() - De-allocate DP sink
  522. * @sw: Switch whose DP sink is de-allocated
  523. * @in: DP IN port whose DP sink is de-allocated
  524. *
  525. * De-allocate DP sink from @in using LC SNK_ALLOCATION registers.
  526. */
  527. int tb_lc_dp_sink_dealloc(struct tb_switch *sw, struct tb_port *in)
  528. {
  529. int ret, sink;
  530. u32 val;
  531. if (sw->generation < 3)
  532. return 0;
  533. sink = tb_lc_dp_sink_from_port(sw, in);
  534. if (sink < 0)
  535. return sink;
  536. /* Needs to be owned by CM/SW */
  537. ret = tb_lc_dp_sink_available(sw, sink);
  538. if (ret)
  539. return ret;
  540. ret = tb_sw_read(sw, &val, TB_CFG_SWITCH,
  541. sw->cap_lc + TB_LC_SNK_ALLOCATION, 1);
  542. if (ret)
  543. return ret;
  544. if (!sink)
  545. val &= ~TB_LC_SNK_ALLOCATION_SNK0_MASK;
  546. else
  547. val &= ~TB_LC_SNK_ALLOCATION_SNK1_MASK;
  548. ret = tb_sw_write(sw, &val, TB_CFG_SWITCH,
  549. sw->cap_lc + TB_LC_SNK_ALLOCATION, 1);
  550. if (ret)
  551. return ret;
  552. tb_port_dbg(in, "sink %d de-allocated\n", sink);
  553. return 0;
  554. }
  555. /**
  556. * tb_lc_force_power() - Forces LC to be powered on
  557. * @sw: Thunderbolt switch
  558. *
  559. * This is useful to let authentication cycle pass even without
  560. * a Thunderbolt link present.
  561. */
  562. int tb_lc_force_power(struct tb_switch *sw)
  563. {
  564. u32 in = 0xffff;
  565. return tb_sw_write(sw, &in, TB_CFG_SWITCH, TB_LC_POWER, 1);
  566. }