<HTML dir=ltr><HEAD><TITLE>PowerPC 460EX AD7416 Temperature Sensor</TITLE>
<META http-equiv=Content-Type content="text/html; charset=unicode">
<META content="MSHTML 6.00.6000.16788" name=GENERATOR></HEAD>
<BODY>
<DIV id=idOWAReplyText836 dir=ltr>
<DIV dir=ltr><FONT face=Arial color=#000000 size=2>Did you have dts entries for IIC in device tree ? also did you have I2C enabled in "make menuconfig" </FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2>"device drivers -> i2c support --> I2C bus support -> IBM ppc 4xx On chip I2C support " selected. Then you should i2c see an entry /proc/devices . Use that major address and create a device node "mknode /dev/i2c-0 c 89 0" .</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>Write a user level program to access this device. Here is an example user code.</FONT></DIV>
<DIV dir=ltr><FONT face=Arial size=2></FONT> </DIV>
<DIV dir=ltr><FONT face=Arial size=2>----------</FONT></DIV>
<DIV dir=ltr>cat fan.c<BR>/* This program is an example of writing and reading an EEPROM device via<BR> SMBus on a GE Fanuc Embedded Systems, Inc. VMIVME-7809 Single Board<BR> Computer.</DIV>
<DIV dir=ltr> To compile this program:</DIV>
<DIV dir=ltr> gcc -O vmieep.c -o vmieep</DIV>
<DIV dir=ltr><BR> Before running this program, log in as root, then load the following<BR> modules using:</DIV>
<DIV dir=ltr> /sbin/modprobe i2c-core<BR> /sbin/modprobe i2c-dev<BR> /sbin/modprobe i2c-i801</DIV>
<DIV dir=ltr> Loading the i2c-i801 module will create /dev/i2c-0, with<BR> permissions = CRW- --- ---. Either run the vmieep program as root,<BR> or change the permissions to CRW- RW- RW- as shown:</DIV>
<DIV dir=ltr> chmod 666 /dev/i2c-0</DIV>
<DIV dir=ltr>*/</DIV>
<DIV dir=ltr><BR>#include <stdio.h><BR>#include <string.h><BR>#include <stdlib.h><BR>#include <errno.h><BR>#include <fcntl.h><BR>//#include <linux/i2c.h><BR>//#include <linux/i2c-dev.h><BR>#include <sys/time.h></DIV>
<DIV dir=ltr><BR>/* The inline smbus function definitions may or may not be in i2c-dev.h,<BR> depending on the Linux distribution. Comment or uncomment the following<BR> #include as necessary. */<BR>#include "i2c-dev.h" /* Use the file of lm_sensors */</DIV>
<DIV dir=ltr><BR>#define EEPROM_SIZE 256 /* Adjust for actual number of bytes in EEPROM */<BR>#define EEPROM_SMBUS_ADDR 0x90 /* Do NOT change! */</DIV>
<DIV dir=ltr>int gef_eeprom_read(int fd, unsigned char start_offset, unsigned char *buffer,<BR> unsigned short buflen);<BR>int gef_eeprom_write(int fd, unsigned char start_offset, unsigned char *buffer,<BR> unsigned short buflen);<BR>void gef_msec_delay(unsigned int msecs);</DIV>
<DIV dir=ltr><BR>int main(int argc, char *argv[])<BR>{<BR> int fd; /* File descriptor initialized with open() */<BR> int adapter_num = 0;<BR> int status;<BR> char filename[20]; /* Name of special device file */<BR> int i2c_addr = EEPROM_SMBUS_ADDR; /* SMBus address of EEPROM */<BR> unsigned short offset; /* Which byte to access in the EEPROM */<BR> unsigned char rbuffer; /* Data read from EEPROM */</DIV>
<DIV dir=ltr> if ((argc < 3) || (argc > 4))<BR> {<BR> printf("Usage: fan read <addr> or fan write <addr> <data>\n");<BR> return 0;<BR> }<BR> /* Open the special device file for the SMBus */<BR> sprintf(filename, "/dev/i2c-%d", adapter_num);<BR> fd = open(filename, O_RDWR);<BR> if (fd < 0)<BR> {<BR> printf("ERROR: open(%s) failed\n", filename);<BR> printf("errno = %d, %s\n", errno, strerror(errno));<BR> return -1;<BR> }<BR> //printf("SUCCESS: open(%s) passed\n", filename);</DIV>
<DIV dir=ltr><BR> /* Specify the EEPROM as the device we want to access.<BR> *** IMPORTANT ***<BR> The address is actually in the 7 LSBs, so shift<BR> i2c_addr one bit to the right.*/<BR> status = ioctl(fd, I2C_SLAVE, i2c_addr>>1);<BR> if (status < 0)<BR> {<BR> printf("ERROR: ioctl(fd, I2C_SLAVE, 0x%02X) failed\n", i2c_addr);<BR> printf("errno = %d, %s\n", errno, strerror(errno));<BR> close(fd);<BR> return -1;<BR> }<BR> //printf("SUCCESS: ioctl(fd, I2C_SLAVE, 0x%02X>>1) passed\n", i2c_addr);</DIV>
<DIV dir=ltr><BR> if (strcmp(argv[1],"read") == 0)<BR> {<BR> offset = atoi(argv[2]);<BR> gef_eeprom_read(fd, offset, &rbuffer, 1);<BR> printf("Offset: %d Data: %d\n", offset, rbuffer);<BR> }</DIV>
<DIV dir=ltr><BR> if (strcmp(argv[1],"write") == 0)<BR> {<BR> offset = (unsigned char)(atoi(argv[2]));<BR> rbuffer =(unsigned char)(atoi(argv[3]));<BR> gef_eeprom_write(fd, offset, &rbuffer, 1);<BR> printf("Offset: %d Data: %d\n", offset, rbuffer);<BR> }</DIV>
<DIV dir=ltr><BR> /* Close the special device file */<BR> close(fd);</DIV>
<DIV dir=ltr> return 0;<BR>}</DIV>
<DIV dir=ltr><BR>//////////////////////////////////////////////////////////////////////////////<BR>//<BR>// Function name : gef_eeprom_read<BR>//<BR>// Description : Read buflen bytes from the EEPROM beginning at start_offset<BR>//<BR>// Return type : 0 for success, -1 for failure<BR>//<BR>// Argument : int fd : File descriptor returned by open()<BR>// Argument : unsigned char start_offset : Read bytes starting at this<BR>// offset in the EEPROM. The sum of buflen and<BR>// start_offset must not exceed the maximum size in bytes<BR>// of the EEPROM<BR>// Argument : unsigned char *buffer : Where to store the bytes read<BR>// from the EEPROM. The buffer must be large enough<BR>// to store buflen bytes read from the EEPROM.<BR>// Argument : unsigned short buflen : The size in bytes of buffer, or<BR>// how many bytes to read from the EEPROM. The sum of<BR>// buflen and start_offset must not exceed the maximum<BR>// size in bytes of the EEPROM.<BR>//</DIV>
<DIV dir=ltr>int gef_eeprom_read(int fd, unsigned char start_offset, unsigned char *buffer,<BR> unsigned short buflen)<BR>{<BR> int offset, index;<BR> int data;</DIV>
<DIV dir=ltr> for (index=0, offset=start_offset; index<buflen &&<BR> offset<EEPROM_SIZE; index++, offset++)<BR> {<BR> data = i2c_smbus_read_byte_data(fd, offset);<BR> if (data == -1)<BR> {<BR> printf("ERROR: i2c_smbus_read_byte_data(fd, 0x%02X) failed\n",<BR> offset);<BR> printf("errno = %d, %s\n", errno, strerror(errno));<BR> return -1;<BR> }<BR> buffer[index] = (unsigned char) (data);<BR> }</DIV>
<DIV dir=ltr> return 0;<BR>}</DIV>
<DIV dir=ltr><BR>//////////////////////////////////////////////////////////////////////////////<BR>//<BR>// Function name : gef_eeprom_write<BR>//<BR>// Description : Write buflen bytes to the EEPROM beginning at start_offset<BR>//<BR>// Return type : 0 for success, -1 for failure<BR>//<BR>// Argument : int fd : File descriptor returned by open()<BR>// Argument : unsigned char start_offset : Write bytes starting at this<BR>// offset in the EEPROM. The sum of buflen and<BR>// start_offset must not exceed the maximum size in bytes<BR>// of the EEPROM<BR>// Argument : unsigned char *buffer : Where to get the bytes to write<BR>// to the EEPROM.<BR>// Argument : unsigned short buflen : The size in bytes of buffer.<BR>// The sum of buflen and start_offset must not exceed the<BR>// maximum size in bytes of the EEPROM.<BR>//</DIV>
<DIV dir=ltr>int gef_eeprom_write(int fd, unsigned char start_offset, unsigned char *buffer,<BR> unsigned short buflen)<BR>{<BR> int offset, index;<BR> int status;</DIV>
<DIV dir=ltr> for (index=0, offset=start_offset; index<buflen &&<BR> offset<EEPROM_SIZE; index++, offset++)<BR> {<BR> status = i2c_smbus_write_byte_data(fd, offset, buffer[index]);<BR> if (status < 0)<BR> {<BR> printf("ERROR: i2c_smbus_write_byte_data(fd, 0x%02X, 0x%02X) failed\n",<BR> offset, buffer[index]);<BR> printf("errno = %d, %s\n", errno, strerror(errno));<BR> return -1;<BR> }</DIV>
<DIV dir=ltr> /* Delay while the byte write completes */<BR> gef_msec_delay(10);<BR> }</DIV>
<DIV dir=ltr> return 0;<BR>}</DIV>
<DIV dir=ltr><BR>//////////////////////////////////////////////////////////////////////////////<BR>//<BR>// Function name : gef_msec_delay<BR>//<BR>// Description : Delay for a number of milliseconds before returning<BR>//<BR>// Return type : void<BR>//<BR>// Argument : unsigned int msecs : The number of milliseconds to delay<BR>//</DIV>
<DIV dir=ltr>void gef_msec_delay(unsigned int msecs)<BR>{<BR> struct timeval s_current, s_start;<BR> struct timezone tz;<BR> unsigned int current, start;</DIV>
<DIV dir=ltr><BR> /* Get initial time */<BR> gettimeofday(&s_start, &tz);<BR> start = s_start.tv_sec*1000000 + s_start.tv_usec;</DIV>
<DIV dir=ltr> /* Loop until msecs time have elapsed */<BR> do<BR> {<BR> gettimeofday(&s_current, &tz);<BR> current = s_current.tv_sec*1000000 + s_current.tv_usec;<BR> } while ((current-start) < (msecs*1000));<BR>}</DIV>
<DIV dir=ltr><BR>-------------</DIV></DIV>
<DIV dir=ltr><BR>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> linuxppc-dev-bounces+tmarri=amcc.com@ozlabs.org on behalf of Henry Bausley<BR><B>Sent:</B> Tue 3/31/2009 5:41 PM<BR><B>To:</B> linuxppc-dev@ozlabs.org<BR><B>Subject:</B> PowerPC 460EX AD7416 Temperature Sensor<BR></FONT><BR></DIV>
<DIV>
<P><FONT size=2>Does anyone know if the I2C temperature sensor is functioning on the AMCC<BR>460EX?<BR>When I do a cat /proc/ad7416 I get the following crash.<BR><BR>Unable to handle kernel paging request for data at address 0x00000000<BR>Faulting instruction address: 0xc02cbe28<BR>Oops: Kernel access of bad area, sig: 11 [#1]<BR>PowerPC 44x Platform<BR>NIP: c02cbe28 LR: c023cec8 CTR: c023d314<BR>REGS: ef107d90 TRAP: 0300 Not tainted (2.6.28.7)<BR>MSR: 00029000 <EE,ME> CR: 88000444 XER: 00000000<BR>DEAR: 00000000, ESR: 00000000<BR>TASK = ef8590c0[2611] 'cat' THREAD: ef106000<BR>GPR00: 00000000 ef107e40 ef8590c0 00000000 ef107e9c 00000000 00000c00<BR>ef107e98<BR>GPR08: 00000000 c0330000 ffffffff c0330000 48000448 1001cb7c 100042bc<BR>100df49c<BR>GPR16: 00000002 00000400 c032f014 c032efe4 ef107e9c ef107e98 bfffffff<BR>efb43a00<BR>GPR24: ef61d000 00000000 ef107f20 ef107e98 00000c00 c0400000 00001000<BR>efb43a00<BR>NIP [c02cbe28] mutex_lock+0x0/0x1c<BR>LR [c023cec8] ad7416_read_temp+0x24/0x80<BR>Call Trace:<BR>[ef107e40] [00000400] 0x400 (unreliable)<BR>[ef107e70] [c023d334] i2c_ad7416_read_proc+0x20/0x70<BR>[ef107e90] [c00e8018] proc_file_read+0x108/0x334<BR>[ef107ee0] [c00e2d3c] proc_reg_read+0x4c/0x70<BR>[ef107ef0] [c00a54e8] vfs_read+0xb4/0x16c<BR>[ef107f10] [c00a58e0] sys_read+0x4c/0x90<BR>[ef107f40] [c000ea88] ret_from_syscall+0x0/0x3c<BR>Instruction dump:<BR>90010014 38000001 90030000 85230004 7f891800 419e000c 80690008 4bd50779<BR>80010014 38210010 7c0803a6 4e800020 <7c001828> 3000ffff 7c00192d 40a2fff4<BR>---[ end trace 774db769c3754abe ]---<BR><BR><BR><BR>**********************************************************<BR>Outbound scan for Spam or Virus by Barracuda at Delta Tau<BR>**********************************************************<BR>_______________________________________________<BR>Linuxppc-dev mailing list<BR>Linuxppc-dev@ozlabs.org<BR><A href="https://ozlabs.org/mailman/listinfo/linuxppc-dev">https://ozlabs.org/mailman/listinfo/linuxppc-dev</A><BR></FONT></P></DIV></BODY></HTML>