|
@@ -166,7 +166,7 @@ int smscusb_eeprom_fetch_mac ( struct smscusb_device *smscusb,
|
166
|
166
|
|
167
|
167
|
/* Check that EEPROM is physically present */
|
168
|
168
|
if ( ! is_valid_ether_addr ( netdev->hw_addr ) ) {
|
169
|
|
- DBGC ( smscusb, "SMSCUSB %p has no EEPROM (%s)\n",
|
|
169
|
+ DBGC ( smscusb, "SMSCUSB %p has no EEPROM MAC (%s)\n",
|
170
|
170
|
smscusb, eth_ntoa ( netdev->hw_addr ) );
|
171
|
171
|
return -ENODEV;
|
172
|
172
|
}
|
|
@@ -176,6 +176,212 @@ int smscusb_eeprom_fetch_mac ( struct smscusb_device *smscusb,
|
176
|
176
|
return 0;
|
177
|
177
|
}
|
178
|
178
|
|
|
179
|
+/******************************************************************************
|
|
180
|
+ *
|
|
181
|
+ * OTP access
|
|
182
|
+ *
|
|
183
|
+ ******************************************************************************
|
|
184
|
+ */
|
|
185
|
+
|
|
186
|
+/**
|
|
187
|
+ * Power up OTP
|
|
188
|
+ *
|
|
189
|
+ * @v smscusb SMSC USB device
|
|
190
|
+ * @v otp_base OTP register base
|
|
191
|
+ * @ret rc Return status code
|
|
192
|
+ */
|
|
193
|
+static int smscusb_otp_power_up ( struct smscusb_device *smscusb,
|
|
194
|
+ unsigned int otp_base ) {
|
|
195
|
+ uint32_t otp_power;
|
|
196
|
+ unsigned int i;
|
|
197
|
+ int rc;
|
|
198
|
+
|
|
199
|
+ /* Power up OTP */
|
|
200
|
+ if ( ( rc = smscusb_writel ( smscusb, ( otp_base + SMSCUSB_OTP_POWER ),
|
|
201
|
+ 0 ) ) != 0 )
|
|
202
|
+ return rc;
|
|
203
|
+
|
|
204
|
+ /* Wait for OTP_POWER_DOWN to become clear */
|
|
205
|
+ for ( i = 0 ; i < SMSCUSB_OTP_MAX_WAIT_MS ; i++ ) {
|
|
206
|
+
|
|
207
|
+ /* Read OTP_POWER and check OTP_POWER_DOWN */
|
|
208
|
+ if ( ( rc = smscusb_readl ( smscusb,
|
|
209
|
+ ( otp_base + SMSCUSB_OTP_POWER ),
|
|
210
|
+ &otp_power ) ) != 0 )
|
|
211
|
+ return rc;
|
|
212
|
+ if ( ! ( otp_power & SMSCUSB_OTP_POWER_DOWN ) )
|
|
213
|
+ return 0;
|
|
214
|
+
|
|
215
|
+ /* Delay */
|
|
216
|
+ mdelay ( 1 );
|
|
217
|
+ }
|
|
218
|
+
|
|
219
|
+ DBGC ( smscusb, "SMSCUSB %p timed out waiting for OTP power up\n",
|
|
220
|
+ smscusb );
|
|
221
|
+ return -ETIMEDOUT;
|
|
222
|
+}
|
|
223
|
+
|
|
224
|
+/**
|
|
225
|
+ * Wait for OTP to become idle
|
|
226
|
+ *
|
|
227
|
+ * @v smscusb SMSC USB device
|
|
228
|
+ * @v otp_base OTP register base
|
|
229
|
+ * @ret rc Return status code
|
|
230
|
+ */
|
|
231
|
+static int smscusb_otp_wait ( struct smscusb_device *smscusb,
|
|
232
|
+ unsigned int otp_base ) {
|
|
233
|
+ uint32_t otp_status;
|
|
234
|
+ unsigned int i;
|
|
235
|
+ int rc;
|
|
236
|
+
|
|
237
|
+ /* Wait for OTP_STATUS_BUSY to become clear */
|
|
238
|
+ for ( i = 0 ; i < SMSCUSB_OTP_MAX_WAIT_MS ; i++ ) {
|
|
239
|
+
|
|
240
|
+ /* Read OTP_STATUS and check OTP_STATUS_BUSY */
|
|
241
|
+ if ( ( rc = smscusb_readl ( smscusb,
|
|
242
|
+ ( otp_base + SMSCUSB_OTP_STATUS ),
|
|
243
|
+ &otp_status ) ) != 0 )
|
|
244
|
+ return rc;
|
|
245
|
+ if ( ! ( otp_status & SMSCUSB_OTP_STATUS_BUSY ) )
|
|
246
|
+ return 0;
|
|
247
|
+
|
|
248
|
+ /* Delay */
|
|
249
|
+ mdelay ( 1 );
|
|
250
|
+ }
|
|
251
|
+
|
|
252
|
+ DBGC ( smscusb, "SMSCUSB %p timed out waiting for OTP\n",
|
|
253
|
+ smscusb );
|
|
254
|
+ return -ETIMEDOUT;
|
|
255
|
+}
|
|
256
|
+
|
|
257
|
+/**
|
|
258
|
+ * Read byte from OTP
|
|
259
|
+ *
|
|
260
|
+ * @v smscusb SMSC USB device
|
|
261
|
+ * @v otp_base OTP register base
|
|
262
|
+ * @v address OTP address
|
|
263
|
+ * @ret byte Byte read, or negative error
|
|
264
|
+ */
|
|
265
|
+static int smscusb_otp_read_byte ( struct smscusb_device *smscusb,
|
|
266
|
+ unsigned int otp_base,
|
|
267
|
+ unsigned int address ) {
|
|
268
|
+ uint8_t addrh = ( address >> 8 );
|
|
269
|
+ uint8_t addrl = ( address >> 0 );
|
|
270
|
+ uint32_t otp_data;
|
|
271
|
+ int rc;
|
|
272
|
+
|
|
273
|
+ /* Wait for OTP to become idle */
|
|
274
|
+ if ( ( rc = smscusb_otp_wait ( smscusb, otp_base ) ) != 0 )
|
|
275
|
+ return rc;
|
|
276
|
+
|
|
277
|
+ /* Initiate read command */
|
|
278
|
+ if ( ( rc = smscusb_writel ( smscusb, ( otp_base + SMSCUSB_OTP_ADDRH ),
|
|
279
|
+ addrh ) ) != 0 )
|
|
280
|
+ return rc;
|
|
281
|
+ if ( ( rc = smscusb_writel ( smscusb, ( otp_base + SMSCUSB_OTP_ADDRL ),
|
|
282
|
+ addrl ) ) != 0 )
|
|
283
|
+ return rc;
|
|
284
|
+ if ( ( rc = smscusb_writel ( smscusb, ( otp_base + SMSCUSB_OTP_CMD ),
|
|
285
|
+ SMSCUSB_OTP_CMD_READ ) ) != 0 )
|
|
286
|
+ return rc;
|
|
287
|
+ if ( ( rc = smscusb_writel ( smscusb, ( otp_base + SMSCUSB_OTP_GO ),
|
|
288
|
+ SMSCUSB_OTP_GO_GO ) ) != 0 )
|
|
289
|
+ return rc;
|
|
290
|
+
|
|
291
|
+ /* Wait for command to complete */
|
|
292
|
+ if ( ( rc = smscusb_otp_wait ( smscusb, otp_base ) ) != 0 )
|
|
293
|
+ return rc;
|
|
294
|
+
|
|
295
|
+ /* Read OTP data */
|
|
296
|
+ if ( ( rc = smscusb_readl ( smscusb, ( otp_base + SMSCUSB_OTP_DATA ),
|
|
297
|
+ &otp_data ) ) != 0 )
|
|
298
|
+ return rc;
|
|
299
|
+
|
|
300
|
+ return SMSCUSB_OTP_DATA_GET ( otp_data );
|
|
301
|
+}
|
|
302
|
+
|
|
303
|
+/**
|
|
304
|
+ * Read data from OTP
|
|
305
|
+ *
|
|
306
|
+ * @v smscusb SMSC USB device
|
|
307
|
+ * @v otp_base OTP register base
|
|
308
|
+ * @v address OTP address
|
|
309
|
+ * @v data Data buffer
|
|
310
|
+ * @v len Length of data
|
|
311
|
+ * @ret rc Return status code
|
|
312
|
+ */
|
|
313
|
+static int smscusb_otp_read ( struct smscusb_device *smscusb,
|
|
314
|
+ unsigned int otp_base, unsigned int address,
|
|
315
|
+ void *data, size_t len ) {
|
|
316
|
+ uint8_t *bytes;
|
|
317
|
+ int byte;
|
|
318
|
+ int rc;
|
|
319
|
+
|
|
320
|
+ /* Power up OTP */
|
|
321
|
+ if ( ( rc = smscusb_otp_power_up ( smscusb, otp_base ) ) != 0 )
|
|
322
|
+ return rc;
|
|
323
|
+
|
|
324
|
+ /* Read bytes */
|
|
325
|
+ for ( bytes = data ; len-- ; address++, bytes++ ) {
|
|
326
|
+ byte = smscusb_otp_read_byte ( smscusb, otp_base, address );
|
|
327
|
+ if ( byte < 0 )
|
|
328
|
+ return byte;
|
|
329
|
+ *bytes = byte;
|
|
330
|
+ }
|
|
331
|
+
|
|
332
|
+ return 0;
|
|
333
|
+}
|
|
334
|
+
|
|
335
|
+/**
|
|
336
|
+ * Fetch MAC address from OTP
|
|
337
|
+ *
|
|
338
|
+ * @v smscusb SMSC USB device
|
|
339
|
+ * @v otp_base OTP register base
|
|
340
|
+ * @ret rc Return status code
|
|
341
|
+ */
|
|
342
|
+int smscusb_otp_fetch_mac ( struct smscusb_device *smscusb,
|
|
343
|
+ unsigned int otp_base ) {
|
|
344
|
+ struct net_device *netdev = smscusb->netdev;
|
|
345
|
+ uint8_t signature;
|
|
346
|
+ unsigned int address;
|
|
347
|
+ int rc;
|
|
348
|
+
|
|
349
|
+ /* Read OTP signature byte */
|
|
350
|
+ if ( ( rc = smscusb_otp_read ( smscusb, otp_base, 0, &signature,
|
|
351
|
+ sizeof ( signature ) ) ) != 0 )
|
|
352
|
+ return rc;
|
|
353
|
+
|
|
354
|
+ /* Determine location of MAC address */
|
|
355
|
+ switch ( signature ) {
|
|
356
|
+ case SMSCUSB_OTP_1_SIG:
|
|
357
|
+ address = SMSCUSB_OTP_1_MAC;
|
|
358
|
+ break;
|
|
359
|
+ case SMSCUSB_OTP_2_SIG:
|
|
360
|
+ address = SMSCUSB_OTP_2_MAC;
|
|
361
|
+ break;
|
|
362
|
+ default:
|
|
363
|
+ DBGC ( smscusb, "SMSCUSB %p unknown OTP signature %#02x\n",
|
|
364
|
+ smscusb, signature );
|
|
365
|
+ return -ENOTSUP;
|
|
366
|
+ }
|
|
367
|
+
|
|
368
|
+ /* Read MAC address from OTP */
|
|
369
|
+ if ( ( rc = smscusb_otp_read ( smscusb, otp_base, address,
|
|
370
|
+ netdev->hw_addr, ETH_ALEN ) ) != 0 )
|
|
371
|
+ return rc;
|
|
372
|
+
|
|
373
|
+ /* Check that OTP is valid */
|
|
374
|
+ if ( ! is_valid_ether_addr ( netdev->hw_addr ) ) {
|
|
375
|
+ DBGC ( smscusb, "SMSCUSB %p has no layout %#02x OTP MAC (%s)\n",
|
|
376
|
+ smscusb, signature, eth_ntoa ( netdev->hw_addr ) );
|
|
377
|
+ return -ENODEV;
|
|
378
|
+ }
|
|
379
|
+
|
|
380
|
+ DBGC ( smscusb, "SMSCUSB %p using layout %#02x OTP MAC %s\n",
|
|
381
|
+ smscusb, signature, eth_ntoa ( netdev->hw_addr ) );
|
|
382
|
+ return 0;
|
|
383
|
+}
|
|
384
|
+
|
179
|
385
|
/******************************************************************************
|
180
|
386
|
*
|
181
|
387
|
* MII access
|