1 /* Minimal support functions to read configuration from IIC EEPROMS
2 * on MPC8xx boards. Originally written for RPGC RPX-Lite.
3 * Dan Malek (dmalek@jlc.net).
5 #include <linux/types.h>
6 #include <asm/uaccess.h>
7 #include <asm/mpc8xx.h>
8 #include <asm/commproc.h>
12 * These are just the basic master read/write operations so we can
13 * examine serial EEPROM.
15 void iic_read(uint devaddr
, u_char
*buf
, uint offset
, uint count
);
17 static int iic_init_done
;
23 volatile i2c8xx_t
*i2c
;
24 volatile cpm8xx_t
*cp
;
25 volatile immap_t
*immap
;
28 immap
= (immap_t
*)IMAP_ADDR
;
29 cp
= (cpm8xx_t
*)&(immap
->im_cpm
);
31 /* Reset the CPM. This is necessary on the 860 processors
32 * that may have started the SCC1 ethernet without relocating
34 * This also stops the Ethernet in case we were loaded by a
37 cp
->cp_cpcr
= (CPM_CR_RST
| CPM_CR_FLG
);
41 while (cp
->cp_cpcr
& (CPM_CR_RST
| CPM_CR_FLG
));
43 /* Remove any microcode patches. We will install our own
52 iip
= (iic_t
*)&cp
->cp_dparam
[PROFF_IIC
];
53 i2c
= (i2c8xx_t
*)&(immap
->im_i2c
);
55 /* Initialize Port B IIC pins.
57 cp
->cp_pbpar
|= 0x00000030;
58 cp
->cp_pbdir
|= 0x00000030;
59 cp
->cp_pbodr
|= 0x00000030;
61 /* Initialize the parameter ram.
64 /* Allocate space for a two transmit and one receive buffer
65 * descriptor in the DP ram.
66 * For now, this address seems OK, but it may have to
67 * change with newer versions of the firmware.
71 /* Set up the IIC parameters in the parameter ram.
73 iip
->iic_tbase
= dpaddr
;
74 iip
->iic_rbase
= dpaddr
+ (2 * sizeof(cbd_t
));
76 iip
->iic_tfcr
= SMC_EB
;
77 iip
->iic_rfcr
= SMC_EB
;
79 /* This should really be done by the reader/writer.
83 /* Initialize Tx/Rx parameters.
85 cp
->cp_cpcr
= mk_cr_cmd(CPM_CR_CH_I2C
, CPM_CR_INIT_TRX
) | CPM_CR_FLG
;
86 while (cp
->cp_cpcr
& CPM_CR_FLG
);
88 /* Select an arbitrary address. Just make sure it is unique.
90 i2c
->i2c_i2add
= 0x34;
92 /* Make clock run maximum slow.
96 /* Disable interrupts.
99 i2c
->i2c_i2cer
= 0xff;
103 immap
->im_siu_conf
.sc_sdcr
= 1;
109 * Caller provides device address, memory buffer, and byte count.
111 static u_char iitemp
[32];
114 iic_read(uint devaddr
, u_char
*buf
, uint offset
, uint count
)
117 volatile i2c8xx_t
*i2c
;
118 volatile cbd_t
*tbdf
, *rbdf
;
119 volatile cpm8xx_t
*cp
;
120 volatile immap_t
*immap
;
124 /* If the interface has not been initialized, do that now.
129 immap
= (immap_t
*)IMAP_ADDR
;
130 cp
= (cpm8xx_t
*)&(immap
->im_cpm
);
132 iip
= (iic_t
*)&cp
->cp_dparam
[PROFF_IIC
];
133 i2c
= (i2c8xx_t
*)&(immap
->im_i2c
);
135 tbdf
= (cbd_t
*)&cp
->cp_dpmem
[iip
->iic_tbase
];
136 rbdf
= (cbd_t
*)&cp
->cp_dpmem
[iip
->iic_rbase
];
138 /* Send a "dummy write" operation. This is a write request with
139 * only the offset sent, followed by another start condition.
140 * This will ensure we start reading from the first location
144 tb
= (u_char
*)(((uint
)tb
+ 15) & ~15);
145 tbdf
->cbd_bufaddr
= (int)tb
;
146 *tb
= devaddr
& 0xfe; /* Device address */
147 *(tb
+1) = offset
; /* Offset */
148 tbdf
->cbd_datlen
= 2; /* Length */
150 BD_SC_READY
| BD_SC_LAST
| BD_SC_WRAP
| BD_IIC_START
;
152 i2c
->i2c_i2mod
= 1; /* Enable */
153 i2c
->i2c_i2cer
= 0xff;
154 i2c
->i2c_i2com
= 0x81; /* Start master */
156 /* Wait for IIC transfer.
159 while ((i2c
->i2c_i2cer
& 3) == 0);
161 if (tbdf
->cbd_sc
& BD_SC_READY
)
162 printf("IIC ra complete but tbuf ready\n");
165 while ((tbdf
->cbd_sc
& BD_SC_READY
) && (temp
!= 0))
168 /* We can't do this...there is no serial port yet!
171 printf("Timeout reading EEPROM\n");
177 /* Chip errata, clear enable.
181 /* To read, we need an empty buffer of the proper length.
182 * All that is used is the first byte for address, the remainder
183 * is just used for timing (and doesn't really have to exist).
185 tbdf
->cbd_bufaddr
= (int)tb
;
186 *tb
= devaddr
| 1; /* Device address */
187 rbdf
->cbd_bufaddr
= (uint
)buf
; /* Desination buffer */
188 tbdf
->cbd_datlen
= rbdf
->cbd_datlen
= count
+ 1; /* Length */
189 tbdf
->cbd_sc
= BD_SC_READY
| BD_SC_LAST
| BD_SC_WRAP
| BD_IIC_START
;
190 rbdf
->cbd_sc
= BD_SC_EMPTY
| BD_SC_WRAP
;
192 /* Chip bug, set enable here.
194 i2c
->i2c_i2mod
= 1; /* Enable */
195 i2c
->i2c_i2cer
= 0xff;
196 i2c
->i2c_i2com
= 0x81; /* Start master */
198 /* Wait for IIC transfer.
201 while ((i2c
->i2c_i2cer
& 1) == 0);
203 if (rbdf
->cbd_sc
& BD_SC_EMPTY
)
204 printf("IIC read complete but rbuf empty\n");
207 while ((tbdf
->cbd_sc
& BD_SC_READY
) && (temp
!= 0))
211 /* Chip errata, clear enable.