From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vladimir Gurevich Date: Fri, 07 Feb 2003 21:10:20 -0800 Subject: [U-Boot-Users] [Patch]: A small patch for PPC4xx I2C driver References: <20030208031610.16267.qmail@web13801.mail.yahoo.com> Message-ID: <3E44913C.2020309@paulidav.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 : stwu r1,-16(r1) # Store the return address on the stack 0x7fe8a84 : mflr r0 0x7fe8a88 : stw r0,20(r1) # Store "val" on the stack 0x7fe8a8c : stb r5,8(r1) # Set "alen" to 1 0x7fe8a90 : li r5,1 # set buffer = &val (it is r1+8) 0x7fe8a94 : addi r6,r1,8 # set "len" to 1 0x7fe8a98 : li r7,1 # r3 has i2c_addr, that is chip # r4 has reg # i2c_write(chip, reg, 1, &val, 1) 0x7fe8a9c : bl 0x7fe89a0 # restore the return address 0x7fe8aa0 : lwz r0,20(r1) 0x7fe8aa4 : mtlr r0 # remove the stack frame 0x7fe8aa8 : addi r1,r1,16 #return 0x7fe8aac : blr End of assembler dump. (gdb) Happy hacking, Vladimir