1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
|
/*
* hsi_driver_debugfs.c
*
* Implements HSI debugfs.
*
* Copyright (C) 2007-2008 Nokia Corporation. All rights reserved.
* Copyright (C) 2009 Texas Instruments, Inc.
*
* Author: Carlos Chinea <carlos.chinea@nokia.com>
* Author: Sebastien JAN <s-jan@ti.com>
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <linux/err.h>
#include <linux/list.h>
#include <linux/uaccess.h>
#include <linux/ctype.h>
#include "hsi_driver.h"
#define HSI_DIR_NAME_SIZE 64
static struct dentry *hsi_dir;
static int hsi_debug_show(struct seq_file *m, void *p)
{
struct hsi_dev *hsi_ctrl = m->private;
struct platform_device *pdev = to_platform_device(hsi_ctrl->dev);
hsi_clocks_enable(hsi_ctrl->dev, __func__);
seq_printf(m, "REVISION\t: 0x%08x\n",
hsi_inl(hsi_ctrl->base, HSI_SYS_REVISION_REG));
if (hsi_driver_device_is_hsi(pdev))
seq_printf(m, "HWINFO\t\t: 0x%08x\n",
hsi_inl(hsi_ctrl->base, HSI_SYS_HWINFO_REG));
seq_printf(m, "SYSCONFIG\t: 0x%08x\n",
hsi_inl(hsi_ctrl->base, HSI_SYS_SYSCONFIG_REG));
seq_printf(m, "SYSSTATUS\t: 0x%08x\n",
hsi_inl(hsi_ctrl->base, HSI_SYS_SYSSTATUS_REG));
hsi_clocks_disable(hsi_ctrl->dev, __func__);
return 0;
}
static int hsi_debug_port_show(struct seq_file *m, void *p)
{
struct hsi_port *hsi_port = m->private;
struct hsi_dev *hsi_ctrl = hsi_port->hsi_controller;
void __iomem *base = hsi_ctrl->base;
unsigned int port = hsi_port->port_number;
int ch, fifo;
long buff_offset;
struct platform_device *pdev = to_platform_device(hsi_ctrl->dev);
hsi_clocks_enable(hsi_ctrl->dev, __func__);
if (hsi_port->cawake_gpio >= 0)
seq_printf(m, "CAWAKE\t\t: %d\n", hsi_get_cawake(hsi_port));
seq_printf(m, "WAKE\t\t: 0x%08x\n",
hsi_inl(base, HSI_SYS_WAKE_REG(port)));
seq_printf(m, "MPU_ENABLE_IRQ%d\t: 0x%08x\n", hsi_port->n_irq,
hsi_inl(base,
HSI_SYS_MPU_ENABLE_REG(port, hsi_port->n_irq)));
seq_printf(m, "MPU_STATUS_IRQ%d\t: 0x%08x\n", hsi_port->n_irq,
hsi_inl(base,
HSI_SYS_MPU_STATUS_REG(port, hsi_port->n_irq)));
if (hsi_driver_device_is_hsi(pdev)) {
seq_printf(m, "MPU_U_ENABLE_IRQ%d\t: 0x%08x\n",
hsi_port->n_irq,
hsi_inl(base, HSI_SYS_MPU_U_ENABLE_REG(port,
hsi_port->n_irq)));
seq_printf(m, "MPU_U_STATUS_IRQ%d\t: 0x%08x\n", hsi_port->n_irq,
hsi_inl(base,
HSI_SYS_MPU_U_STATUS_REG(port,
hsi_port->n_irq)));
}
/* HST */
seq_printf(m, "\nHST\n===\n");
seq_printf(m, "MODE\t\t: 0x%08x\n",
hsi_inl(base, HSI_HST_MODE_REG(port)));
seq_printf(m, "FRAMESIZE\t: 0x%08x\n",
hsi_inl(base, HSI_HST_FRAMESIZE_REG(port)));
seq_printf(m, "DIVISOR\t\t: 0x%08x\n",
hsi_inl(base, HSI_HST_DIVISOR_REG(port)));
seq_printf(m, "CHANNELS\t: 0x%08x\n",
hsi_inl(base, HSI_HST_CHANNELS_REG(port)));
seq_printf(m, "ARBMODE\t\t: 0x%08x\n",
hsi_inl(base, HSI_HST_ARBMODE_REG(port)));
seq_printf(m, "TXSTATE\t\t: 0x%08x\n",
hsi_inl(base, HSI_HST_TXSTATE_REG(port)));
if (hsi_driver_device_is_hsi(pdev)) {
seq_printf(m, "BUFSTATE P1\t: 0x%08x\n",
hsi_inl(base, HSI_HST_BUFSTATE_REG(1)));
seq_printf(m, "BUFSTATE P2\t: 0x%08x\n",
hsi_inl(base, HSI_HST_BUFSTATE_REG(2)));
} else {
seq_printf(m, "BUFSTATE\t: 0x%08x\n",
hsi_inl(base, HSI_HST_BUFSTATE_REG(port)));
}
seq_printf(m, "BREAK\t\t: 0x%08x\n",
hsi_inl(base, HSI_HST_BREAK_REG(port)));
for (ch = 0; ch < 8; ch++) {
buff_offset = hsi_hst_buffer_reg(hsi_ctrl, port, ch);
if (buff_offset >= 0)
seq_printf(m, "BUFFER_CH%d\t: 0x%08x\n", ch,
hsi_inl(base, buff_offset));
}
if (hsi_driver_device_is_hsi(pdev)) {
for (fifo = 0; fifo < HSI_HST_FIFO_COUNT; fifo++) {
seq_printf(m, "FIFO MAPPING%d\t: 0x%08x\n", fifo,
hsi_inl(base,
HSI_HST_MAPPING_FIFO_REG(fifo)));
}
}
/* HSR */
seq_printf(m, "\nHSR\n===\n");
seq_printf(m, "MODE\t\t: 0x%08x\n",
hsi_inl(base, HSI_HSR_MODE_REG(port)));
seq_printf(m, "FRAMESIZE\t: 0x%08x\n",
hsi_inl(base, HSI_HSR_FRAMESIZE_REG(port)));
seq_printf(m, "CHANNELS\t: 0x%08x\n",
hsi_inl(base, HSI_HSR_CHANNELS_REG(port)));
seq_printf(m, "COUNTERS\t: 0x%08x\n",
hsi_inl(base, HSI_HSR_COUNTERS_REG(port)));
seq_printf(m, "RXSTATE\t\t: 0x%08x\n",
hsi_inl(base, HSI_HSR_RXSTATE_REG(port)));
if (hsi_driver_device_is_hsi(pdev)) {
seq_printf(m, "BUFSTATE P1\t: 0x%08x\n",
hsi_inl(base, HSI_HSR_BUFSTATE_REG(1)));
seq_printf(m, "BUFSTATE P2\t: 0x%08x\n",
hsi_inl(base, HSI_HSR_BUFSTATE_REG(2)));
} else {
seq_printf(m, "BUFSTATE\t: 0x%08x\n",
hsi_inl(base, HSI_HSR_BUFSTATE_REG(port)));
}
seq_printf(m, "BREAK\t\t: 0x%08x\n",
hsi_inl(base, HSI_HSR_BREAK_REG(port)));
seq_printf(m, "ERROR\t\t: 0x%08x\n",
hsi_inl(base, HSI_HSR_ERROR_REG(port)));
seq_printf(m, "ERRORACK\t: 0x%08x\n",
hsi_inl(base, HSI_HSR_ERRORACK_REG(port)));
for (ch = 0; ch < 8; ch++) {
buff_offset = hsi_hsr_buffer_reg(hsi_ctrl, port, ch);
if (buff_offset >= 0)
seq_printf(m, "BUFFER_CH%d\t: 0x%08x\n", ch,
hsi_inl(base, buff_offset));
}
if (hsi_driver_device_is_hsi(pdev)) {
for (fifo = 0; fifo < HSI_HSR_FIFO_COUNT; fifo++) {
seq_printf(m, "FIFO MAPPING%d\t: 0x%08x\n", fifo,
hsi_inl(base,
HSI_HSR_MAPPING_FIFO_REG(fifo)));
}
seq_printf(m, "DLL\t: 0x%08x\n",
hsi_inl(base, HSI_HSR_DLL_REG));
seq_printf(m, "DIVISOR\t: 0x%08x\n",
hsi_inl(base, HSI_HSR_DIVISOR_REG(port)));
}
hsi_clocks_disable(hsi_ctrl->dev, __func__);
return 0;
}
static int hsi_debug_gdd_show(struct seq_file *m, void *p)
{
struct hsi_dev *hsi_ctrl = m->private;
void __iomem *base = hsi_ctrl->base;
int lch;
struct platform_device *pdev = to_platform_device(hsi_ctrl->dev);
hsi_clocks_enable(hsi_ctrl->dev, __func__);
seq_printf(m, "GDD_MPU_STATUS\t: 0x%08x\n",
hsi_inl(base, HSI_SYS_GDD_MPU_IRQ_STATUS_REG));
seq_printf(m, "GDD_MPU_ENABLE\t: 0x%08x\n\n",
hsi_inl(base, HSI_SYS_GDD_MPU_IRQ_ENABLE_REG));
if (!hsi_driver_device_is_hsi(pdev)) {
seq_printf(m, "HW_ID\t\t: 0x%08x\n",
hsi_inl(base, HSI_SSI_GDD_HW_ID_REG));
seq_printf(m, "PPORT_ID\t: 0x%08x\n",
hsi_inl(base, HSI_SSI_GDD_PPORT_ID_REG));
seq_printf(m, "MPORT_ID\t: 0x%08x\n",
hsi_inl(base, HSI_SSI_GDD_MPORT_ID_REG));
seq_printf(m, "TEST\t\t: 0x%08x\n",
hsi_inl(base, HSI_SSI_GDD_TEST_REG));
}
seq_printf(m, "GCR\t\t: 0x%08x\n", hsi_inl(base, HSI_GDD_GCR_REG));
for (lch = 0; lch < hsi_ctrl->gdd_chan_count; lch++) {
seq_printf(m, "\nGDD LCH %d\n=========\n", lch);
seq_printf(m, "CSDP\t\t: 0x%04x\n",
hsi_inw(base, HSI_GDD_CSDP_REG(lch)));
seq_printf(m, "CCR\t\t: 0x%04x\n",
hsi_inw(base, HSI_GDD_CCR_REG(lch)));
seq_printf(m, "CICR\t\t: 0x%04x\n",
hsi_inw(base, HSI_GDD_CCIR_REG(lch)));
seq_printf(m, "CSR\t\t: 0x%04x\n",
hsi_inw(base, HSI_GDD_CSR_REG(lch)));
seq_printf(m, "CSSA\t\t: 0x%08x\n",
hsi_inl(base, HSI_GDD_CSSA_REG(lch)));
seq_printf(m, "CDSA\t\t: 0x%08x\n",
hsi_inl(base, HSI_GDD_CDSA_REG(lch)));
seq_printf(m, "CEN\t\t: 0x%04x\n",
hsi_inw(base, HSI_GDD_CEN_REG(lch)));
seq_printf(m, "CSAC\t\t: 0x%04x\n",
hsi_inw(base, HSI_GDD_CSAC_REG(lch)));
seq_printf(m, "CDAC\t\t: 0x%04x\n",
hsi_inw(base, HSI_GDD_CDAC_REG(lch)));
if (!hsi_driver_device_is_hsi(pdev))
seq_printf(m, "CLNK_CTRL\t: 0x%04x\n",
hsi_inw(base,
HSI_SSI_GDD_CLNK_CTRL_REG(lch)));
}
hsi_clocks_disable(hsi_ctrl->dev, __func__);
return 0;
}
static int hsi_port_counters_open(struct inode *inode, struct file *file)
{
file->private_data = inode->i_private;
return 0;
}
static int hsi_port_counters_release(struct inode *inode, struct file *file)
{
return 0;
}
static loff_t hsi_port_counters_seek(struct file *file, loff_t off, int whence)
{
return 0;
}
static ssize_t hsi_port_counters_read(struct file *filep, char __user * buff,
size_t count, loff_t *offp)
{
ssize_t ret;
struct hsi_port *hsi_port = filep->private_data;
struct hsi_dev *hsi_ctrl = hsi_port->hsi_controller;
void __iomem *base = hsi_ctrl->base;
unsigned int port = hsi_port->port_number;
struct platform_device *pdev = to_platform_device(hsi_ctrl->dev);
char str[50];
unsigned long reg;
if (*offp > 0) {
ret = 0;
goto hsi_cnt_rd_bk;
}
hsi_clocks_enable(hsi_ctrl->dev, __func__);
reg = hsi_inl(base, HSI_HSR_COUNTERS_REG(port));
hsi_clocks_disable(hsi_ctrl->dev, __func__);
if (hsi_driver_device_is_hsi(pdev)) {
sprintf(str, "FT:%d, TB:%d, FB:%d\n",
(int)(reg & HSI_COUNTERS_FT_MASK) >>
HSI_COUNTERS_FT_OFFSET,
(int)(reg & HSI_COUNTERS_TB_MASK) >>
HSI_COUNTERS_TB_OFFSET,
(int)(reg & HSI_COUNTERS_FB_MASK) >>
HSI_COUNTERS_FB_OFFSET);
} else {
sprintf(str, "timeout:%d\n", (int)reg);
}
ret = strlen(str);
if (copy_to_user((void __user *)buff, str, ret)) {
dev_err(hsi_ctrl->dev, "copy_to_user failed\n");
ret = 0;
} else {
*offp = ret;
}
hsi_cnt_rd_bk:
return ret;
}
/*
* Split the buffer `buf' into space-separated words.
* Return the number of words or <0 on error.
*/
static int hsi_debug_tokenize(char *buf, char *words[], int maxwords)
{
int nwords = 0;
while (*buf) {
char *end;
/* Skip leading whitespace */
while (*buf && isspace(*buf))
buf++;
if (!*buf)
break; /* oh, it was trailing whitespace */
/* Run `end' over a word */
for (end = buf; *end && !isspace(*end); end++)
;
/* `buf' is the start of the word, `end' is one past the end */
if (nwords == maxwords)
return -EINVAL; /* ran out of words[] before bytes */
if (*end)
*end++ = '\0'; /* terminate the word */
words[nwords++] = buf;
buf = end;
}
return nwords;
}
static ssize_t hsi_port_counters_write(struct file *filep,
const char __user *buff, size_t count,
loff_t *offp)
{
ssize_t ret;
struct hsi_port *hsi_port = filep->private_data;
struct hsi_dev *hsi_ctrl = hsi_port->hsi_controller;
void __iomem *base = hsi_ctrl->base;
unsigned int port = hsi_port->port_number;
struct platform_device *pdev = to_platform_device(hsi_ctrl->dev);
#define MAXWORDS 4
int nwords;
char *words[MAXWORDS];
char tmpbuf[256];
unsigned long reg, ft, tb, fb;
if (count == 0)
return 0;
if (count > sizeof(tmpbuf) - 1)
return -E2BIG;
if (copy_from_user(tmpbuf, buff, count))
return -EFAULT;
tmpbuf[count] = '\0';
dev_dbg(hsi_ctrl->dev, "%s: read %d bytes from userspace\n",
__func__, (int)count);
nwords = hsi_debug_tokenize(tmpbuf, words, MAXWORDS);
if (nwords < 0) {
dev_warn(hsi_ctrl->dev,
"HSI counters write usage: echo <values> > counters\n");
return -EINVAL;
}
hsi_clocks_enable(hsi_ctrl->dev, __func__);
if (hsi_driver_device_is_hsi(pdev)) {
if (nwords != 3) {
dev_warn(hsi_ctrl->dev, "HSI counters write usage: "
"echo \"FT TB FB\" > counters\n");
ret = -EINVAL;
goto hsi_cnt_w_bk1;
}
strict_strtoul(words[0], 0, &ft);
strict_strtoul(words[1], 0, &tb);
strict_strtoul(words[2], 0, &fb);
reg = ((ft << HSI_COUNTERS_FT_OFFSET & HSI_COUNTERS_FT_MASK) |
(tb << HSI_COUNTERS_TB_OFFSET & HSI_COUNTERS_TB_MASK) |
(fb << HSI_COUNTERS_FB_OFFSET & HSI_COUNTERS_FB_MASK));
} else {
if (nwords != 1) {
dev_warn(hsi_ctrl->dev, "HSI counters write usage: "
"echo \"timeout\" > counters\n");
ret = -EINVAL;
goto hsi_cnt_w_bk1;
}
strict_strtoul(words[0], 0, ®);
}
hsi_outl(reg, base, HSI_HSR_COUNTERS_REG(port));
ret = count;
*offp += count;
hsi_cnt_w_bk1:
hsi_clocks_disable(hsi_ctrl->dev, __func__);
return ret;
}
static int hsi_regs_open(struct inode *inode, struct file *file)
{
return single_open(file, hsi_debug_show, inode->i_private);
}
static int hsi_port_regs_open(struct inode *inode, struct file *file)
{
return single_open(file, hsi_debug_port_show, inode->i_private);
}
static int hsi_gdd_regs_open(struct inode *inode, struct file *file)
{
return single_open(file, hsi_debug_gdd_show, inode->i_private);
}
static const struct file_operations hsi_regs_fops = {
.open = hsi_regs_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static const struct file_operations hsi_port_regs_fops = {
.open = hsi_port_regs_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
static const struct file_operations hsi_port_counters_fops = {
.open = hsi_port_counters_open,
.read = hsi_port_counters_read,
.write = hsi_port_counters_write,
.llseek = hsi_port_counters_seek,
.release = hsi_port_counters_release,
};
static const struct file_operations hsi_gdd_regs_fops = {
.open = hsi_gdd_regs_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
int __init hsi_debug_add_ctrl(struct hsi_dev *hsi_ctrl)
{
struct platform_device *pdev = to_platform_device(hsi_ctrl->dev);
unsigned char dir_name[HSI_DIR_NAME_SIZE];
struct dentry *dir;
unsigned int port;
if (pdev->id < 0) {
hsi_ctrl->dir = debugfs_create_dir(pdev->name, hsi_dir);
} else {
snprintf(dir_name, sizeof(dir_name), "%s%d", pdev->name,
pdev->id);
hsi_ctrl->dir = debugfs_create_dir(dir_name, hsi_dir);
}
if (IS_ERR(hsi_ctrl->dir))
return PTR_ERR(hsi_ctrl->dir);
debugfs_create_file("regs", S_IRUGO, hsi_ctrl->dir, hsi_ctrl,
&hsi_regs_fops);
for (port = 0; port < hsi_ctrl->max_p; port++) {
snprintf(dir_name, sizeof(dir_name), "port%d", port + 1);
dir = debugfs_create_dir(dir_name, hsi_ctrl->dir);
if (IS_ERR(dir))
goto rback;
debugfs_create_file("regs", S_IRUGO, dir,
&hsi_ctrl->hsi_port[port],
&hsi_port_regs_fops);
debugfs_create_file("counters", S_IRUGO | S_IWUGO, dir,
&hsi_ctrl->hsi_port[port],
&hsi_port_counters_fops);
}
dir = debugfs_create_dir("gdd", hsi_ctrl->dir);
if (IS_ERR(dir))
goto rback;
debugfs_create_file("regs", S_IRUGO, dir, hsi_ctrl, &hsi_gdd_regs_fops);
return 0;
rback:
debugfs_remove_recursive(hsi_ctrl->dir);
return PTR_ERR(dir);
}
void hsi_debug_remove_ctrl(struct hsi_dev *hsi_ctrl)
{
debugfs_remove_recursive(hsi_ctrl->dir);
}
int __init hsi_debug_init(void)
{
hsi_dir = debugfs_create_dir("hsi", NULL);
if (IS_ERR(hsi_dir))
return PTR_ERR(hsi_dir);
return 0;
}
void hsi_debug_exit(void)
{
debugfs_remove_recursive(hsi_dir);
}
|