tpm_nsc.c (2fc2991175bf77395e6b15fe6b2304d3bf72da40) | tpm_nsc.c (e2a8f7a129aff5173c238c8896f004e07a2a3abe) |
---|---|
1/* 2 * Copyright (C) 2004 IBM Corporation 3 * 4 * Authors: 5 * Leendert van Doorn <leendert@watson.ibm.com> 6 * Dave Safford <safford@watson.ibm.com> 7 * Reiner Sailer <sailer@watson.ibm.com> 8 * Kylene Hall <kjhall@us.ibm.com> --- 273 unchanged lines hidden (view full) --- 282}; 283 284static int __init init_nsc(void) 285{ 286 int rc = 0; 287 int lo, hi; 288 int nscAddrBase = TPM_ADDR; 289 | 1/* 2 * Copyright (C) 2004 IBM Corporation 3 * 4 * Authors: 5 * Leendert van Doorn <leendert@watson.ibm.com> 6 * Dave Safford <safford@watson.ibm.com> 7 * Reiner Sailer <sailer@watson.ibm.com> 8 * Kylene Hall <kjhall@us.ibm.com> --- 273 unchanged lines hidden (view full) --- 282}; 283 284static int __init init_nsc(void) 285{ 286 int rc = 0; 287 int lo, hi; 288 int nscAddrBase = TPM_ADDR; 289 |
290 driver_register(&nsc_drv); | |
291 | 290 |
292 /* select PM channel 1 */ 293 tpm_write_index(nscAddrBase,NSC_LDN_INDEX, 0x12); 294 | |
295 /* verify that it is a National part (SID) */ 296 if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) { 297 nscAddrBase = (tpm_read_index(TPM_SUPERIO_ADDR, 0x2C)<<8)| 298 (tpm_read_index(TPM_SUPERIO_ADDR, 0x2B)&0xFE); 299 if (tpm_read_index(nscAddrBase, NSC_SID_INDEX) != 0xF6) 300 return -ENODEV; 301 } 302 | 291 /* verify that it is a National part (SID) */ 292 if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) { 293 nscAddrBase = (tpm_read_index(TPM_SUPERIO_ADDR, 0x2C)<<8)| 294 (tpm_read_index(TPM_SUPERIO_ADDR, 0x2B)&0xFE); 295 if (tpm_read_index(nscAddrBase, NSC_SID_INDEX) != 0xF6) 296 return -ENODEV; 297 } 298 |
299 driver_register(&nsc_drv); 300 |
|
303 hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI); 304 lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO); 305 tpm_nsc.base = (hi<<8) | lo; 306 307 /* enable the DPM module */ 308 tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01); 309 | 301 hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI); 302 lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO); 303 tpm_nsc.base = (hi<<8) | lo; 304 305 /* enable the DPM module */ 306 tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01); 307 |
310 pdev = kmalloc(sizeof(struct platform_device), GFP_KERNEL); 311 if ( !pdev ) 312 return -ENOMEM; | 308 pdev = kzalloc(sizeof(struct platform_device), GFP_KERNEL); 309 if (!pdev) { 310 rc = -ENOMEM; 311 goto err_unreg_drv; 312 } |
313 | 313 |
314 memset(pdev, 0, sizeof(struct platform_device)); 315 | |
316 pdev->name = "tpm_nscl0"; 317 pdev->id = -1; 318 pdev->num_resources = 0; 319 pdev->dev.release = tpm_nsc_remove; 320 pdev->dev.driver = &nsc_drv; 321 | 314 pdev->name = "tpm_nscl0"; 315 pdev->id = -1; 316 pdev->num_resources = 0; 317 pdev->dev.release = tpm_nsc_remove; 318 pdev->dev.driver = &nsc_drv; 319 |
322 if ((rc=platform_device_register(pdev)) < 0) { 323 kfree(pdev); 324 pdev = NULL; 325 return rc; 326 } | 320 if ((rc = platform_device_register(pdev)) < 0) 321 goto err_free_dev; |
327 328 if (request_region(tpm_nsc.base, 2, "tpm_nsc0") == NULL ) { | 322 323 if (request_region(tpm_nsc.base, 2, "tpm_nsc0") == NULL ) { |
329 platform_device_unregister(pdev); 330 kfree(pdev); 331 pdev = NULL; 332 return -EBUSY; | 324 rc = -EBUSY; 325 goto err_unreg_dev; |
333 } 334 | 326 } 327 |
335 if ((rc = tpm_register_hardware(&pdev->dev, &tpm_nsc)) < 0) { 336 release_region(tpm_nsc.base, 2); 337 platform_device_unregister(pdev); 338 kfree(pdev); 339 pdev = NULL; 340 return rc; 341 } | 328 if ((rc = tpm_register_hardware(&pdev->dev, &tpm_nsc)) < 0) 329 goto err_rel_reg; |
342 343 dev_dbg(&pdev->dev, "NSC TPM detected\n"); 344 dev_dbg(&pdev->dev, 345 "NSC LDN 0x%x, SID 0x%x, SRID 0x%x\n", 346 tpm_read_index(nscAddrBase,0x07), tpm_read_index(nscAddrBase,0x20), 347 tpm_read_index(nscAddrBase,0x27)); 348 dev_dbg(&pdev->dev, 349 "NSC SIOCF1 0x%x SIOCF5 0x%x SIOCF6 0x%x SIOCF8 0x%x\n", --- 19 unchanged lines hidden (view full) --- 369 tpm_read_index(nscAddrBase,0xF6), tpm_read_index(nscAddrBase,0xF7), 370 tpm_read_index(nscAddrBase,0xF8), tpm_read_index(nscAddrBase,0xF9)); 371 372 dev_info(&pdev->dev, 373 "NSC TPM revision %d\n", 374 tpm_read_index(nscAddrBase, 0x27) & 0x1F); 375 376 return 0; | 330 331 dev_dbg(&pdev->dev, "NSC TPM detected\n"); 332 dev_dbg(&pdev->dev, 333 "NSC LDN 0x%x, SID 0x%x, SRID 0x%x\n", 334 tpm_read_index(nscAddrBase,0x07), tpm_read_index(nscAddrBase,0x20), 335 tpm_read_index(nscAddrBase,0x27)); 336 dev_dbg(&pdev->dev, 337 "NSC SIOCF1 0x%x SIOCF5 0x%x SIOCF6 0x%x SIOCF8 0x%x\n", --- 19 unchanged lines hidden (view full) --- 357 tpm_read_index(nscAddrBase,0xF6), tpm_read_index(nscAddrBase,0xF7), 358 tpm_read_index(nscAddrBase,0xF8), tpm_read_index(nscAddrBase,0xF9)); 359 360 dev_info(&pdev->dev, 361 "NSC TPM revision %d\n", 362 tpm_read_index(nscAddrBase, 0x27) & 0x1F); 363 364 return 0; |
365 366err_rel_reg: 367 release_region(tpm_nsc.base, 2); 368err_unreg_dev: 369 platform_device_unregister(pdev); 370err_free_dev: 371 kfree(pdev); 372err_unreg_drv: 373 driver_unregister(&nsc_drv); 374 return rc; |
|
377} 378 379static void __exit cleanup_nsc(void) 380{ 381 if (pdev) { 382 tpm_nsc_remove(&pdev->dev); 383 platform_device_unregister(pdev); 384 kfree(pdev); --- 13 unchanged lines hidden --- | 375} 376 377static void __exit cleanup_nsc(void) 378{ 379 if (pdev) { 380 tpm_nsc_remove(&pdev->dev); 381 platform_device_unregister(pdev); 382 kfree(pdev); --- 13 unchanged lines hidden --- |