This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to access uncached mscpi->base address from GPIO Driver

Other Parts Discussed in Thread: SYSCONFIG, DM3730

Hi


I am struggling with reading and writing to mcsp registers and I would be grateful if anyone can share an example.

I need to modify and read mcspi2 registers for my GPIO driver and have tried phys_to_virt macro which returns an address which is not same as the virtual address when mcspi2 master is registered.

If I had code the virtual address of mcspi2 at the time of registration and read the registers it returns all 0's

The debug statement shows this

[    0.038635] omap2_mcspi omap2_mcspi.1: r->start 48098000    r->end 480980ff  mcspi->base  cd89936c
[    0.043792] omap2_mcspi omap2_mcspi.1: registered master spi1
[    0.051788] omap2_mcspi omap2_mcspi.2: r->start 4809a000    r->end 4809a0ff  mcspi->base  cd89916c
[    0.056884] omap2_mcspi omap2_mcspi.2: registered master spi2
[    0.063171] spi spi2.0: setup: speed 1500000, sample leading edge, clk normal
[    0.068634] spi spi2.0: setup mode 0, 8 bits/w, 1500000 Hz max --> 0
[    0.073791] omap2_mcspi omap2_mcspi.2: registered child spi2.0
[    0.080169] spi spi2.1: setup: speed 12000000, sample leading edge, clk normal
[    0.085693] spi spi2.1: setup mode 0, 8 bits/w, 12000000 Hz max --> 0
[    0.090820] omap2_mcspi omap2_mcspi.2: registered child spi2.1
[    0.098785] omap2_mcspi omap2_mcspi.3: r->start 480b8000    r->end 480b80ff  mcspi->base  cd8afb6c
[    0.103851] omap2_mcspi omap2_mcspi.3: registered master spi3
[    0.111816] omap2_mcspi omap2_mcspi.4: r->start 480ba000    r->end 480ba0ff  mcspi->base  cd8af96c
[    0.116882] omap2_mcspi omap2_mcspi.4: registered master spi4

this is what i get when i use

*************************************

struct xra1405
{
    struct spi_device *spi;
    struct device *dev;
    struct xra1405_platform_data *pdata;
    struct spi_message *msg[5];
    struct spi_transfer *xfer[18];
    struct mutex    lock;

    int cs_change;
    void __iomem        *base;
    unsigned long        phys;
};

*************************************

struct xra1405 *ts;

ts->base = phys_to_virt(0x4809A000);

On reading registers I get

[    6.230163] xra1405 spi2.1: xra1405->base cdabb938
[    6.238128] READ REGISTER OMAP2_MCSPI_REVISION fa09a000
[    6.246704] READ REGISTER OMAP2_MCSPI_SYSCONFIG 00000000
[    6.255371] READ REGISTER OMAP2_MCSPI_SYSSTATUS 00000000
[    6.264038] READ REGISTER OMAP2_MCSPI_IRQSTATUS 00000000
[    6.272705] READ REGISTER OMAP2_MCSPI_IRQENABLE 00000000
[    6.281555] READ REGISTER OMAP2_MCSPI_WAKEUPENABLE 00000000
[    6.290161] READ REGISTER OMAP2_MCSPI_SYST 00000000
[    6.298370] READ REGISTER OMAP2_MCSPI_MODULCTRL 00000000

Can someone share an exaple of how to access mcspi->base value from specific driver say forexaple GPIO, Touchscreen etc.

Any help would be great.

