blob: 4ff5961cd36f5d2948b8a14b23f5ceb034e18572 [file] [log] [blame]
Alexander Shishkin2c415382015-09-22 15:47:12 +03001/*
2 * A dummy STM device for stm/stm_source class testing.
3 * Copyright (c) 2014, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * STM class implements generic infrastructure for System Trace Module devices
15 * as defined in MIPI STPv2 specification.
16 */
17
18#undef DEBUG
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/slab.h>
22#include <linux/stm.h>
23
24static ssize_t
25dummy_stm_packet(struct stm_data *stm_data, unsigned int master,
26 unsigned int channel, unsigned int packet, unsigned int flags,
27 unsigned int size, const unsigned char *payload)
28{
29#ifdef DEBUG
30 u64 pl = 0;
31
32 if (payload)
33 pl = *(u64 *)payload;
34
35 if (size < 8)
36 pl &= (1ull << (size * 8)) - 1;
37 trace_printk("[%u:%u] [pkt: %x/%x] (%llx)\n", master, channel,
38 packet, size, pl);
39#endif
40 return size;
41}
42
Alexander Shishkinbcfdf8a2016-02-15 19:12:03 +020043#define DUMMY_STM_MAX 32
44
45static struct stm_data dummy_stm[DUMMY_STM_MAX];
46
47static int nr_dummies = 4;
48
49module_param(nr_dummies, int, 0600);
50
51static unsigned int dummy_stm_nr;
Alexander Shishkin2c415382015-09-22 15:47:12 +030052
53static int dummy_stm_init(void)
54{
Alexander Shishkinbcfdf8a2016-02-15 19:12:03 +020055 int i, ret = -ENOMEM, __nr_dummies = ACCESS_ONCE(nr_dummies);
56
57 if (__nr_dummies < 0 || __nr_dummies > DUMMY_STM_MAX)
58 return -EINVAL;
59
60 for (i = 0; i < __nr_dummies; i++) {
61 dummy_stm[i].name = kasprintf(GFP_KERNEL, "dummy_stm.%d", i);
62 if (!dummy_stm[i].name)
63 goto fail_unregister;
64
65 dummy_stm[i].sw_start = 0x0000;
66 dummy_stm[i].sw_end = 0xffff;
67 dummy_stm[i].sw_nchannels = 0xffff;
68 dummy_stm[i].packet = dummy_stm_packet;
69
70 ret = stm_register_device(NULL, &dummy_stm[i], THIS_MODULE);
71 if (ret)
72 goto fail_free;
73 }
74
75 dummy_stm_nr = __nr_dummies;
76
77 return 0;
78
79fail_unregister:
80 for (i--; i >= 0; i--) {
81 stm_unregister_device(&dummy_stm[i]);
82fail_free:
83 kfree(dummy_stm[i].name);
84 }
85
86 return ret;
87
Alexander Shishkin2c415382015-09-22 15:47:12 +030088}
89
90static void dummy_stm_exit(void)
91{
Alexander Shishkinbcfdf8a2016-02-15 19:12:03 +020092 int i;
93
94 for (i = 0; i < dummy_stm_nr; i++) {
95 stm_unregister_device(&dummy_stm[i]);
96 kfree(dummy_stm[i].name);
97 }
Alexander Shishkin2c415382015-09-22 15:47:12 +030098}
99
100module_init(dummy_stm_init);
101module_exit(dummy_stm_exit);
102
103MODULE_LICENSE("GPL v2");
104MODULE_DESCRIPTION("dummy_stm device");
105MODULE_AUTHOR("Alexander Shishkin <alexander.shishkin@linux.intel.com>");