From: Vladimir Gurevich <vag@paulidav.org>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] [Patch]: A small patch for PPC4xx I2C driver
Date: Fri, 07 Feb 2003 21:10:20 -0800 [thread overview]
Message-ID: <3E44913C.2020309@paulidav.org> (raw)
In-Reply-To: 20030208031610.16267.qmail@web13801.mail.yahoo.com
Hi Frank,
This code has been copied verbatim from common/soft_i2c.c
and is identical to the implementations in other drivers like
cpu/mpc8260/i2c.c for example. It is done this way
because the prototype for i2c_write is
int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len);
As you can see it requires an address of the buffer.
Since this is a real function and not a macro,
it will always work even if the actual parameter is
a literal, there is nothing wrong about it. Because the
prototype is
void i2c_reg_write(uchar i2c_addr, uchar reg, uchar val)
you don't have to pass an address of a value,
just the value itself.
If you look at the code that the compiler generates,
youll see it does the right thing (comments are mine):
(gdb) disas i2c_reg_write
Dump of assembler code for function i2c_reg_write:
# Make a stack frame
0x7fe8a80 <i2c_reg_write>: stwu r1,-16(r1)
# Store the return address on the stack
0x7fe8a84 <i2c_reg_write+4>: mflr r0
0x7fe8a88 <i2c_reg_write+8>: stw r0,20(r1)
# Store "val" on the stack
0x7fe8a8c <i2c_reg_write+12>: stb r5,8(r1)
# Set "alen" to 1
0x7fe8a90 <i2c_reg_write+16>: li r5,1
# set buffer = &val (it is r1+8)
0x7fe8a94 <i2c_reg_write+20>: addi r6,r1,8
# set "len" to 1
0x7fe8a98 <i2c_reg_write+24>: li r7,1
# r3 has i2c_addr, that is chip
# r4 has reg
# i2c_write(chip, reg, 1, &val, 1)
0x7fe8a9c <i2c_reg_write+28>: bl 0x7fe89a0 <i2c_write>
# restore the return address
0x7fe8aa0 <i2c_reg_write+32>: lwz r0,20(r1)
0x7fe8aa4 <i2c_reg_write+36>: mtlr r0
# remove the stack frame
0x7fe8aa8 <i2c_reg_write+40>: addi r1,r1,16
#return
0x7fe8aac <i2c_reg_write+44>: blr
End of assembler dump.
(gdb)
Happy hacking,
Vladimir
next prev parent reply other threads:[~2003-02-08 5:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-02-08 1:33 [U-Boot-Users] [Patch]: A small patch for PPC4xx I2C driver Vladimir Gurevich
2003-02-08 3:16 ` Frank
2003-02-08 5:10 ` Vladimir Gurevich [this message]
2003-02-08 9:45 ` Wolfgang Denk
2003-03-06 20:14 ` Wolfgang Denk
2003-03-06 20:25 ` Vladimir Gurevich
2003-03-06 20:47 ` [U-Boot-Users] MC68360 Port Reinhard Meyer
2003-03-06 21:49 ` Wolfgang Denk
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=3E44913C.2020309@paulidav.org \
--to=vag@paulidav.org \
--cc=u-boot@lists.denx.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.