Thanks

  • Hi Ali,

    Typically we use "ioremap" function to read and write (access) the any MMR registers in kernel driver.

    Ex:

    #define SPI_BASE_ADDR 0x4809A000
    
    #define SPI_IRQSTATUS_OFFSET 00
    
    unsigned int *IRQSTATUS = IRQSTATUS = ioremap(SPI_BASE_ADDR+SPI_IRQSTATUS,4)
    
    printk("IRQSTATUS reg value %p\n",*IRQSTATUS);
    
    iounmap(IRQSTATUS);
  • Hi Titus,

    If I want to use the memory permanently then can I use it by not unmapping it. Is it safe to do so.

    Thanks

  • Hi Ali,

    Just I have given this code snippet for example.

    Generally "iounmap" could be used in "__exit" function.

  • Hi Titus,


    I have just tried the code snippet you sent me.

    After trying the boot process crashes. This is what I did

    #define SPI_BASE_ADDR 0x4809A000
    #define SPI_IRQSTATUS_OFFSET 00
    unsigned int *IRQSTATUS;

    IRQSTATUS = ioremap(SPI_BASE_ADDR+SPI_IRQSTATUS_OFFSET,4);
    printk("IRQSTATUS reg value %p\n",*IRQSTATUS);

    The debug log shows

     Unhandled fault: external abort on non-linefetch (0x1028) at 0xfa09a000
    [    6.239349] Internal error: : 1028 [#1]
    [    6.244720] last sysfs file:
    [    6.249114] Modules linked in:
    [    6.256164] CPU: 0    Not tainted  (2.6.37-00010-g428066e-dirty #136)
    [    6.265136] PC is at xra1405_probe+0x1d8/0x230
    [    6.272033] LR is at xra1405_probe+0x1d0/0x230
    [    6.283111] pc : [<c046720c>]    lr : [<c0467204>]    psr: 80000013
    [    6.283111] sp : cd81be48  ip : 4809a000  fp : cd81be84
    [    6.297882] r10: c04670dc  r9 : 00000080  r8 : c05f0390
    [    6.307128] r7 : 00000000  r6 : 00000016  r5 : cdaa18c0  r4 : cd8afc00
    [    6.317687] r3 : fa09a000  r2 : 00000000  r1 : 00000004  r0 : c0574f28
    [    6.328857] Flags: Nzcv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment kernel
    [    6.339691] Control: 10c5387d  Table: 80004019  DAC: 00000017
    [    6.346862]
    [    6.346862] PC: 0xc046718c:
    [    6.351623] 718c  ea000010 e6ef1076 e1a00004 ebf6883a e1a03006 e1a01004 e2866001 e59f20a4
    [    6.365142] 71ac  e6efc070 e59f0078 e58dc000 ebf7bf0f e3560016 1afffff2 e2877001 e6ef7077
    [    6.378662] 71cc  e357000a 0a000001 e3a06000 eaffffec e5953078 e1a01004 e59f206c e3a07000
    [    6.392181] 71ec  e59f003c ebf7bf01 e3a01004 e1a02007 e59f0058 ebf088a9 e1a03000 e59f0050
    [    6.405731] 720c  e5931000 eb001cf1 ea000001 e1a00005 ebf2d9cb e1a00007 e24bd028 e89daff0
    [    6.419250] 722c  c0574eac c05567a7 c0574eb5 c0574ec6 c0574ece c05fee8c c04670dc c0624120
    [    6.432769] 724c  c0574ef6 c06792dc c0574f00 c0574f17 4809a000 c0574f28 e1a0c00d e92ddff0
    [    6.446319] 726c  e24cb004 e24dd014 e5908050 e1a07000 e2805008 e3580000 1a000004 e1a00005
    [    6.460723]
    [    6.460723] LR: 0xc0467184:
    [    6.465484] 7184  e59f20c4 ebf14279 ea000010 e6ef1076 e1a00004 ebf6883a e1a03006 e1a01004
    [    6.479003] 71a4  e2866001 e59f20a4 e6efc070 e59f0078 e58dc000 ebf7bf0f e3560016 1afffff2
    [    6.492523] 71c4  e2877001 e6ef7077 e357000a 0a000001 e3a06000 eaffffec e5953078 e1a01004
    [    6.506072] 71e4  e59f206c e3a07000 e59f003c ebf7bf01 e3a01004 e1a02007 e59f0058 ebf088a9
    [    6.519592] 7204  e1a03000 e59f0050 e5931000 eb001cf1 ea000001 e1a00005 ebf2d9cb e1a00007
    [    6.533111] 7224  e24bd028 e89daff0 c0574eac c05567a7 c0574eb5 c0574ec6 c0574ece c05fee8c
    [    6.546661] 7244  c04670dc c0624120 c0574ef6 c06792dc c0574f00 c0574f17 4809a000 c0574f28
    [    6.560180] 7264  e1a0c00d e92ddff0 e24cb004 e24dd014 e5908050 e1a07000 e2805008 e3580000
    [    6.574584]
    [    6.574584] SP: 0xcd81bdc8:
    [    6.579345] bdc8  00000080 c04670dc cd81bdf4 cd81bde0 c046e604 c009a624 ffffffff cd81be34
    [    6.592864] bde8  00000016 00000000 cd81be84 cd81be00 c047066c c005e274 c0574f28 00000004
    [    6.606414] be08  00000000 fa09a000 cd8afc00 cdaa18c0 00000016 00000000 c05f0390 00000080
    [    6.619934] be28  c04670dc cd81be84 4809a000 cd81be48 c0467204 c046720c 80000013 ffffffff
    [    6.633453] be48  00000000 00000000 c0259cc0 00000080 cd81be74 cd8afc00 c0601ebc c0601ebc
    [    6.646972] be68  00000000 c0259cc0 00000000 00000080 cd81be94 cd81be88 c02a8158 c0467040
    [    6.660522] be88  cd81bebc cd81be98 c025af28 c02a8144 cd81bebc cd81bea8 c02a848c cd8afc00
    [    6.674041] bea8  cd8afc34 c0601ebc cd81bedc cd81bec0 c025b0a4 c025adf0 c0601ebc cd81bee0
    [    6.688446]
    [    6.688446] FP: 0xcd81be04:
    [    6.693206] be04  00000004 00000000 fa09a000 cd8afc00 cdaa18c0 00000016 00000000 c05f0390
    [    6.706756] be24  00000080 c04670dc cd81be84 4809a000 cd81be48 c0467204 c046720c 80000013
    [    6.720275] be44  ffffffff 00000000 00000000 c0259cc0 00000080 cd81be74 cd8afc00 c0601ebc
    [    6.733795] be64  c0601ebc 00000000 c0259cc0 00000000 00000080 cd81be94 cd81be88 c02a8158
    [    6.747344] be84  c0467040 cd81bebc cd81be98 c025af28 c02a8144 cd81bebc cd81bea8 c02a848c
    [    6.760864] bea4  cd8afc00 cd8afc34 c0601ebc cd81bedc cd81bec0 c025b0a4 c025adf0 c0601ebc
    [    6.774383] bec4  cd81bee0 c025b03c 00000000 cd81bf04 cd81bee0 c025a534 c025b048 cd84fc78
    [    6.787933] bee4  cd8953f0 c0601ebc cdaa1940 c060c874 00000000 cd81bf14 cd81bf08 c025ac4c
    [    6.802337]
    [    6.802337] R0: 0xc0574ea8:
    [    6.807098] 4ea8  0065766f 49206f4e 0a3f5152 206f4e00 74616c50 6d726f66 74614420 50470061
    [    6.820648] 4ec8  33314f49 333c0038 6e61433e 67207427 47207465 314f4950 66203833 5520726f
    [    6.834167] 4ee8  70204253 72207968 74657365 7426000a 6c3e2d73 006b636f 20697073 6d6d6f63
    [    6.847686] 4f08  20646e61 72206425 20646165 78006425 34316172 3e2d3530 65736162 00702520
    [    6.861236] 4f28  53515249 55544154 65722053 61762067 2065756c 000a7025 31617278 00353034
    [    6.874755] 4f48  64256266 616e7500 20656c62 67206f74 6d207465 726f6a61 20642520 20726f66
    [    6.888275] 4f68  64206266 0a737665 61726700 63696870 343c0073 616e553e 20656c62 63206f74
    [    6.901824] 4f88  74616572 62662065 616c6320 203b7373 6e727265 203d206f 0a646c25 6f666f00
    [    6.916229]
    [    6.916229] R3: 0xfa099f80:
    [    6.920989] 9f80  ******** ******** ******** ******** ******** ******** ******** ********
    [    6.934509] 9fa0  ******** ******** ******** ******** ******** ******** ******** ********
    [    6.948059] 9fc0  ******** ******** ******** ******** ******** ******** ******** ********
    [    6.961578] 9fe0  ******** ******** ******** ******** ******** ******** ******** ********
    [    6.975097] a000  ******** ******** ******** ******** ******** ******** ******** ********
    [    6.988647] a020  ******** ******** ******** ******** ******** ******** ******** ********
    [    7.002166] a040  ******** ******** ******** ******** ******** ******** ******** ********
    [    7.015686] a060  ******** ******** ******** ******** ******** ******** ******** ********
    [    7.030090]
    [    7.030120] R4: 0xcd8afb80:
    [    7.034851] fb80  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    [    7.048400] fba0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    [    7.061920] fbc0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    [    7.075439] fbe0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    [    7.088958] fc00  c05e52d0 cd8953c0 cd8a3140 cd8afa0c cd8afe0c c05e52d8 cd81fd40 c0606d60
    [    7.102478] fc20  cd8b0b18 00000003 00000007 00000000 00000000 00000000 cd8afc38 cd8afc38
    [    7.116027] fc40  c060c874 c0601ebc c05f0390 00000000 00000000 00000001 cd8afa58 cd8afe58
    [    7.129547] fc60  7fffffff cd8afc64 cd8afc64 00000000 00000000 00000000 00000000 c0643d40
    [    7.143951]
    [    7.143951] R5: 0xcdaa1840:
    [    7.148712] 1840  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    [    7.162261] 1860  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    [    7.175781] 1880  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    [    7.189300] 18a0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    [    7.202819] 18c0  cd8afc00 cd8afc00 c05f0390 00000000 00000000 00000000 00000000 00000000
    [    7.216369] 18e0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    [    7.229888] 1900  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
    [    7.243408] 1920  00000000 00000000 00000001 cdaa192c cdaa192c 00000000 00000000 00000000
    [    7.257812]
    [    7.257843] R8: 0xc05f0310:
    [    7.262573] 0310  00000000 c05f0314 c05f0314 00000000 00000000 00000000 00000000 00000000
    [    7.276123] 0330  00000000 00000000 00000000 00000000 00000000 00000000 00000000 01010000
    [    7.289642] 0350  00000096 000000b4 0fff0000 0fff0000 00ff0000 0003000a 00000001 00000000
    [    7.303161] 0370  c0084384 00000000 00000000 00000000 00000000 00000001 00000000 00000002
    [    7.316711] 0390  0000888a 00000002 c05596b2 001b7740 0000000b 00011170 00000001 c05f0644
    [    7.330230] 03b0  000000c0 00000180 00000192 00000001 00000000 00000000 00000000 c00844b4
    [    7.343780] 03d0  00000000 00000001 00000001 018cba80 c05f06b8 00000000 00000000 00000000
    [    7.357299] 03f0  00000000 00000000 00000000 001b7740 001b7740 00000000 00000000 0000000a
    [    7.371765]
    [    7.371765] R10: 0xc046705c:
    [    7.376617] 705c  e59f21c8 e59f01c8 e3e07012 ebf7bf63 ea00006b e3580000 1a000003 e59f11b4
    [    7.390136] 707c  e3e07012 ebf7bf15 ea000065 e3a0008a e59f11a4 ebf6835d e3500000 aa000001
    [    7.403686] 709c  e59f0198 eb001d4d e3a01001 e3a0008a ebf682b2 e3a0008a e3a01000 ebf68200
    [    7.417205] 70bc  e3a03008 e1a00004 e5c43122 e3a03000 e5c43121 ebf905c9 e2507000 ba000050
    [    7.430725] 70dc  e59f315c e30810d0 e5936014 e1a00006 ebf2dd6b e59fa14c e1a05000 e1a00006
    [    7.444274] 70fc  ebf2d7df e59f3140 e5932004 e3520000 e1a09000 0a000010 e5936010 e3560000
    [    7.457794] 711c  0a00000d e308c0d0 e58dc004 e3a03080 e58d9000 e1a0100a e5960004 e1a02005
    [    7.471343] 713c  e50bc030 e1a0e00f e596f000 e5b63008 e51bc030 e3530000 1afffff2 e3550000
    [    7.488037] Process swapper (pid: 1, stack limit = 0xcd81a2f0)
    [    7.496490] Stack: (0xcd81be48 to 0xcd81c000)
    [    7.506225] be40:                   00000000 00000000 c0259cc0 00000080 cd81be74 cd8afc00
    [    7.519897] be60: c0601ebc c0601ebc 00000000 c0259cc0 00000000 00000080 cd81be94 cd81be88
    [    7.533599] be80: c02a8158 c0467040 cd81bebc cd81be98 c025af28 c02a8144 cd81bebc cd81bea8
    [    7.547302] bea0: c02a848c cd8afc00 cd8afc34 c0601ebc cd81bedc cd81bec0 c025b0a4 c025adf0
    [    7.560974] bec0: c0601ebc cd81bee0 c025b03c 00000000 cd81bf04 cd81bee0 c025a534 c025b048
    [    7.574676] bee0: cd84fc78 cd8953f0 c0601ebc cdaa1940 c060c874 00000000 cd81bf14 cd81bf08
    [    7.588378] bf00: c025ac4c c025a4ec cd81bf4c cd81bf18 c0259da4 c025ac38 c0574f40 00000000
    [    7.602081] bf20: cd81bf3c c0601ebc c0021bb0 c009cd48 00000000 00000000 00000000 00000000
    [    7.615753] bf40: cd81bf74 cd81bf50 c025b3d8 c0259c84 c003306c c0021bb0 c009cd48 00000000
    [    7.629455] bf60: 00000000 00000000 cd81bf84 cd81bf78 c02a8f58 c025b334 cd81bf94 cd81bf88
    [    7.643127] bf80: c0021bc4 c02a8f18 cd81bfdc cd81bf98 c005e3e0 c0021bbc cd81bfbc 00383034
    [    7.656829] bfa0: 00000000 c0050000 00000199 c05fd5a4 c009cd48 c003306c c0033098 c009cd48
    [    7.670532] bfc0: 00000013 00000000 00000000 00000000 cd81bff4 cd81bfe0 c0008708 c005e314
    [    7.684234] bfe0: 00000000 c0008668 00000000 cd81bff8 c009cd48 c0008674 04080022 00020000
    [    7.693420] Backtrace:
    [    7.701416] [<c0467034>] (xra1405_probe+0x0/0x230) from [<c02a8158>] (spi_drv_probe+0x20/0x24)
    [    7.716156] [<c02a8138>] (spi_drv_probe+0x0/0x24) from [<c025af28>] (driver_probe_device+0x144/0x258)
    [    7.731567] [<c025ade4>] (driver_probe_device+0x0/0x258) from [<c025b0a4>] (__driver_attach+0x68/0x8c)
    [    7.742004]  r6:c0601ebc r5:cd8afc34 r4:cd8afc00
    [    7.754028] [<c025b03c>] (__driver_attach+0x0/0x8c) from [<c025a534>] (bus_for_each_dev+0x54/0x94)
    [    7.764099]  r7:00000000 r6:c025b03c r5:cd81bee0 r4:c0601ebc
    [    7.777862] [<c025a4e0>] (bus_for_each_dev+0x0/0x94) from [<c025ac4c>] (driver_attach+0x20/0x28)
    [    7.787750]  r7:00000000 r6:c060c874 r5:cdaa1940 r4:c0601ebc
    [    7.801483] [<c025ac2c>] (driver_attach+0x0/0x28) from [<c0259da4>] (bus_add_driver+0x12c/0x2b0)
    [    7.816192] [<c0259c78>] (bus_add_driver+0x0/0x2b0) from [<c025b3d8>] (driver_register+0xb0/0x140)
    [    7.831329] [<c025b328>] (driver_register+0x0/0x140) from [<c02a8f58>] (spi_register_driver+0x4c/0x60)
    [    7.841796]  r9:00000000 r8:00000000 r7:00000000 r6:c009cd48 r5:c0021bb0
    [    7.852447] r4:c003306c
    [    7.860870] [<c02a8f0c>] (spi_register_driver+0x0/0x60) from [<c0021bc4>] (xra1405_init+0x14/0x1c)
    [    7.875579] [<c0021bb0>] (xra1405_init+0x0/0x1c) from [<c005e3e0>] (do_one_initcall+0xd8/0x1ac)
    [    7.890014] [<c005e308>] (do_one_initcall+0x0/0x1ac) from [<c0008708>] (kernel_init+0xa0/0x154)
    [    7.903869] [<c0008668>] (kernel_init+0x0/0x154) from [<c009cd48>] (do_exit+0x0/0x638)
    [    7.912872]  r5:c0008668 r4:00000000
    [    7.921142] Code: e59f0058 ebf088a9 e1a03000 e59f0050 (e5931000)
    [    7.930419] ---[ end trace 5cff4efa54947c41 ]---
    [    7.938781] Kernel panic - not syncing: Attempted to kill init!
    [    7.945648] Backtrace:
    [    7.953521] [<c006de1c>] (dump_backtrace+0x0/0x110) from [<c046e458>] (dump_stack+0x18/0x1c)
    [    7.963073]  r7:00000001 r6:cd815ac0 r5:c06331e8 r4:c06331e8
    [    7.976013] [<c046e440>] (dump_stack+0x0/0x1c) from [<c046e4c0>] (panic+0x64/0x180)
    [    7.988494] [<c046e45c>] (panic+0x0/0x180) from [<c009cdc4>] (do_exit+0x7c/0x638)
    [    7.997039]  r3:c05f4278 r2:cd815bf0 r1:00000000 r0:c055c46c
    [    8.009765] [<c009cd48>] (do_exit+0x0/0x638) from [<c006e210>] (die+0x2e4/0x320)
    [    8.022216] [<c006df2c>] (die+0x0/0x320) from [<c006e308>] (arm_notify_die+0x58/0x5c)
    [    8.035797] [<c006e2b0>] (arm_notify_die+0x0/0x5c) from [<c005e2f4>] (do_DataAbort+0x8c/0xa0)
    [    8.049682] [<c005e268>] (do_DataAbort+0x0/0xa0) from [<c047066c>] (__dabt_svc+0x4c/0x60)
    [    8.060913] Exception stack(0xcd81be00 to 0xcd81be48)
    [    8.071166] be00: c0574f28 00000004 00000000 fa09a000 cd8afc00 cdaa18c0 00000016 00000000
    [    8.084716] be20: c05f0390 00000080 c04670dc cd81be84 4809a000 cd81be48 c0467204 c046720c
    [    8.094818] be40: 80000013 ffffffff
    [    8.099212]  r7:00000000 r6:00000016 r5:cd81be34 r4:ffffffff
    [    8.112884] [<c0467034>] (xra1405_probe+0x0/0x230) from [<c02a8158>] (spi_drv_probe+0x20/0x24)
    [    8.127716] [<c02a8138>] (spi_drv_probe+0x0/0x24) from [<c025af28>] (driver_probe_device+0x144/0x258)
    [    8.143157] [<c025ade4>] (driver_probe_device+0x0/0x258) from [<c025b0a4>] (__driver_attach+0x68/0x8c)
    [    8.153625]  r6:c0601ebc r5:cd8afc34 r4:cd8afc00
    [    8.165649] [<c025b03c>] (__driver_attach+0x0/0x8c) from [<c025a534>] (bus_for_each_dev+0x54/0x94)
    [    8.175750]  r7:00000000 r6:c025b03c r5:cd81bee0 r4:c0601ebc
    [    8.189514] [<c025a4e0>] (bus_for_each_dev+0x0/0x94) from [<c025ac4c>] (driver_attach+0x20/0x28)
    [    8.199401]  r7:00000000 r6:c060c874 r5:cdaa1940 r4:c0601ebc
    [    8.213165] [<c025ac2c>] (driver_attach+0x0/0x28) from [<c0259da4>] (bus_add_driver+0x12c/0x2b0)
    [    8.228027] [<c0259c78>] (bus_add_driver+0x0/0x2b0) from [<c025b3d8>] (driver_register+0xb0/0x140)
    [    8.243164] [<c025b328>] (driver_register+0x0/0x140) from [<c02a8f58>] (spi_register_driver+0x4c/0x60)
    [    8.253631]  r9:00000000 r8:00000000 r7:00000000 r6:c009cd48 r5:c0021bb0
    [    8.264312] r4:c003306c
    [    8.272735] [<c02a8f0c>] (spi_register_driver+0x0/0x60) from [<c0021bc4>] (xra1405_init+0x14/0x1c)
    [    8.287445] [<c0021bb0>] (xra1405_init+0x0/0x1c) from [<c005e3e0>] (do_one_initcall+0xd8/0x1ac)
    [    8.301879] [<c005e308>] (do_one_initcall+0x0/0x1ac) from [<c0008708>] (kernel_init+0xa0/0x154)
    [    8.315765] [<c0008668>] (kernel_init+0x0/0x154) from [<c009cd48>] (do_exit+0x0/0x638)
    [    8.324920]  r5:c0008668 r4:00000000

  • Hi Ali,

    I'm very sorry that I have provided the sample code.

    Just I've given some memory address for SPI base address and offset to explain the ioremap concept also I don't know what processor you are using.

    What processor are you suing ?

    You have to use correct SPI BASE address and appropriate offset address for registers from data sheet and TRM.

  • Hi Titus,

    No that's fine I have been working on the same lines before.

    The SPI_BASE_ADDRESS is correct as I am using DM3730 processor and MCSPI2 is at address 0x4809A000

    So I am not really sure whats going on here?

  • Hi Ali,

    Try the sample kernel module driver to read the SPI2 register.

    I hope that you know how to build kernel module driver with this code.

    1) Create Makefile and put entry for the kernel code

    obj-m += sample.c

    2) Build

    To build

    make -C <kernel source dir> -M=`pwd` modules

    To clean

    make -C <kernel source dir> -M=`pwd` clean

    3) You would get "sample.ko" after successful build

    Note that you may get the error from include section since I have used this code for the latest kernel code so change the include files appropriately.

    /*
     * Sample driver
     *
     * This file is subject to the terms and conditions of the GNU General Public
     * License.
     *
     * AUTHOR : Titusrathinaraj Stalin
     * EMAIL  : x0213399@ti.com
     *	
     */
    
    
    
    /* Include linux kernel header files */
    #include <linux/kernel.h>
    #include <linux/module.h>
    #include <linux/fs.h>
    #include <linux/cdev.h>
    #include <asm/uaccess.h>
    #include <linux/device.h>
    #include <asm/gpio.h>
    #include <linux/interrupt.h>
    #include <asm/irq.h>
    #include <linux/sched.h>
    #include <linux/irq.h>
    #include <linux/delay.h>
    #include<linux/proc_fs.h>  // Required for proc entry creation
    
    #include <linux/mm.h>
    
    #include <linux/io.h>
    
    #include <linux/slab.h>
    
    #include <linux/kernel.h>
    #include <linux/module.h>
    #include <linux/fs.h>
    #include <linux/cdev.h>
    #include <asm/uaccess.h>
    #include <linux/device.h>
    #include <asm/gpio.h>
    #include <linux/interrupt.h>
    #include <asm/irq.h>
    #include <linux/sched.h>
    #include <linux/irq.h>
    #include <linux/delay.h>
    
    MODULE_LICENSE("GPL");
    MODULE_AUTHOR("Titus S");
    MODULE_DESCRIPTION("Sample driver");
    
    #define SPI2_BASE_ADDR 0x4809A000
    #define SPI_MODULECTRL_OFFSET 0x28
    
    
    int sample_init(void)
    {
    	unsigned int *SPI2_MODULECTRL = SPI2_MODULECTRL = ioremap(SPI2_BASE_ADDR+SPI2_MODULECTRL_OFFSET,4); //SPI2_MODULECTRL_OFFSET
    
    	printk(KERN_ALERT "sample driver is inserted sucessfully SPI2_MODULECTRL register %p\n",*SPI2_MODULECTRL);
    
    	return 0;
    
    }
    
    void sample_exit(void)
    {
    	printk(KERN_ALERT "sample driver is ejected sucessfully...\n");
    }
    
    /* Register driver to the kernel */
    module_init(sample_init);
    module_exit(sample_exit);
    

    make -C <kernel source dir> -M=`pwd` modules

  • Hi Titus,


    Thanks for that. I'll try that and let you know.

    Regards

    Ali

  • Hi Ali,

    Just to ensure, try the following.

    You can also use "devmem" or "devmem2" to read the MMR (memory mapped register) registers in user space through linux commands.

    devmem2 0x4809A028

    devmem 0x4809A028