hc
2024-11-01 2f529f9b558ca1c1bd74be7437a84e4711743404
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
/*
 * Copyright (C) 2006 Wolfgang Grandegger <wg@grandegger.com>
 *
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
 
#include <linux/module.h>
#include <linux/ioport.h>
#include <linux/delay.h>
 
#include <rtdm/driver.h>
 
/* CAN device profile */
#include "rtcan_dev.h"
#include "rtcan_internal.h"
#include "rtcan_mscan_regs.h"
 
#define MSCAN_REG_ARGS(reg) \
   "%-8s 0x%02x\n", #reg, (int)(in_8(&regs->reg)) & 0xff
 
#ifdef CONFIG_XENO_DRIVERS_CAN_DEBUG
 
static int rtcan_mscan_proc_regs(struct seq_file *p, void *data)
{
   struct rtcan_device *dev = (struct rtcan_device *)data;
   struct mscan_regs *regs = (struct mscan_regs *)dev->base_addr;
#ifdef MPC5xxx_GPIO
   struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5xxx_GPIO;
   u32 port_config;
#endif
   u8 canctl0, canctl1;
 
   seq_printf(p, "MSCAN registers at %p\n", regs);
 
   canctl0 = in_8(&regs->canctl0);
   seq_printf(p, "canctl0  0x%02x%s%s%s%s%s%s%s%s\n",
          canctl0,
          (canctl0 & MSCAN_RXFRM) ? " rxfrm" :"",
          (canctl0 & MSCAN_RXACT) ? " rxact" :"",
          (canctl0 & MSCAN_CSWAI) ? " cswai" :"",
          (canctl0 & MSCAN_SYNCH) ? " synch" :"",
          (canctl0 & MSCAN_TIME)  ? " time"  :"",
          (canctl0 & MSCAN_WUPE)  ? " wupe"  :"",
          (canctl0 & MSCAN_SLPRQ) ? " slprq" :"",
          (canctl0 & MSCAN_INITRQ)? " initrq":"" );
   canctl1 = in_8(&regs->canctl1);
   seq_printf(p, "canctl1  0x%02x%s%s%s%s%s%s%s\n",
          canctl1,
          (canctl1 & MSCAN_CANE)  ? " cane"  :"",
          (canctl1 & MSCAN_CLKSRC)? " clksrc":"",
          (canctl1 & MSCAN_LOOPB) ? " loopb" :"",
          (canctl1 & MSCAN_LISTEN)? " listen":"",
          (canctl1 & MSCAN_WUPM)  ? " wump"  :"",
          (canctl1 & MSCAN_SLPAK) ? " slpak" :"",
          (canctl1 & MSCAN_INITAK)? " initak":"");
   seq_printf(p, MSCAN_REG_ARGS(canbtr0 ));
   seq_printf(p, MSCAN_REG_ARGS(canbtr1 ));
   seq_printf(p, MSCAN_REG_ARGS(canrflg ));
   seq_printf(p, MSCAN_REG_ARGS(canrier ));
   seq_printf(p, MSCAN_REG_ARGS(cantflg ));
   seq_printf(p, MSCAN_REG_ARGS(cantier ));
   seq_printf(p, MSCAN_REG_ARGS(cantarq ));
   seq_printf(p, MSCAN_REG_ARGS(cantaak ));
   seq_printf(p, MSCAN_REG_ARGS(cantbsel));
   seq_printf(p, MSCAN_REG_ARGS(canidac ));
   seq_printf(p, MSCAN_REG_ARGS(canrxerr));
   seq_printf(p, MSCAN_REG_ARGS(cantxerr));
   seq_printf(p, MSCAN_REG_ARGS(canidar0));
   seq_printf(p, MSCAN_REG_ARGS(canidar1));
   seq_printf(p, MSCAN_REG_ARGS(canidar2));
   seq_printf(p, MSCAN_REG_ARGS(canidar3));
   seq_printf(p, MSCAN_REG_ARGS(canidmr0));
   seq_printf(p, MSCAN_REG_ARGS(canidmr1));
   seq_printf(p, MSCAN_REG_ARGS(canidmr2));
   seq_printf(p, MSCAN_REG_ARGS(canidmr3));
   seq_printf(p, MSCAN_REG_ARGS(canidar4));
   seq_printf(p, MSCAN_REG_ARGS(canidar5));
   seq_printf(p, MSCAN_REG_ARGS(canidar6));
   seq_printf(p, MSCAN_REG_ARGS(canidar7));
   seq_printf(p, MSCAN_REG_ARGS(canidmr4));
   seq_printf(p, MSCAN_REG_ARGS(canidmr5));
   seq_printf(p, MSCAN_REG_ARGS(canidmr6));
   seq_printf(p, MSCAN_REG_ARGS(canidmr7));
 
#ifdef MPC5xxx_GPIO
   seq_printf(p, "GPIO registers\n");
   port_config = in_be32(&gpio->port_config);
   seq_printf(p, "port_config 0x%08x %s\n", port_config,
          (port_config & 0x10000000 ?
           "CAN1 on I2C1, CAN2 on TMR0/1 pins" :
           (port_config & 0x70) == 0x10 ?
               "CAN1/2 on PSC2 pins" :
               "MSCAN1/2 not routed"));
#endif
 
   return 0;
}
 
static int rtcan_mscan_proc_regs_open(struct inode *inode, struct file *file)
{
   return single_open(file, rtcan_mscan_proc_regs, PDE_DATA(inode));
}
 
static const DEFINE_PROC_OPS(rtcan_mscan_proc_regs_ops,
           rtcan_mscan_proc_regs_open,
           single_elease,
           seq_read,
           NULL);
 
int rtcan_mscan_create_proc(struct rtcan_device* dev)
{
   if (!dev->proc_root)
       return -EINVAL;
 
   proc_create_data("registers", S_IFREG | S_IRUGO | S_IWUSR,
            dev->proc_root, &rtcan_mscan_proc_regs_ops, dev);
   return 0;
}
 
void rtcan_mscan_remove_proc(struct rtcan_device* dev)
{
   if (!dev->proc_root)
       return;
 
   remove_proc_entry("registers", dev->proc_root);
}
 
#else /* !CONFIG_XENO_DRIVERS_CAN_DEBUG */
 
void rtcan_mscan_remove_proc(struct rtcan_device* dev)
{
}
 
int rtcan_mscan_create_proc(struct rtcan_device* dev)
{
   return 0;
}
#endif    /* CONFIG_XENO_DRIVERS_CAN_DEBUG */