当前位置: 技术问答>linux和unix
求助:如何获得spi寄存器地址,对它进行操作
来源: 互联网 发布时间:2016-07-15
本文导语: 在做一个spi的驱动,但通过查看相关代码后,自己编写了一个获取spi寄存器地址的方法,想通过这个方法对spi寄存器进行配置,但发现运行出错!不知道大家能否帮忙看下~ 我的cpu是AT91SAM9260 以下是我自己编写的代...
在做一个spi的驱动,但通过查看相关代码后,自己编写了一个获取spi寄存器地址的方法,想通过这个方法对spi寄存器进行配置,但发现运行出错!不知道大家能否帮忙看下~
我的cpu是AT91SAM9260
以下是我自己编写的代码:
#define SPI0_ADDR_OFFSET (AT91SAM9260_BASE_SPI0 - AT91_IO_PHYS_BASE)
static inline unsigned int spi_read(unsigned int spi_name,unsigned int reg_offset)
{
void __iomem *SPI0_ADDR = (void __iomem *)(AT91_IO_P2V(AT91_IO_PHYS_BASE)+SPI0_ADDR_OFFSET);
__raw_readl(SPI0_ADDR + (reg_offset));
}
出错如下:
root@at91sam9260:~# ./test
mspi opened
Unable to handle kernel paging request at virtual address fefc8000
pgd = c19dc000
[fefc8000] *pgd=20003051, *pte=00000000, *ppte=00000000
Internal error: Oops: 827 [#3]
Modules linked in: mspi_driver
CPU: 0
PC is at mspi_ioctl+0x1e0/0x230 [mspi_driver]
LR is at do_ioctl+0x74/0x84
pc : [] lr : [] Not tainted
sp : c10fbf30 ip : c10fbf44 fp : c10fbf40
r10: 402d1000 r9 : c10fa000 r8 : c0023084
r7 : 00000000 r6 : 00000101 r5 : ffffffe7 r4 : 00000001
r3 : fefc8000 r2 : 00000000 r1 : 0030181c r0 : 00000100
Flags: nZCv IRQs on FIQs on Mode SVC_32 Segment user
Control: 5317F
Table: 219DC000 DAC: 00000015
Process test (pid: 2178, stack limit = 0xc10fa250)
Stack: (0xc10fbf30 to 0xc10fc000)
bf20: c190d4c0 c10fbf5c c10fbf44 c007ff10
bf40: bf000050 c190d4c0 00000001 00000003 c10fbf84 c10fbf60 c00801b0 c007feac
bf60: c10fbf6c c007377c c190d4c0 fffffff7 00000101 00000036 c10fbfa4 c10fbf88
bf80: c0080210 c007ff30 00000000 40020dd8 00009d18 402d427c 00000000 c10fbfa8
bfa0: c0022ee0 c00801e0 40020dd8 00009d18 00000003 00000101 00000001 00000101
bfc0: 40020dd8 00009d18 402d427c 00000000 00000001 00008a28 402d1000 be9cbd40
bfe0: 0001229c be9cbd24 000091bc 402722e4 60000010 00000003 00000000 00000000
Backtrace:
[] (mspi_ioctl+0x0/0x230 [mspi_driver]) from [] (do_ioctl+0x74/0x84)
r4 = C190D4C0
[] (do_ioctl+0x0/0x84) from [] (vfs_ioctl+0x290/0x2b0)
r6 = 00000003 r5 = 00000001 r4 = C190D4C0
[] (vfs_ioctl+0x0/0x2b0) from [] (sys_ioctl+0x40/0x5c)
r7 = 00000036 r6 = 00000101 r5 = FFFFFFF7 r4 = C190D4C0
[] (sys_ioctl+0x0/0x5c) from [] (ret_fast_syscall+0x0/0x2c)
r6 = 402D427C r5 = 00009D18 r4 = 40020DD8
Code: e7821003 e59f3048 e3500c01 e3a02000 (07832002)
mspi released
Segmentation fault
不知道如何解决?
我的cpu是AT91SAM9260
以下是我自己编写的代码:
#define SPI0_ADDR_OFFSET (AT91SAM9260_BASE_SPI0 - AT91_IO_PHYS_BASE)
static inline unsigned int spi_read(unsigned int spi_name,unsigned int reg_offset)
{
void __iomem *SPI0_ADDR = (void __iomem *)(AT91_IO_P2V(AT91_IO_PHYS_BASE)+SPI0_ADDR_OFFSET);
__raw_readl(SPI0_ADDR + (reg_offset));
}
出错如下:
root@at91sam9260:~# ./test
mspi opened
Unable to handle kernel paging request at virtual address fefc8000
pgd = c19dc000
[fefc8000] *pgd=20003051, *pte=00000000, *ppte=00000000
Internal error: Oops: 827 [#3]
Modules linked in: mspi_driver
CPU: 0
PC is at mspi_ioctl+0x1e0/0x230 [mspi_driver]
LR is at do_ioctl+0x74/0x84
pc : [] lr : [] Not tainted
sp : c10fbf30 ip : c10fbf44 fp : c10fbf40
r10: 402d1000 r9 : c10fa000 r8 : c0023084
r7 : 00000000 r6 : 00000101 r5 : ffffffe7 r4 : 00000001
r3 : fefc8000 r2 : 00000000 r1 : 0030181c r0 : 00000100
Flags: nZCv IRQs on FIQs on Mode SVC_32 Segment user
Control: 5317F
Table: 219DC000 DAC: 00000015
Process test (pid: 2178, stack limit = 0xc10fa250)
Stack: (0xc10fbf30 to 0xc10fc000)
bf20: c190d4c0 c10fbf5c c10fbf44 c007ff10
bf40: bf000050 c190d4c0 00000001 00000003 c10fbf84 c10fbf60 c00801b0 c007feac
bf60: c10fbf6c c007377c c190d4c0 fffffff7 00000101 00000036 c10fbfa4 c10fbf88
bf80: c0080210 c007ff30 00000000 40020dd8 00009d18 402d427c 00000000 c10fbfa8
bfa0: c0022ee0 c00801e0 40020dd8 00009d18 00000003 00000101 00000001 00000101
bfc0: 40020dd8 00009d18 402d427c 00000000 00000001 00008a28 402d1000 be9cbd40
bfe0: 0001229c be9cbd24 000091bc 402722e4 60000010 00000003 00000000 00000000
Backtrace:
[] (mspi_ioctl+0x0/0x230 [mspi_driver]) from [] (do_ioctl+0x74/0x84)
r4 = C190D4C0
[] (do_ioctl+0x0/0x84) from [] (vfs_ioctl+0x290/0x2b0)
r6 = 00000003 r5 = 00000001 r4 = C190D4C0
[] (vfs_ioctl+0x0/0x2b0) from [] (sys_ioctl+0x40/0x5c)
r7 = 00000036 r6 = 00000101 r5 = FFFFFFF7 r4 = C190D4C0
[] (sys_ioctl+0x0/0x5c) from [] (ret_fast_syscall+0x0/0x2c)
r6 = 402D427C r5 = 00009D18 r4 = 40020DD8
Code: e7821003 e59f3048 e3500c01 e3a02000 (07832002)
mspi released
Segmentation fault
不知道如何解决?
|
你使用SPI设备的地址之前有做map吗?在MMU enable的情况下,直接访问物理地址会出page fault,就像你看到的那样。
|
SPI寄存器?是控制该总线的寄存器还是挂在该总线上的设备的寄存器?如果是前者的话,有什么好疑问的,直接操作就是了。如果是后者的话,我就不知道了。
|
不懂 帮顶