linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Anatolij Gustschin <agust@denx.de>
To: neorf3k <neorf3k@gmail.com>
Cc: linuxppc-dev@lists.ozlabs.org
Subject: Re: Problem reading and programming memory location...
Date: Sat, 16 Nov 2013 15:29:33 +0100	[thread overview]
Message-ID: <20131116152933.276f9939@crub> (raw)
In-Reply-To: <51E043E6-19FB-4655-9B3C-3B81F868DC47@gmail.com>

Hi Lorenzo,

see my comments below.

On Fri, 15 Nov 2013 17:27:30 +0100
neorf3k <neorf3k@gmail.com> wrote:

> Hello again, I=E2=80=99ve tried this code, but we are not able to
> change cs4 reg value=E2=80=A6 what could be?
>=20
> =E2=80=94
>=20
> #define MALab_DEVICE_NAME	"MALab"
> #define MPC5xxx_MM_CS4_START	(MBAR_BASE + 0x0024)
> #define MPC5xxx_MM_CS4_STOP	(MBAR_BASE + 0x0028)
> #define MPC5xxx_MM_IPBI	 (MBAR_BASE + 0x0054)
>=20
> #define MALab_MM_START	 0x10020000U
> #define MALab_MM_END	 0x10020FFFU

Please change MALab_MM_END to 0x10030000U.

> #define MALab_MM_SIZE	 0x00001000U
>=20
> int init_module(void) { ...
>     u16 cs4_start_value;
>     u16 cs4_stop_value;
>     u32 cs4_enable_value;
>    =20
>     u8 rvoice_ioaddr_value;
>=20
>    =20
>     // reserve a page of memory for our hardware /proc/iomem
>     if ( check_region(MALab_MM_START,MALab_MM_SIZE) ) {
>         printk (KERN_ALERT "LED init_module: memory already in use\n");
>         return -EBUSY;
>     }
>=20
>    =20
>     request_mem_region(MALab_MM_START,MALab_MM_SIZE,MALab_DEVICE_NAME);
>=20
>    =20
>     void __iomem *cs0_reg   =3D ioremap ((volatile unsigned long)(MBAR_BA=
SE + 0x0300), 4);
>     void __iomem *cs3_reg   =3D ioremap ((volatile unsigned long)(MBAR_BA=
SE + 0x030C), 4);
>
>     void __iomem *ipbi_cr =3D ioremap ((volatile unsigned long)(MPC5xxx_M=
M_IPBI), 4);
>     void __iomem *cs4_start  =3D ioremap ((volatile unsigned long)(MPC5xx=
x_MM_CS4_START + 2), 2);
>     void __iomem *cs4_stop   =3D ioremap ((volatile unsigned long)(MPC5xx=
x_MM_CS4_STOP + 2), 2);
>    =20
>     void __iomem *cs4_enable   =3D ioremap ((volatile unsigned long)(MBAR=
_BASE + 0x0310), 4);
>     void __iomem *cs_ctrl_reg   =3D ioremap ((volatile unsigned long)(MBA=
R_BASE + 0x0318), 4);


this might work, but this is not how ioremap() supposed to be used.
The mapping is done in 4k-page granularity, so it would be better
to just map the internal register range my one ioremap() call, i.e.

    reg_base =3D ioremap(MBAR_BASE, 0x400);

and then to calculate the register offsets, i.e.

   cs0_reg =3D reg_base + 0x0300;
   cs0_reg =3D reg_base + 0x030C;
   ...
   ipbi_cr =3D reg_base + 0x0054;
   cs4_start =3D reg_base + 0x0026;
   cs4_stop =3D reg_base + 0x002a;
   ...

For FPGA mapping you need a separate ioremap() call of course.

>     void __iomem *rvoice_ioaddr   =3D ioremap ((volatile unsigned long)(M=
ALab_MM_START), MALab_MM_SIZE);
>
>     //disable CSO
>=20
>     out_be32(cs0_reg, 0x0004ed00);
>=20
>    =20
>     //disable CS3
>=20
>     out_be32(cs3_reg, 0x0002cf00);
>=20
>     // enable LocalBus chip select CS4
>     out_be32(ipbi_cr, 0x00290001);

The comment and the code doesn't match here, the code disables
CS4 to configure the its range, so the comment is confusing.

>     cs4_start_value=3Din_be16(cs4_start);
>     cs4_start_value=3DMALab_MM_START >>16;
>     out_be16(cs4_start, cs4_start_value);
>     cs4_stop_value=3Din_be16(cs4_stop);
>     cs4_stop_value=3DMALab_MM_END >>16;
>     out_be16(cs4_stop, cs4_stop_value);

Here is the problem. The _minimal_ chip select range _must_
be 64 KiB, otherwise the register access can't work. Your
current chip select 4 range is less then 1 KiB:

  0x10020FFF - 0x10020000 =3D 0xFFF

Since you right-shift the start and stop values by 16,
the chip select start and stop registers are both 0x1002.
The resulting chip select address range is 0. Therefore
please set MALab_MM_END value to 0x10030000.

Thanks,
Anatolij

  reply	other threads:[~2013-11-16 14:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-12 19:23 Problem reading and programming memory location neorf3k
2013-11-13  7:32 ` Anatolij Gustschin
2013-11-13 13:48   ` neorf3k
2013-11-13 18:06     ` Anatolij Gustschin
2013-11-14  8:38       ` neorf3k
     [not found]         ` <20131114100917.31f674d7@crub>
2013-11-14  9:49           ` neorf3k
2013-11-15 16:27           ` neorf3k
2013-11-16 14:29             ` Anatolij Gustschin [this message]
2013-11-16 15:11               ` neorf3k
2013-11-19 10:20               ` neorf3k
2013-11-19 21:45                 ` Anatolij Gustschin
2013-11-26 18:29                   ` neorf3k

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131116152933.276f9939@crub \
    --to=agust@denx.de \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=neorf3k@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).