gth.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Intel(R) Trace Hub Global Trace Hub
  4. *
  5. * Copyright (C) 2014-2015 Intel Corporation.
  6. */
  7. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  8. #include <linux/types.h>
  9. #include <linux/module.h>
  10. #include <linux/device.h>
  11. #include <linux/io.h>
  12. #include <linux/mm.h>
  13. #include <linux/slab.h>
  14. #include <linux/bitmap.h>
  15. #include <linux/pm_runtime.h>
  16. #include "intel_th.h"
  17. #include "gth.h"
  18. struct gth_device;
  19. /**
  20. * struct gth_output - GTH view on an output port
  21. * @gth: backlink to the GTH device
  22. * @output: link to output device's output descriptor
  23. * @index: output port number
  24. * @port_type: one of GTH_* port type values
  25. * @master: bitmap of masters configured for this output
  26. */
  27. struct gth_output {
  28. struct gth_device *gth;
  29. struct intel_th_output *output;
  30. unsigned int index;
  31. unsigned int port_type;
  32. DECLARE_BITMAP(master, TH_CONFIGURABLE_MASTERS + 1);
  33. };
  34. /**
  35. * struct gth_device - GTH device
  36. * @dev: driver core's device
  37. * @base: register window base address
  38. * @output_group: attributes describing output ports
  39. * @master_group: attributes describing master assignments
  40. * @output: output ports
  41. * @master: master/output port assignments
  42. * @gth_lock: serializes accesses to GTH bits
  43. */
  44. struct gth_device {
  45. struct device *dev;
  46. void __iomem *base;
  47. struct attribute_group output_group;
  48. struct attribute_group master_group;
  49. struct gth_output output[TH_POSSIBLE_OUTPUTS];
  50. signed char master[TH_CONFIGURABLE_MASTERS + 1];
  51. spinlock_t gth_lock;
  52. };
  53. static void gth_output_set(struct gth_device *gth, int port,
  54. unsigned int config)
  55. {
  56. unsigned long reg = port & 4 ? REG_GTH_GTHOPT1 : REG_GTH_GTHOPT0;
  57. u32 val;
  58. int shift = (port & 3) * 8;
  59. val = ioread32(gth->base + reg);
  60. val &= ~(0xff << shift);
  61. val |= config << shift;
  62. iowrite32(val, gth->base + reg);
  63. }
  64. static unsigned int gth_output_get(struct gth_device *gth, int port)
  65. {
  66. unsigned long reg = port & 4 ? REG_GTH_GTHOPT1 : REG_GTH_GTHOPT0;
  67. u32 val;
  68. int shift = (port & 3) * 8;
  69. val = ioread32(gth->base + reg);
  70. val &= 0xff << shift;
  71. val >>= shift;
  72. return val;
  73. }
  74. static void gth_smcfreq_set(struct gth_device *gth, int port,
  75. unsigned int freq)
  76. {
  77. unsigned long reg = REG_GTH_SMCR0 + ((port / 2) * 4);
  78. int shift = (port & 1) * 16;
  79. u32 val;
  80. val = ioread32(gth->base + reg);
  81. val &= ~(0xffff << shift);
  82. val |= freq << shift;
  83. iowrite32(val, gth->base + reg);
  84. }
  85. static unsigned int gth_smcfreq_get(struct gth_device *gth, int port)
  86. {
  87. unsigned long reg = REG_GTH_SMCR0 + ((port / 2) * 4);
  88. int shift = (port & 1) * 16;
  89. u32 val;
  90. val = ioread32(gth->base + reg);
  91. val &= 0xffff << shift;
  92. val >>= shift;
  93. return val;
  94. }
  95. /*
  96. * "masters" attribute group
  97. */
  98. struct master_attribute {
  99. struct device_attribute attr;
  100. struct gth_device *gth;
  101. unsigned int master;
  102. };
  103. static void
  104. gth_master_set(struct gth_device *gth, unsigned int master, int port)
  105. {
  106. unsigned int reg = REG_GTH_SWDEST0 + ((master >> 1) & ~3u);
  107. unsigned int shift = (master & 0x7) * 4;
  108. u32 val;
  109. if (master >= 256) {
  110. reg = REG_GTH_GSWTDEST;
  111. shift = 0;
  112. }
  113. val = ioread32(gth->base + reg);
  114. val &= ~(0xf << shift);
  115. if (port >= 0)
  116. val |= (0x8 | port) << shift;
  117. iowrite32(val, gth->base + reg);
  118. }
  119. static ssize_t master_attr_show(struct device *dev,
  120. struct device_attribute *attr,
  121. char *buf)
  122. {
  123. struct master_attribute *ma =
  124. container_of(attr, struct master_attribute, attr);
  125. struct gth_device *gth = ma->gth;
  126. size_t count;
  127. int port;
  128. spin_lock(&gth->gth_lock);
  129. port = gth->master[ma->master];
  130. spin_unlock(&gth->gth_lock);
  131. if (port >= 0)
  132. count = snprintf(buf, PAGE_SIZE, "%x\n", port);
  133. else
  134. count = snprintf(buf, PAGE_SIZE, "disabled\n");
  135. return count;
  136. }
  137. static ssize_t master_attr_store(struct device *dev,
  138. struct device_attribute *attr,
  139. const char *buf, size_t count)
  140. {
  141. struct master_attribute *ma =
  142. container_of(attr, struct master_attribute, attr);
  143. struct gth_device *gth = ma->gth;
  144. int old_port, port;
  145. if (kstrtoint(buf, 10, &port) < 0)
  146. return -EINVAL;
  147. if (port >= TH_POSSIBLE_OUTPUTS || port < -1)
  148. return -EINVAL;
  149. spin_lock(&gth->gth_lock);
  150. /* disconnect from the previous output port, if any */
  151. old_port = gth->master[ma->master];
  152. if (old_port >= 0) {
  153. gth->master[ma->master] = -1;
  154. clear_bit(ma->master, gth->output[old_port].master);
  155. /*
  156. * if the port is active, program this setting,
  157. * implies that runtime PM is on
  158. */
  159. if (gth->output[old_port].output->active)
  160. gth_master_set(gth, ma->master, -1);
  161. }
  162. /* connect to the new output port, if any */
  163. if (port >= 0) {
  164. /* check if there's a driver for this port */
  165. if (!gth->output[port].output) {
  166. count = -ENODEV;
  167. goto unlock;
  168. }
  169. set_bit(ma->master, gth->output[port].master);
  170. /* if the port is active, program this setting, see above */
  171. if (gth->output[port].output->active)
  172. gth_master_set(gth, ma->master, port);
  173. }
  174. gth->master[ma->master] = port;
  175. unlock:
  176. spin_unlock(&gth->gth_lock);
  177. return count;
  178. }
  179. struct output_attribute {
  180. struct device_attribute attr;
  181. struct gth_device *gth;
  182. unsigned int port;
  183. unsigned int parm;
  184. };
  185. #define OUTPUT_PARM(_name, _mask, _r, _w, _what) \
  186. [TH_OUTPUT_PARM(_name)] = { .name = __stringify(_name), \
  187. .get = gth_ ## _what ## _get, \
  188. .set = gth_ ## _what ## _set, \
  189. .mask = (_mask), \
  190. .readable = (_r), \
  191. .writable = (_w) }
  192. static const struct output_parm {
  193. const char *name;
  194. unsigned int (*get)(struct gth_device *gth, int port);
  195. void (*set)(struct gth_device *gth, int port,
  196. unsigned int val);
  197. unsigned int mask;
  198. unsigned int readable : 1,
  199. writable : 1;
  200. } output_parms[] = {
  201. OUTPUT_PARM(port, 0x7, 1, 0, output),
  202. OUTPUT_PARM(null, BIT(3), 1, 1, output),
  203. OUTPUT_PARM(drop, BIT(4), 1, 1, output),
  204. OUTPUT_PARM(reset, BIT(5), 1, 0, output),
  205. OUTPUT_PARM(flush, BIT(7), 0, 1, output),
  206. OUTPUT_PARM(smcfreq, 0xffff, 1, 1, smcfreq),
  207. };
  208. static void
  209. gth_output_parm_set(struct gth_device *gth, int port, unsigned int parm,
  210. unsigned int val)
  211. {
  212. unsigned int config = output_parms[parm].get(gth, port);
  213. unsigned int mask = output_parms[parm].mask;
  214. unsigned int shift = __ffs(mask);
  215. config &= ~mask;
  216. config |= (val << shift) & mask;
  217. output_parms[parm].set(gth, port, config);
  218. }
  219. static unsigned int
  220. gth_output_parm_get(struct gth_device *gth, int port, unsigned int parm)
  221. {
  222. unsigned int config = output_parms[parm].get(gth, port);
  223. unsigned int mask = output_parms[parm].mask;
  224. unsigned int shift = __ffs(mask);
  225. config &= mask;
  226. config >>= shift;
  227. return config;
  228. }
  229. /*
  230. * Reset outputs and sources
  231. */
  232. static int intel_th_gth_reset(struct gth_device *gth)
  233. {
  234. u32 reg;
  235. int port, i;
  236. reg = ioread32(gth->base + REG_GTH_SCRPD0);
  237. if (reg & SCRPD_DEBUGGER_IN_USE)
  238. return -EBUSY;
  239. /* Always save/restore STH and TU registers in S0ix entry/exit */
  240. reg |= SCRPD_STH_IS_ENABLED | SCRPD_TRIGGER_IS_ENABLED;
  241. iowrite32(reg, gth->base + REG_GTH_SCRPD0);
  242. /* output ports */
  243. for (port = 0; port < 8; port++) {
  244. if (gth_output_parm_get(gth, port, TH_OUTPUT_PARM(port)) ==
  245. GTH_NONE)
  246. continue;
  247. gth_output_set(gth, port, 0);
  248. gth_smcfreq_set(gth, port, 16);
  249. }
  250. /* disable overrides */
  251. iowrite32(0, gth->base + REG_GTH_DESTOVR);
  252. /* masters swdest_0~31 and gswdest */
  253. for (i = 0; i < 33; i++)
  254. iowrite32(0, gth->base + REG_GTH_SWDEST0 + i * 4);
  255. /* sources */
  256. iowrite32(0, gth->base + REG_GTH_SCR);
  257. iowrite32(0xfc, gth->base + REG_GTH_SCR2);
  258. return 0;
  259. }
  260. /*
  261. * "outputs" attribute group
  262. */
  263. static ssize_t output_attr_show(struct device *dev,
  264. struct device_attribute *attr,
  265. char *buf)
  266. {
  267. struct output_attribute *oa =
  268. container_of(attr, struct output_attribute, attr);
  269. struct gth_device *gth = oa->gth;
  270. size_t count;
  271. pm_runtime_get_sync(dev);
  272. spin_lock(&gth->gth_lock);
  273. count = snprintf(buf, PAGE_SIZE, "%x\n",
  274. gth_output_parm_get(gth, oa->port, oa->parm));
  275. spin_unlock(&gth->gth_lock);
  276. pm_runtime_put(dev);
  277. return count;
  278. }
  279. static ssize_t output_attr_store(struct device *dev,
  280. struct device_attribute *attr,
  281. const char *buf, size_t count)
  282. {
  283. struct output_attribute *oa =
  284. container_of(attr, struct output_attribute, attr);
  285. struct gth_device *gth = oa->gth;
  286. unsigned int config;
  287. if (kstrtouint(buf, 16, &config) < 0)
  288. return -EINVAL;
  289. pm_runtime_get_sync(dev);
  290. spin_lock(&gth->gth_lock);
  291. gth_output_parm_set(gth, oa->port, oa->parm, config);
  292. spin_unlock(&gth->gth_lock);
  293. pm_runtime_put(dev);
  294. return count;
  295. }
  296. static int intel_th_master_attributes(struct gth_device *gth)
  297. {
  298. struct master_attribute *master_attrs;
  299. struct attribute **attrs;
  300. int i, nattrs = TH_CONFIGURABLE_MASTERS + 2;
  301. attrs = devm_kcalloc(gth->dev, nattrs, sizeof(void *), GFP_KERNEL);
  302. if (!attrs)
  303. return -ENOMEM;
  304. master_attrs = devm_kcalloc(gth->dev, nattrs,
  305. sizeof(struct master_attribute),
  306. GFP_KERNEL);
  307. if (!master_attrs)
  308. return -ENOMEM;
  309. for (i = 0; i < TH_CONFIGURABLE_MASTERS + 1; i++) {
  310. char *name;
  311. name = devm_kasprintf(gth->dev, GFP_KERNEL, "%d%s", i,
  312. i == TH_CONFIGURABLE_MASTERS ? "+" : "");
  313. if (!name)
  314. return -ENOMEM;
  315. master_attrs[i].attr.attr.name = name;
  316. master_attrs[i].attr.attr.mode = S_IRUGO | S_IWUSR;
  317. master_attrs[i].attr.show = master_attr_show;
  318. master_attrs[i].attr.store = master_attr_store;
  319. sysfs_attr_init(&master_attrs[i].attr.attr);
  320. attrs[i] = &master_attrs[i].attr.attr;
  321. master_attrs[i].gth = gth;
  322. master_attrs[i].master = i;
  323. }
  324. gth->master_group.name = "masters";
  325. gth->master_group.attrs = attrs;
  326. return sysfs_create_group(&gth->dev->kobj, &gth->master_group);
  327. }
  328. static int intel_th_output_attributes(struct gth_device *gth)
  329. {
  330. struct output_attribute *out_attrs;
  331. struct attribute **attrs;
  332. int i, j, nouts = TH_POSSIBLE_OUTPUTS;
  333. int nparms = ARRAY_SIZE(output_parms);
  334. int nattrs = nouts * nparms + 1;
  335. attrs = devm_kcalloc(gth->dev, nattrs, sizeof(void *), GFP_KERNEL);
  336. if (!attrs)
  337. return -ENOMEM;
  338. out_attrs = devm_kcalloc(gth->dev, nattrs,
  339. sizeof(struct output_attribute),
  340. GFP_KERNEL);
  341. if (!out_attrs)
  342. return -ENOMEM;
  343. for (i = 0; i < nouts; i++) {
  344. for (j = 0; j < nparms; j++) {
  345. unsigned int idx = i * nparms + j;
  346. char *name;
  347. name = devm_kasprintf(gth->dev, GFP_KERNEL, "%d_%s", i,
  348. output_parms[j].name);
  349. if (!name)
  350. return -ENOMEM;
  351. out_attrs[idx].attr.attr.name = name;
  352. if (output_parms[j].readable) {
  353. out_attrs[idx].attr.attr.mode |= S_IRUGO;
  354. out_attrs[idx].attr.show = output_attr_show;
  355. }
  356. if (output_parms[j].writable) {
  357. out_attrs[idx].attr.attr.mode |= S_IWUSR;
  358. out_attrs[idx].attr.store = output_attr_store;
  359. }
  360. sysfs_attr_init(&out_attrs[idx].attr.attr);
  361. attrs[idx] = &out_attrs[idx].attr.attr;
  362. out_attrs[idx].gth = gth;
  363. out_attrs[idx].port = i;
  364. out_attrs[idx].parm = j;
  365. }
  366. }
  367. gth->output_group.name = "outputs";
  368. gth->output_group.attrs = attrs;
  369. return sysfs_create_group(&gth->dev->kobj, &gth->output_group);
  370. }
  371. /**
  372. * intel_th_gth_disable() - disable tracing to an output device
  373. * @thdev: GTH device
  374. * @output: output device's descriptor
  375. *
  376. * This will deconfigure all masters set to output to this device,
  377. * disable tracing using force storeEn off signal and wait for the
  378. * "pipeline empty" bit for corresponding output port.
  379. */
  380. static void intel_th_gth_disable(struct intel_th_device *thdev,
  381. struct intel_th_output *output)
  382. {
  383. struct gth_device *gth = dev_get_drvdata(&thdev->dev);
  384. unsigned long count;
  385. int master;
  386. u32 reg;
  387. spin_lock(&gth->gth_lock);
  388. output->active = false;
  389. for_each_set_bit(master, gth->output[output->port].master,
  390. TH_CONFIGURABLE_MASTERS) {
  391. gth_master_set(gth, master, -1);
  392. }
  393. spin_unlock(&gth->gth_lock);
  394. iowrite32(0, gth->base + REG_GTH_SCR);
  395. iowrite32(0xfd, gth->base + REG_GTH_SCR2);
  396. /* wait on pipeline empty for the given port */
  397. for (reg = 0, count = GTH_PLE_WAITLOOP_DEPTH;
  398. count && !(reg & BIT(output->port)); count--) {
  399. reg = ioread32(gth->base + REG_GTH_STAT);
  400. cpu_relax();
  401. }
  402. /* clear force capture done for next captures */
  403. iowrite32(0xfc, gth->base + REG_GTH_SCR2);
  404. if (!count)
  405. dev_dbg(&thdev->dev, "timeout waiting for GTH[%d] PLE\n",
  406. output->port);
  407. reg = ioread32(gth->base + REG_GTH_SCRPD0);
  408. reg &= ~output->scratchpad;
  409. iowrite32(reg, gth->base + REG_GTH_SCRPD0);
  410. }
  411. static void gth_tscu_resync(struct gth_device *gth)
  412. {
  413. u32 reg;
  414. reg = ioread32(gth->base + REG_TSCU_TSUCTRL);
  415. reg &= ~TSUCTRL_CTCRESYNC;
  416. iowrite32(reg, gth->base + REG_TSCU_TSUCTRL);
  417. }
  418. /**
  419. * intel_th_gth_enable() - enable tracing to an output device
  420. * @thdev: GTH device
  421. * @output: output device's descriptor
  422. *
  423. * This will configure all masters set to output to this device and
  424. * enable tracing using force storeEn signal.
  425. */
  426. static void intel_th_gth_enable(struct intel_th_device *thdev,
  427. struct intel_th_output *output)
  428. {
  429. struct gth_device *gth = dev_get_drvdata(&thdev->dev);
  430. struct intel_th *th = to_intel_th(thdev);
  431. u32 scr = 0xfc0000, scrpd;
  432. int master;
  433. spin_lock(&gth->gth_lock);
  434. for_each_set_bit(master, gth->output[output->port].master,
  435. TH_CONFIGURABLE_MASTERS + 1) {
  436. gth_master_set(gth, master, output->port);
  437. }
  438. if (output->multiblock)
  439. scr |= 0xff;
  440. output->active = true;
  441. spin_unlock(&gth->gth_lock);
  442. if (INTEL_TH_CAP(th, tscu_enable))
  443. gth_tscu_resync(gth);
  444. scrpd = ioread32(gth->base + REG_GTH_SCRPD0);
  445. scrpd |= output->scratchpad;
  446. iowrite32(scrpd, gth->base + REG_GTH_SCRPD0);
  447. iowrite32(scr, gth->base + REG_GTH_SCR);
  448. iowrite32(0, gth->base + REG_GTH_SCR2);
  449. }
  450. /**
  451. * intel_th_gth_assign() - assign output device to a GTH output port
  452. * @thdev: GTH device
  453. * @othdev: output device
  454. *
  455. * This will match a given output device parameters against present
  456. * output ports on the GTH and fill out relevant bits in output device's
  457. * descriptor.
  458. *
  459. * Return: 0 on success, -errno on error.
  460. */
  461. static int intel_th_gth_assign(struct intel_th_device *thdev,
  462. struct intel_th_device *othdev)
  463. {
  464. struct gth_device *gth = dev_get_drvdata(&thdev->dev);
  465. int i, id;
  466. if (thdev->host_mode)
  467. return -EBUSY;
  468. if (othdev->type != INTEL_TH_OUTPUT)
  469. return -EINVAL;
  470. for (i = 0, id = 0; i < TH_POSSIBLE_OUTPUTS; i++) {
  471. if (gth->output[i].port_type != othdev->output.type)
  472. continue;
  473. if (othdev->id == -1 || othdev->id == id)
  474. goto found;
  475. id++;
  476. }
  477. return -ENOENT;
  478. found:
  479. spin_lock(&gth->gth_lock);
  480. othdev->output.port = i;
  481. othdev->output.active = false;
  482. gth->output[i].output = &othdev->output;
  483. spin_unlock(&gth->gth_lock);
  484. return 0;
  485. }
  486. /**
  487. * intel_th_gth_unassign() - deassociate an output device from its output port
  488. * @thdev: GTH device
  489. * @othdev: output device
  490. */
  491. static void intel_th_gth_unassign(struct intel_th_device *thdev,
  492. struct intel_th_device *othdev)
  493. {
  494. struct gth_device *gth = dev_get_drvdata(&thdev->dev);
  495. int port = othdev->output.port;
  496. int master;
  497. if (thdev->host_mode)
  498. return;
  499. spin_lock(&gth->gth_lock);
  500. othdev->output.port = -1;
  501. othdev->output.active = false;
  502. gth->output[port].output = NULL;
  503. for (master = 0; master <= TH_CONFIGURABLE_MASTERS; master++)
  504. if (gth->master[master] == port)
  505. gth->master[master] = -1;
  506. spin_unlock(&gth->gth_lock);
  507. }
  508. static int
  509. intel_th_gth_set_output(struct intel_th_device *thdev, unsigned int master)
  510. {
  511. struct gth_device *gth = dev_get_drvdata(&thdev->dev);
  512. int port = 0; /* FIXME: make default output configurable */
  513. /*
  514. * everything above TH_CONFIGURABLE_MASTERS is controlled by the
  515. * same register
  516. */
  517. if (master > TH_CONFIGURABLE_MASTERS)
  518. master = TH_CONFIGURABLE_MASTERS;
  519. spin_lock(&gth->gth_lock);
  520. if (gth->master[master] == -1) {
  521. set_bit(master, gth->output[port].master);
  522. gth->master[master] = port;
  523. }
  524. spin_unlock(&gth->gth_lock);
  525. return 0;
  526. }
  527. static int intel_th_gth_probe(struct intel_th_device *thdev)
  528. {
  529. struct device *dev = &thdev->dev;
  530. struct intel_th *th = dev_get_drvdata(dev->parent);
  531. struct gth_device *gth;
  532. struct resource *res;
  533. void __iomem *base;
  534. int i, ret;
  535. res = intel_th_device_get_resource(thdev, IORESOURCE_MEM, 0);
  536. if (!res)
  537. return -ENODEV;
  538. base = devm_ioremap(dev, res->start, resource_size(res));
  539. if (!base)
  540. return -ENOMEM;
  541. gth = devm_kzalloc(dev, sizeof(*gth), GFP_KERNEL);
  542. if (!gth)
  543. return -ENOMEM;
  544. gth->dev = dev;
  545. gth->base = base;
  546. spin_lock_init(&gth->gth_lock);
  547. dev_set_drvdata(dev, gth);
  548. /*
  549. * Host mode can be signalled via SW means or via SCRPD_DEBUGGER_IN_USE
  550. * bit. Either way, don't reset HW in this case, and don't export any
  551. * capture configuration attributes. Also, refuse to assign output
  552. * drivers to ports, see intel_th_gth_assign().
  553. */
  554. if (thdev->host_mode)
  555. return 0;
  556. ret = intel_th_gth_reset(gth);
  557. if (ret) {
  558. if (ret != -EBUSY)
  559. return ret;
  560. thdev->host_mode = true;
  561. return 0;
  562. }
  563. for (i = 0; i < TH_CONFIGURABLE_MASTERS + 1; i++)
  564. gth->master[i] = -1;
  565. for (i = 0; i < TH_POSSIBLE_OUTPUTS; i++) {
  566. gth->output[i].gth = gth;
  567. gth->output[i].index = i;
  568. gth->output[i].port_type =
  569. gth_output_parm_get(gth, i, TH_OUTPUT_PARM(port));
  570. if (gth->output[i].port_type == GTH_NONE)
  571. continue;
  572. ret = intel_th_output_enable(th, gth->output[i].port_type);
  573. /* -ENODEV is ok, we just won't have that device enumerated */
  574. if (ret && ret != -ENODEV)
  575. return ret;
  576. }
  577. if (intel_th_output_attributes(gth) ||
  578. intel_th_master_attributes(gth)) {
  579. pr_warn("Can't initialize sysfs attributes\n");
  580. if (gth->output_group.attrs)
  581. sysfs_remove_group(&gth->dev->kobj, &gth->output_group);
  582. return -ENOMEM;
  583. }
  584. return 0;
  585. }
  586. static void intel_th_gth_remove(struct intel_th_device *thdev)
  587. {
  588. struct gth_device *gth = dev_get_drvdata(&thdev->dev);
  589. sysfs_remove_group(&gth->dev->kobj, &gth->output_group);
  590. sysfs_remove_group(&gth->dev->kobj, &gth->master_group);
  591. }
  592. static struct intel_th_driver intel_th_gth_driver = {
  593. .probe = intel_th_gth_probe,
  594. .remove = intel_th_gth_remove,
  595. .assign = intel_th_gth_assign,
  596. .unassign = intel_th_gth_unassign,
  597. .set_output = intel_th_gth_set_output,
  598. .enable = intel_th_gth_enable,
  599. .disable = intel_th_gth_disable,
  600. .driver = {
  601. .name = "gth",
  602. .owner = THIS_MODULE,
  603. },
  604. };
  605. module_driver(intel_th_gth_driver,
  606. intel_th_driver_register,
  607. intel_th_driver_unregister);
  608. MODULE_ALIAS("intel_th_switch");
  609. MODULE_LICENSE("GPL v2");
  610. MODULE_DESCRIPTION("Intel(R) Trace Hub Global Trace Hub driver");
  611. MODULE_AUTHOR("Alexander Shishkin <alexander.shishkin@linux.intel.com>");