tpm_nsc.c (e659a3fe2027b19ecd8abb7ad79253672763454b) tpm_nsc.c (570302a31149083b0ac8b2f08c195e9211c2c0c6)
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>

--- 247 unchanged lines hidden (view full) ---

256 .status = tpm_nsc_status,
257 .req_complete_mask = NSC_STATUS_OBF,
258 .req_complete_val = NSC_STATUS_OBF,
259 .req_canceled = NSC_STATUS_RDY,
260 .attr_group = &nsc_attr_grp,
261 .miscdev = { .fops = &nsc_ops, },
262};
263
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>

--- 247 unchanged lines hidden (view full) ---

256 .status = tpm_nsc_status,
257 .req_complete_mask = NSC_STATUS_OBF,
258 .req_complete_val = NSC_STATUS_OBF,
259 .req_canceled = NSC_STATUS_RDY,
260 .attr_group = &nsc_attr_grp,
261 .miscdev = { .fops = &nsc_ops, },
262};
263
264static int __devinit tpm_nsc_init(struct pci_dev *pci_dev,
265 const struct pci_device_id *pci_id)
264static struct platform_device *pdev = NULL;
265
266static void __devexit tpm_nsc_remove(struct device *dev)
266{
267{
268 struct tpm_chip *chip = dev_get_drvdata(dev);
269 if ( chip ) {
270 release_region(chip->vendor->base, 2);
271 tpm_remove_hardware(chip->dev);
272 }
273}
274
275static struct device_driver nsc_drv = {
276 .name = "tpm_nsc",
277 .bus = &platform_bus_type,
278 .owner = THIS_MODULE,
279 .suspend = tpm_pm_suspend,
280 .resume = tpm_pm_resume,
281};
282
283static int __init init_nsc(void)
284{
267 int rc = 0;
268 int lo, hi;
269 int nscAddrBase = TPM_ADDR;
270
285 int rc = 0;
286 int lo, hi;
287 int nscAddrBase = TPM_ADDR;
288
289 driver_register(&nsc_drv);
271
290
272 if (pci_enable_device(pci_dev))
273 return -EIO;
274
275 /* select PM channel 1 */
276 tpm_write_index(nscAddrBase,NSC_LDN_INDEX, 0x12);
277
278 /* verify that it is a National part (SID) */
279 if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) {
280 nscAddrBase = (tpm_read_index(TPM_SUPERIO_ADDR, 0x2C)<<8)|
281 (tpm_read_index(TPM_SUPERIO_ADDR, 0x2B)&0xFE);
291 /* select PM channel 1 */
292 tpm_write_index(nscAddrBase,NSC_LDN_INDEX, 0x12);
293
294 /* verify that it is a National part (SID) */
295 if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) {
296 nscAddrBase = (tpm_read_index(TPM_SUPERIO_ADDR, 0x2C)<<8)|
297 (tpm_read_index(TPM_SUPERIO_ADDR, 0x2B)&0xFE);
282 if (tpm_read_index(nscAddrBase, NSC_SID_INDEX) != 0xF6) {
283 rc = -ENODEV;
284 goto out_err;
285 }
298 if (tpm_read_index(nscAddrBase, NSC_SID_INDEX) != 0xF6)
299 return -ENODEV;
286 }
287
288 hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI);
289 lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO);
290 tpm_nsc.base = (hi<<8) | lo;
291
300 }
301
302 hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI);
303 lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO);
304 tpm_nsc.base = (hi<<8) | lo;
305
292 dev_dbg(&pci_dev->dev, "NSC TPM detected\n");
293 dev_dbg(&pci_dev->dev,
306 /* enable the DPM module */
307 tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01);
308
309 pdev = kmalloc(sizeof(struct platform_device), GFP_KERNEL);
310 if ( !pdev )
311 return -ENOMEM;
312
313 memset(pdev, 0, sizeof(struct platform_device));
314
315 pdev->name = "tpm_nscl0";
316 pdev->id = -1;
317 pdev->num_resources = 0;
318 pdev->dev.release = tpm_nsc_remove;
319 pdev->dev.driver = &nsc_drv;
320
321 if ((rc=platform_device_register(pdev)) < 0) {
322 kfree(pdev);
323 pdev = NULL;
324 return rc;
325 }
326
327 if (request_region(tpm_nsc.base, 2, "tpm_nsc0") == NULL ) {
328 platform_device_unregister(pdev);
329 kfree(pdev);
330 pdev = NULL;
331 return -EBUSY;
332 }
333
334 if ((rc = tpm_register_hardware(&pdev->dev, &tpm_nsc)) < 0) {
335 release_region(tpm_nsc.base, 2);
336 platform_device_unregister(pdev);
337 kfree(pdev);
338 pdev = NULL;
339 return rc;
340 }
341
342 dev_dbg(&pdev->dev, "NSC TPM detected\n");
343 dev_dbg(&pdev->dev,
294 "NSC LDN 0x%x, SID 0x%x, SRID 0x%x\n",
295 tpm_read_index(nscAddrBase,0x07), tpm_read_index(nscAddrBase,0x20),
296 tpm_read_index(nscAddrBase,0x27));
344 "NSC LDN 0x%x, SID 0x%x, SRID 0x%x\n",
345 tpm_read_index(nscAddrBase,0x07), tpm_read_index(nscAddrBase,0x20),
346 tpm_read_index(nscAddrBase,0x27));
297 dev_dbg(&pci_dev->dev,
347 dev_dbg(&pdev->dev,
298 "NSC SIOCF1 0x%x SIOCF5 0x%x SIOCF6 0x%x SIOCF8 0x%x\n",
299 tpm_read_index(nscAddrBase,0x21), tpm_read_index(nscAddrBase,0x25),
300 tpm_read_index(nscAddrBase,0x26), tpm_read_index(nscAddrBase,0x28));
348 "NSC SIOCF1 0x%x SIOCF5 0x%x SIOCF6 0x%x SIOCF8 0x%x\n",
349 tpm_read_index(nscAddrBase,0x21), tpm_read_index(nscAddrBase,0x25),
350 tpm_read_index(nscAddrBase,0x26), tpm_read_index(nscAddrBase,0x28));
301 dev_dbg(&pci_dev->dev, "NSC IO Base0 0x%x\n",
351 dev_dbg(&pdev->dev, "NSC IO Base0 0x%x\n",
302 (tpm_read_index(nscAddrBase,0x60) << 8) | tpm_read_index(nscAddrBase,0x61));
352 (tpm_read_index(nscAddrBase,0x60) << 8) | tpm_read_index(nscAddrBase,0x61));
303 dev_dbg(&pci_dev->dev, "NSC IO Base1 0x%x\n",
353 dev_dbg(&pdev->dev, "NSC IO Base1 0x%x\n",
304 (tpm_read_index(nscAddrBase,0x62) << 8) | tpm_read_index(nscAddrBase,0x63));
354 (tpm_read_index(nscAddrBase,0x62) << 8) | tpm_read_index(nscAddrBase,0x63));
305 dev_dbg(&pci_dev->dev, "NSC Interrupt number and wakeup 0x%x\n",
355 dev_dbg(&pdev->dev, "NSC Interrupt number and wakeup 0x%x\n",
306 tpm_read_index(nscAddrBase,0x70));
356 tpm_read_index(nscAddrBase,0x70));
307 dev_dbg(&pci_dev->dev, "NSC IRQ type select 0x%x\n",
357 dev_dbg(&pdev->dev, "NSC IRQ type select 0x%x\n",
308 tpm_read_index(nscAddrBase,0x71));
358 tpm_read_index(nscAddrBase,0x71));
309 dev_dbg(&pci_dev->dev,
359 dev_dbg(&pdev->dev,
310 "NSC DMA channel select0 0x%x, select1 0x%x\n",
311 tpm_read_index(nscAddrBase,0x74), tpm_read_index(nscAddrBase,0x75));
360 "NSC DMA channel select0 0x%x, select1 0x%x\n",
361 tpm_read_index(nscAddrBase,0x74), tpm_read_index(nscAddrBase,0x75));
312 dev_dbg(&pci_dev->dev,
362 dev_dbg(&pdev->dev,
313 "NSC Config "
314 "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
315 tpm_read_index(nscAddrBase,0xF0), tpm_read_index(nscAddrBase,0xF1),
316 tpm_read_index(nscAddrBase,0xF2), tpm_read_index(nscAddrBase,0xF3),
317 tpm_read_index(nscAddrBase,0xF4), tpm_read_index(nscAddrBase,0xF5),
318 tpm_read_index(nscAddrBase,0xF6), tpm_read_index(nscAddrBase,0xF7),
319 tpm_read_index(nscAddrBase,0xF8), tpm_read_index(nscAddrBase,0xF9));
320
363 "NSC Config "
364 "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
365 tpm_read_index(nscAddrBase,0xF0), tpm_read_index(nscAddrBase,0xF1),
366 tpm_read_index(nscAddrBase,0xF2), tpm_read_index(nscAddrBase,0xF3),
367 tpm_read_index(nscAddrBase,0xF4), tpm_read_index(nscAddrBase,0xF5),
368 tpm_read_index(nscAddrBase,0xF6), tpm_read_index(nscAddrBase,0xF7),
369 tpm_read_index(nscAddrBase,0xF8), tpm_read_index(nscAddrBase,0xF9));
370
321 dev_info(&pci_dev->dev,
371 dev_info(&pdev->dev,
322 "NSC TPM revision %d\n",
323 tpm_read_index(nscAddrBase, 0x27) & 0x1F);
324
372 "NSC TPM revision %d\n",
373 tpm_read_index(nscAddrBase, 0x27) & 0x1F);
374
325 /* enable the DPM module */
326 tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01);
327
328 if ((rc = tpm_register_hardware(&pci_dev->dev, &tpm_nsc)) < 0)
329 goto out_err;
330
331 return 0;
375 return 0;
332
333out_err:
334 pci_disable_device(pci_dev);
335 return rc;
336}
337
376}
377
338static void __devexit tpm_nsc_remove(struct pci_dev *pci_dev)
378static void __exit cleanup_nsc(void)
339{
379{
340 struct tpm_chip *chip = pci_get_drvdata(pci_dev);
380 if (pdev) {
381 tpm_nsc_remove(&pdev->dev);
382 platform_device_unregister(pdev);
383 kfree(pdev);
384 pdev = NULL;
385 }
341
386
342 if ( chip )
343 tpm_remove_hardware(chip->dev);
387 driver_unregister(&nsc_drv);
344}
345
388}
389
346static struct pci_device_id tpm_pci_tbl[] __devinitdata = {
347 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0)},
348 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12)},
349 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0)},
350 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12)},
351 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0)},
352 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0)},
353 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1)},
354 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_0)},
355 {PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_LPC)},
356 {0,}
357};
358
359MODULE_DEVICE_TABLE(pci, tpm_pci_tbl);
360
361static struct pci_driver nsc_pci_driver = {
362 .name = "tpm_nsc",
363 .id_table = tpm_pci_tbl,
364 .probe = tpm_nsc_init,
365 .remove = __devexit_p(tpm_nsc_remove),
366 .suspend = tpm_pm_suspend,
367 .resume = tpm_pm_resume,
368};
369
370static int __init init_nsc(void)
371{
372 return pci_register_driver(&nsc_pci_driver);
373}
374
375static void __exit cleanup_nsc(void)
376{
377 pci_unregister_driver(&nsc_pci_driver);
378}
379
380module_init(init_nsc);
381module_exit(cleanup_nsc);
382
383MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
384MODULE_DESCRIPTION("TPM Driver");
385MODULE_VERSION("2.0");
386MODULE_LICENSE("GPL");
390module_init(init_nsc);
391module_exit(cleanup_nsc);
392
393MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
394MODULE_DESCRIPTION("TPM Driver");
395MODULE_VERSION("2.0");
396MODULE_LICENSE("GPL");