qcom-hv-haptics-debugfs.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #ifdef CONFIG_DEBUG_FS
  6. #include <linux/debugfs.h>
  7. #define CHAR_BRAKE_MODE 24
  8. #define CHAR_PER_PATTERN_S 48
  9. static int vmax_dbgfs_read(void *data, u64 *val)
  10. {
  11. struct haptics_effect *effect = data;
  12. *val = effect->vmax_mv;
  13. return 0;
  14. }
  15. static int vmax_dbgfs_write(void *data, u64 val)
  16. {
  17. struct haptics_effect *effect = data;
  18. if (val > MAX_VMAX_MV)
  19. val = MAX_VMAX_MV;
  20. effect->vmax_mv = (u32) val;
  21. return 0;
  22. }
  23. DEFINE_DEBUGFS_ATTRIBUTE(vmax_debugfs_ops, vmax_dbgfs_read,
  24. vmax_dbgfs_write, "%llu\n");
  25. static int auto_res_en_dbgfs_read(void *data, u64 *val)
  26. {
  27. struct haptics_effect *effect = data;
  28. *val = !effect->auto_res_disable;
  29. return 0;
  30. }
  31. static int auto_res_en_dbgfs_write(void *data, u64 val)
  32. {
  33. struct haptics_effect *effect = data;
  34. effect->auto_res_disable = !val;
  35. return 0;
  36. }
  37. DEFINE_DEBUGFS_ATTRIBUTE(auto_res_en_debugfs_ops, auto_res_en_dbgfs_read,
  38. auto_res_en_dbgfs_write, "%llu\n");
  39. static ssize_t pattern_s_dbgfs_read(struct file *fp, char __user *buf, size_t count, loff_t *ppos)
  40. {
  41. struct haptics_effect *effect = fp->private_data;
  42. u32 pos = 0, size = CHAR_PER_PATTERN_S * SAMPLES_PER_PATTERN;
  43. char *str;
  44. int i = 0, rc;
  45. if (!effect->pattern)
  46. return 0;
  47. str = kzalloc(size, GFP_KERNEL);
  48. if (!str)
  49. return -ENOMEM;
  50. for (i = 0; i < SAMPLES_PER_PATTERN; i++) {
  51. pos += scnprintf(str + pos, size - pos, "0x%03x ",
  52. effect->pattern->samples[i].amplitude);
  53. pos += scnprintf(str + pos, size - pos, "%s(0x%02x) ",
  54. period_str[effect->pattern->samples[i].period],
  55. effect->pattern->samples[i].period);
  56. pos += scnprintf(str + pos, size - pos, "F_LRA_X2(%1d)\n",
  57. effect->pattern->samples[i].f_lra_x2);
  58. }
  59. rc = simple_read_from_buffer(buf, count, ppos, str, pos);
  60. kfree(str);
  61. return rc;
  62. }
  63. static ssize_t pattern_s_dbgfs_write(struct file *fp,
  64. const char __user *buf, size_t count, loff_t *ppos)
  65. {
  66. struct haptics_effect *effect = fp->private_data;
  67. struct pattern_s patterns[SAMPLES_PER_PATTERN] = {{0, 0, 0},};
  68. char *str, *kbuf, *token;
  69. u32 val, tmp[3 * SAMPLES_PER_PATTERN] = {0};
  70. int rc, i = 0, j = 0;
  71. if (count > CHAR_PER_PATTERN_S * SAMPLES_PER_PATTERN)
  72. return -EINVAL;
  73. kbuf = kzalloc(CHAR_PER_PATTERN_S * SAMPLES_PER_PATTERN + 1,
  74. GFP_KERNEL);
  75. if (!kbuf)
  76. return -ENOMEM;
  77. str = kbuf;
  78. rc = copy_from_user(str, buf, count);
  79. if (rc > 0) {
  80. rc = -EFAULT;
  81. goto exit;
  82. }
  83. str[count] = '\0';
  84. *ppos += count;
  85. while ((token = strsep((char **)&str, " ")) != NULL) {
  86. rc = kstrtouint(token, 0, &val);
  87. if (rc < 0) {
  88. rc = -EINVAL;
  89. goto exit;
  90. }
  91. if (i >= ARRAY_SIZE(tmp)) {
  92. pr_err("too many patterns in input string\n");
  93. rc = -EINVAL;
  94. goto exit;
  95. }
  96. tmp[i++] = val;
  97. }
  98. if (i % 3)
  99. pr_warn("Tuple should be having 3 elements, discarding tuple %d\n",
  100. i / 3);
  101. for (j = 0; j < i / 3; j++) {
  102. if (tmp[3 * j] > 0x1ff || tmp[3 * j + 1] > T_LRA_X_8 ||
  103. tmp[3 * j + 2] > 1) {
  104. pr_err("allowed tuples: [amplitude(<= 0x1ff) period(<=6(T_LRA_X_8)) f_lra_x2(0,1)]\n");
  105. rc = -EINVAL;
  106. goto exit;
  107. }
  108. patterns[j].amplitude = (u16)tmp[3 * j];
  109. patterns[j].period = (enum s_period)tmp[3 * j + 1];
  110. patterns[j].f_lra_x2 = !!tmp[3 * j + 2];
  111. }
  112. memcpy(effect->pattern->samples, patterns,
  113. sizeof(effect->pattern->samples));
  114. /* recalculate the play length */
  115. effect->pattern->play_length_us =
  116. get_pattern_play_length_us(effect->pattern);
  117. if (effect->pattern->play_length_us == -EINVAL) {
  118. pr_err("get pattern play length failed\n");
  119. rc = -EINVAL;
  120. goto exit;
  121. }
  122. rc = count;
  123. exit:
  124. kfree(kbuf);
  125. return rc;
  126. }
  127. static const struct file_operations pattern_s_dbgfs_ops = {
  128. .read = pattern_s_dbgfs_read,
  129. .write = pattern_s_dbgfs_write,
  130. .open = simple_open,
  131. };
  132. static int pattern_play_rate_us_dbgfs_read(void *data, u64 *val)
  133. {
  134. struct haptics_effect *effect = data;
  135. *val = effect->pattern->play_rate_us;
  136. return 0;
  137. }
  138. static int pattern_play_rate_us_dbgfs_write(void *data, u64 val)
  139. {
  140. struct haptics_effect *effect = data;
  141. if (val > TLRA_MAX_US)
  142. val = TLRA_MAX_US;
  143. effect->pattern->play_rate_us = (u32)val;
  144. /* recalculate the play length */
  145. effect->pattern->play_length_us =
  146. get_pattern_play_length_us(effect->pattern);
  147. if (effect->pattern->play_length_us == -EINVAL) {
  148. pr_err("get pattern play length failed\n");
  149. return -EINVAL;
  150. }
  151. return 0;
  152. }
  153. DEFINE_DEBUGFS_ATTRIBUTE(pattern_play_rate_dbgfs_ops,
  154. pattern_play_rate_us_dbgfs_read,
  155. pattern_play_rate_us_dbgfs_write, "%llu\n");
  156. static ssize_t fifo_s_dbgfs_read(struct file *fp, char __user *buf, size_t count, loff_t *ppos)
  157. {
  158. struct haptics_effect *effect = fp->private_data;
  159. struct fifo_cfg *fifo = effect->fifo;
  160. char *kbuf;
  161. int rc, i;
  162. u32 size, pos = 0;
  163. size = CHAR_PER_SAMPLE * fifo->num_s + 1;
  164. kbuf = kzalloc(size, GFP_KERNEL);
  165. if (!kbuf)
  166. return -ENOMEM;
  167. for (i = 0; i < fifo->num_s; i++)
  168. pos += scnprintf(kbuf + pos, size - pos,
  169. "%d ", (s8)fifo->samples[i]);
  170. pos += scnprintf(kbuf + pos, size - pos, "%s", "\n");
  171. rc = simple_read_from_buffer(buf, count, ppos, kbuf, pos);
  172. kfree(kbuf);
  173. return rc;
  174. }
  175. static ssize_t fifo_s_dbgfs_write(struct file *fp,
  176. const char __user *buf, size_t count, loff_t *ppos)
  177. {
  178. struct haptics_effect *effect = fp->private_data;
  179. struct fifo_cfg *fifo = effect->fifo;
  180. char *str, *kbuf, *token;
  181. int rc, i = 0;
  182. int val;
  183. u8 *samples;
  184. kbuf = kzalloc(count + 1, GFP_KERNEL);
  185. if (!kbuf)
  186. return -ENOMEM;
  187. str = kbuf;
  188. rc = copy_from_user(str, buf, count);
  189. if (rc > 0) {
  190. rc = -EFAULT;
  191. goto exit;
  192. }
  193. str[count] = '\0';
  194. *ppos += count;
  195. samples = kcalloc(fifo->num_s, sizeof(*samples), GFP_KERNEL);
  196. if (!samples) {
  197. rc = -ENOMEM;
  198. goto exit;
  199. }
  200. while ((token = strsep(&str, " ")) != NULL) {
  201. rc = kstrtoint(token, 0, &val);
  202. if (rc < 0) {
  203. rc = -EINVAL;
  204. goto exit2;
  205. }
  206. if (val > 0xff)
  207. val = 0xff;
  208. samples[i++] = (u8)val;
  209. /* only support fifo pattern no longer than before */
  210. if (i >= fifo->num_s)
  211. break;
  212. }
  213. memcpy(fifo->samples, samples, fifo->num_s);
  214. fifo->play_length_us = get_fifo_play_length_us(fifo, effect->t_lra_us);
  215. if (fifo->play_length_us == -EINVAL) {
  216. pr_err("get fifo play length failed\n");
  217. rc = -EINVAL;
  218. goto exit2;
  219. }
  220. rc = count;
  221. exit2:
  222. kfree(samples);
  223. exit:
  224. kfree(kbuf);
  225. return rc;
  226. }
  227. static const struct file_operations fifo_s_dbgfs_ops = {
  228. .read = fifo_s_dbgfs_read,
  229. .write = fifo_s_dbgfs_write,
  230. .owner = THIS_MODULE,
  231. .open = simple_open,
  232. };
  233. static int fifo_period_dbgfs_read(void *data, u64 *val)
  234. {
  235. struct haptics_effect *effect = data;
  236. *val = effect->fifo->period_per_s;
  237. return 0;
  238. }
  239. static int fifo_period_dbgfs_write(void *data, u64 val)
  240. {
  241. struct haptics_effect *effect = data;
  242. struct fifo_cfg *fifo = effect->fifo;
  243. if (val > F_48KHZ)
  244. return -EINVAL;
  245. fifo->period_per_s = (enum s_period)val;
  246. fifo->play_length_us = get_fifo_play_length_us(fifo, effect->t_lra_us);
  247. if (fifo->play_length_us == -EINVAL) {
  248. pr_err("get fifo play length failed\n");
  249. return -EINVAL;
  250. }
  251. return 0;
  252. }
  253. DEFINE_DEBUGFS_ATTRIBUTE(fifo_period_dbgfs_ops,
  254. fifo_period_dbgfs_read,
  255. fifo_period_dbgfs_write, "%llu\n");
  256. static ssize_t brake_s_dbgfs_read(struct file *fp, char __user *buf, size_t count, loff_t *ppos)
  257. {
  258. struct haptics_effect *effect = fp->private_data;
  259. struct brake_cfg *brake = effect->brake;
  260. char *str;
  261. int rc, i;
  262. u32 size, pos = 0;
  263. size = CHAR_PER_SAMPLE * BRAKE_SAMPLE_COUNT + 1;
  264. str = kzalloc(size, GFP_KERNEL);
  265. if (!str)
  266. return -ENOMEM;
  267. for (i = 0; i < BRAKE_SAMPLE_COUNT; i++)
  268. pos += scnprintf(str + pos, size - pos, "0x%02x ",
  269. brake->samples[i]);
  270. pos += scnprintf(str + pos, size - pos, "%s", "\n");
  271. rc = simple_read_from_buffer(buf, count, ppos, str, pos);
  272. kfree(str);
  273. return rc;
  274. }
  275. static ssize_t brake_s_dbgfs_write(struct file *fp,
  276. const char __user *buf, size_t count, loff_t *ppos)
  277. {
  278. struct haptics_effect *effect = fp->private_data;
  279. struct brake_cfg *brake = effect->brake;
  280. char *str, *kbuf, *token;
  281. int rc, i = 0;
  282. u32 val;
  283. u8 samples[BRAKE_SAMPLE_COUNT] = {0};
  284. if (count > CHAR_PER_SAMPLE * BRAKE_SAMPLE_COUNT)
  285. return -EINVAL;
  286. kbuf = kzalloc(CHAR_PER_SAMPLE * BRAKE_SAMPLE_COUNT + 1, GFP_KERNEL);
  287. if (!kbuf)
  288. return -ENOMEM;
  289. str = kbuf;
  290. rc = copy_from_user(str, buf, count);
  291. if (rc > 0) {
  292. rc = -EFAULT;
  293. goto exit;
  294. }
  295. str[count] = '\0';
  296. *ppos += count;
  297. while ((token = strsep((char **)&str, " ")) != NULL) {
  298. rc = kstrtouint(token, 0, &val);
  299. if (rc < 0) {
  300. rc = -EINVAL;
  301. goto exit;
  302. }
  303. if (val > 0xff)
  304. val = 0xff;
  305. samples[i++] = (u8)val;
  306. if (i >= BRAKE_SAMPLE_COUNT)
  307. break;
  308. }
  309. memcpy(brake->samples, samples, BRAKE_SAMPLE_COUNT);
  310. verify_brake_samples(brake);
  311. brake->play_length_us =
  312. get_brake_play_length_us(brake, effect->t_lra_us);
  313. rc = count;
  314. exit:
  315. kfree(kbuf);
  316. return rc;
  317. }
  318. static const struct file_operations brake_s_dbgfs_ops = {
  319. .read = brake_s_dbgfs_read,
  320. .write = brake_s_dbgfs_write,
  321. .open = simple_open,
  322. };
  323. static ssize_t brake_mode_dbgfs_read(struct file *fp,
  324. char __user *buf, size_t count, loff_t *ppos)
  325. {
  326. struct haptics_effect *effect = fp->private_data;
  327. struct brake_cfg *brake = effect->brake;
  328. char str[CHAR_BRAKE_MODE] = {0};
  329. u32 size;
  330. int rc;
  331. size = scnprintf(str, ARRAY_SIZE(str), "%s\n", brake_str[brake->mode]);
  332. rc = simple_read_from_buffer(buf, count, ppos, str, size);
  333. return rc;
  334. }
  335. static ssize_t brake_mode_dbgfs_write(struct file *fp,
  336. const char __user *buf, size_t count, loff_t *ppos)
  337. {
  338. struct haptics_effect *effect = fp->private_data;
  339. struct brake_cfg *brake = effect->brake;
  340. char *kbuf;
  341. int rc;
  342. kbuf = kzalloc(count + 1, GFP_KERNEL);
  343. if (!kbuf)
  344. return -ENOMEM;
  345. rc = copy_from_user(kbuf, buf, count);
  346. if (rc > 0) {
  347. rc = -EFAULT;
  348. goto exit;
  349. }
  350. kbuf[count] = '\0';
  351. *ppos += count;
  352. rc = count;
  353. if (strcmp(kbuf, "open-loop") == 0) {
  354. brake->mode = OL_BRAKE;
  355. } else if (strcmp(kbuf, "close-loop") == 0) {
  356. brake->mode = CL_BRAKE;
  357. } else if (strcmp(kbuf, "predictive") == 0) {
  358. brake->mode = PREDICT_BRAKE;
  359. } else if (strcmp(kbuf, "auto") == 0) {
  360. brake->mode = AUTO_BRAKE;
  361. } else {
  362. pr_err("%s brake mode is not supported\n", kbuf);
  363. rc = -EINVAL;
  364. }
  365. exit:
  366. kfree(kbuf);
  367. return rc;
  368. }
  369. static const struct file_operations brake_mode_dbgfs_ops = {
  370. .read = brake_mode_dbgfs_read,
  371. .write = brake_mode_dbgfs_write,
  372. .open = simple_open,
  373. };
  374. static int brake_en_dbgfs_read(void *data, u64 *val)
  375. {
  376. struct haptics_effect *effect = data;
  377. *val = !effect->brake->disabled;
  378. return 0;
  379. }
  380. static int brake_en_dbgfs_write(void *data, u64 val)
  381. {
  382. struct haptics_effect *effect = data;
  383. effect->brake->disabled = !val;
  384. return 0;
  385. }
  386. DEFINE_DEBUGFS_ATTRIBUTE(brake_en_dbgfs_ops, brake_en_dbgfs_read,
  387. brake_en_dbgfs_write, "%llu\n");
  388. static int brake_sine_gain_dbgfs_read(void *data, u64 *val)
  389. {
  390. struct haptics_effect *effect = data;
  391. *val = effect->brake->sine_gain;
  392. return 0;
  393. }
  394. static int brake_sine_gain_dbgfs_write(void *data, u64 val)
  395. {
  396. struct haptics_effect *effect = data;
  397. if (val > BRAKE_SINE_GAIN_X8)
  398. return -EINVAL;
  399. effect->brake->sine_gain = val;
  400. return 0;
  401. }
  402. DEFINE_DEBUGFS_ATTRIBUTE(brake_sine_gain_dbgfs_ops,
  403. brake_sine_gain_dbgfs_read,
  404. brake_sine_gain_dbgfs_write, "%llu\n");
  405. static int preload_effect_idx_dbgfs_read(void *data, u64 *val)
  406. {
  407. struct haptics_chip *chip = data;
  408. *val = chip->config.preload_effect;
  409. return 0;
  410. }
  411. static int preload_effect_idx_dbgfs_write(void *data, u64 val)
  412. {
  413. struct haptics_chip *chip = data;
  414. struct haptics_effect *new, *old;
  415. int rc, i;
  416. for (i = 0; i < chip->effects_count; i++)
  417. if (chip->effects[i].id == val)
  418. break;
  419. if (i == chip->effects_count)
  420. return -EINVAL;
  421. new = &chip->effects[i];
  422. for (i = 0; i < chip->effects_count; i++)
  423. if (chip->effects[i].id == chip->config.preload_effect)
  424. break;
  425. old = &chip->effects[i];
  426. chip->config.preload_effect = (u32)val;
  427. new->pattern->preload = true;
  428. new->src = PATTERN2;
  429. rc = haptics_set_pattern(chip, new->pattern, new->src);
  430. if (rc < 0)
  431. return rc;
  432. old->src = PATTERN1;
  433. old->pattern->preload = false;
  434. return 0;
  435. }
  436. DEFINE_DEBUGFS_ATTRIBUTE(preload_effect_idx_dbgfs_ops,
  437. preload_effect_idx_dbgfs_read,
  438. preload_effect_idx_dbgfs_write, "%llu\n");
  439. static int haptics_add_effects_debugfs(struct haptics_effect *effect, struct dentry *dir)
  440. {
  441. struct dentry *file, *pattern_dir, *fifo_dir, *brake_dir;
  442. file = debugfs_create_file_unsafe("vmax_mv", 0644, dir,
  443. effect, &vmax_debugfs_ops);
  444. if (IS_ERR(file))
  445. return PTR_ERR(file);
  446. file = debugfs_create_file_unsafe("lra_auto_res_en", 0644, dir,
  447. effect, &auto_res_en_debugfs_ops);
  448. if (IS_ERR(file))
  449. return PTR_ERR(file);
  450. /* effect can have either pattern or FIFO */
  451. if (effect->pattern) {
  452. pattern_dir = debugfs_create_dir("pattern", dir);
  453. if (IS_ERR(pattern_dir))
  454. return PTR_ERR(pattern_dir);
  455. file = debugfs_create_file("samples", 0644, pattern_dir,
  456. effect, &pattern_s_dbgfs_ops);
  457. if (IS_ERR(file))
  458. return PTR_ERR(file);
  459. file = debugfs_create_file_unsafe("play_rate_us", 0644,
  460. pattern_dir, effect,
  461. &pattern_play_rate_dbgfs_ops);
  462. if (IS_ERR(file))
  463. return PTR_ERR(file);
  464. } else if (effect->fifo) {
  465. fifo_dir = debugfs_create_dir("fifo", dir);
  466. if (IS_ERR(fifo_dir))
  467. return PTR_ERR(fifo_dir);
  468. file = debugfs_create_file("samples", 0644, fifo_dir,
  469. effect, &fifo_s_dbgfs_ops);
  470. if (IS_ERR(file))
  471. return PTR_ERR(file);
  472. file = debugfs_create_file_unsafe("period", 0644, fifo_dir,
  473. effect, &fifo_period_dbgfs_ops);
  474. if (IS_ERR(file))
  475. return PTR_ERR(file);
  476. }
  477. if (effect->brake) {
  478. brake_dir = debugfs_create_dir("brake", dir);
  479. if (IS_ERR(brake_dir))
  480. return PTR_ERR(brake_dir);
  481. file = debugfs_create_file("samples", 0644, brake_dir,
  482. effect, &brake_s_dbgfs_ops);
  483. if (IS_ERR(file))
  484. return PTR_ERR(file);
  485. file = debugfs_create_file("mode", 0644, brake_dir,
  486. effect, &brake_mode_dbgfs_ops);
  487. if (IS_ERR(file))
  488. return PTR_ERR(file);
  489. file = debugfs_create_file_unsafe("enable", 0644, brake_dir,
  490. effect, &brake_en_dbgfs_ops);
  491. if (IS_ERR(file))
  492. return PTR_ERR(file);
  493. file = debugfs_create_file_unsafe("sine_gain", 0644, brake_dir,
  494. effect, &brake_sine_gain_dbgfs_ops);
  495. if (IS_ERR(file))
  496. return PTR_ERR(file);
  497. }
  498. return 0;
  499. }
  500. #define EFFECT_NAME_SIZE 15
  501. static int haptics_add_debugfs(struct dentry *hap_dir, struct haptics_effect *effects,
  502. int count, char *effect_name)
  503. {
  504. struct dentry *effect_dir;
  505. char str[EFFECT_NAME_SIZE] = {0};
  506. int rc = 0;
  507. int i = 0;
  508. for (; i < count; i++) {
  509. scnprintf(str, ARRAY_SIZE(str), "%s%d", effect_name, effects[i].id);
  510. effect_dir = debugfs_create_dir(str, hap_dir);
  511. if (IS_ERR(effect_dir)) {
  512. rc = PTR_ERR(effect_dir);
  513. pr_err("create %s debugfs directory failed, rc=%d\n", str, rc);
  514. return rc;
  515. }
  516. rc = haptics_add_effects_debugfs(&effects[i], effect_dir);
  517. if (rc < 0) {
  518. pr_err("create debugfs nodes for %s failed, rc=%d\n", str, rc);
  519. return rc;
  520. }
  521. }
  522. return rc;
  523. }
  524. void haptics_remove_debugfs(struct haptics_chip *chip)
  525. {
  526. debugfs_remove_recursive(chip->debugfs_dir);
  527. }
  528. int haptics_create_debugfs(struct haptics_chip *chip)
  529. {
  530. struct dentry *hap_dir, *file;
  531. int rc = 0;
  532. hap_dir = debugfs_create_dir("haptics", NULL);
  533. if (IS_ERR(hap_dir)) {
  534. rc = PTR_ERR(hap_dir);
  535. dev_err(chip->dev, "create haptics debugfs directory failed, rc=%d\n",
  536. rc);
  537. return rc;
  538. }
  539. rc = haptics_add_debugfs(hap_dir, chip->effects, chip->effects_count, "effect");
  540. if (rc < 0)
  541. goto exit;
  542. rc = haptics_add_debugfs(hap_dir, chip->primitives, chip->primitives_count, "primitive");
  543. if (rc < 0)
  544. goto exit;
  545. file = debugfs_create_file_unsafe("preload_effect_idx", 0644, hap_dir,
  546. chip, &preload_effect_idx_dbgfs_ops);
  547. if (IS_ERR(file)) {
  548. rc = PTR_ERR(file);
  549. dev_err(chip->dev, "create preload_effect_idx debugfs failed, rc=%d\n",
  550. rc);
  551. goto exit;
  552. }
  553. debugfs_create_u32("fifo_empty_thresh", 0600, hap_dir,
  554. &chip->config.fifo_empty_thresh);
  555. chip->debugfs_dir = hap_dir;
  556. return 0;
  557. exit:
  558. haptics_remove_debugfs(chip);
  559. return rc;
  560. }
  561. #else
  562. static inline void haptics_remove_debugfs(struct haptics_chip *chip)
  563. {
  564. }
  565. static inline int haptics_create_debugfs(struct haptics_chip *chip)
  566. {
  567. return 0;
  568. }
  569. #endif