aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/pti.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc/pti.c')
-rw-r--r--drivers/misc/pti.c128
1 files changed, 59 insertions, 69 deletions
diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
index b7eb545394b1..4999b34b7a60 100644
--- a/drivers/misc/pti.c
+++ b/drivers/misc/pti.c
@@ -60,7 +60,7 @@ struct pti_tty {
60}; 60};
61 61
62struct pti_dev { 62struct pti_dev {
63 struct tty_port port; 63 struct tty_port port[PTITTY_MINOR_NUM];
64 unsigned long pti_addr; 64 unsigned long pti_addr;
65 unsigned long aperture_base; 65 unsigned long aperture_base;
66 void __iomem *pti_ioaddr; 66 void __iomem *pti_ioaddr;
@@ -76,7 +76,7 @@ struct pti_dev {
76 */ 76 */
77static DEFINE_MUTEX(alloclock); 77static DEFINE_MUTEX(alloclock);
78 78
79static struct pci_device_id pci_ids[] __devinitconst = { 79static const struct pci_device_id pci_ids[] __devinitconst = {
80 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x82B)}, 80 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x82B)},
81 {0} 81 {0}
82}; 82};
@@ -393,25 +393,6 @@ void pti_writedata(struct pti_masterchannel *mc, u8 *buf, int count)
393} 393}
394EXPORT_SYMBOL_GPL(pti_writedata); 394EXPORT_SYMBOL_GPL(pti_writedata);
395 395
396/**
397 * pti_pci_remove()- Driver exit method to remove PTI from
398 * PCI bus.
399 * @pdev: variable containing pci info of PTI.
400 */
401static void __devexit pti_pci_remove(struct pci_dev *pdev)
402{
403 struct pti_dev *drv_data;
404
405 drv_data = pci_get_drvdata(pdev);
406 if (drv_data != NULL) {
407 pci_iounmap(pdev, drv_data->pti_ioaddr);
408 pci_set_drvdata(pdev, NULL);
409 kfree(drv_data);
410 pci_release_region(pdev, 1);
411 pci_disable_device(pdev);
412 }
413}
414
415/* 396/*
416 * for the tty_driver_*() basic function descriptions, see tty_driver.h. 397 * for the tty_driver_*() basic function descriptions, see tty_driver.h.
417 * Specific header comments made for PTI-related specifics. 398 * Specific header comments made for PTI-related specifics.
@@ -446,7 +427,7 @@ static int pti_tty_driver_open(struct tty_struct *tty, struct file *filp)
446 * also removes a locking requirement for the actual write 427 * also removes a locking requirement for the actual write
447 * procedure. 428 * procedure.
448 */ 429 */
449 return tty_port_open(&drv_data->port, tty, filp); 430 return tty_port_open(tty->port, tty, filp);
450} 431}
451 432
452/** 433/**
@@ -462,7 +443,7 @@ static int pti_tty_driver_open(struct tty_struct *tty, struct file *filp)
462 */ 443 */
463static void pti_tty_driver_close(struct tty_struct *tty, struct file *filp) 444static void pti_tty_driver_close(struct tty_struct *tty, struct file *filp)
464{ 445{
465 tty_port_close(&drv_data->port, tty, filp); 446 tty_port_close(tty->port, tty, filp);
466} 447}
467 448
468/** 449/**
@@ -818,6 +799,7 @@ static const struct tty_port_operations tty_port_ops = {
818static int __devinit pti_pci_probe(struct pci_dev *pdev, 799static int __devinit pti_pci_probe(struct pci_dev *pdev,
819 const struct pci_device_id *ent) 800 const struct pci_device_id *ent)
820{ 801{
802 unsigned int a;
821 int retval = -EINVAL; 803 int retval = -EINVAL;
822 int pci_bar = 1; 804 int pci_bar = 1;
823 805
@@ -830,7 +812,7 @@ static int __devinit pti_pci_probe(struct pci_dev *pdev,
830 __func__, __LINE__); 812 __func__, __LINE__);
831 pr_err("%s(%d): Error value returned: %d\n", 813 pr_err("%s(%d): Error value returned: %d\n",
832 __func__, __LINE__, retval); 814 __func__, __LINE__, retval);
833 return retval; 815 goto err;
834 } 816 }
835 817
836 retval = pci_enable_device(pdev); 818 retval = pci_enable_device(pdev);
@@ -838,17 +820,16 @@ static int __devinit pti_pci_probe(struct pci_dev *pdev,
838 dev_err(&pdev->dev, 820 dev_err(&pdev->dev,
839 "%s: pci_enable_device() returned error %d\n", 821 "%s: pci_enable_device() returned error %d\n",
840 __func__, retval); 822 __func__, retval);
841 return retval; 823 goto err_unreg_misc;
842 } 824 }
843 825
844 drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL); 826 drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
845
846 if (drv_data == NULL) { 827 if (drv_data == NULL) {
847 retval = -ENOMEM; 828 retval = -ENOMEM;
848 dev_err(&pdev->dev, 829 dev_err(&pdev->dev,
849 "%s(%d): kmalloc() returned NULL memory.\n", 830 "%s(%d): kmalloc() returned NULL memory.\n",
850 __func__, __LINE__); 831 __func__, __LINE__);
851 return retval; 832 goto err_disable_pci;
852 } 833 }
853 drv_data->pti_addr = pci_resource_start(pdev, pci_bar); 834 drv_data->pti_addr = pci_resource_start(pdev, pci_bar);
854 835
@@ -857,33 +838,65 @@ static int __devinit pti_pci_probe(struct pci_dev *pdev,
857 dev_err(&pdev->dev, 838 dev_err(&pdev->dev,
858 "%s(%d): pci_request_region() returned error %d\n", 839 "%s(%d): pci_request_region() returned error %d\n",
859 __func__, __LINE__, retval); 840 __func__, __LINE__, retval);
860 kfree(drv_data); 841 goto err_free_dd;
861 return retval;
862 } 842 }
863 drv_data->aperture_base = drv_data->pti_addr+APERTURE_14; 843 drv_data->aperture_base = drv_data->pti_addr+APERTURE_14;
864 drv_data->pti_ioaddr = 844 drv_data->pti_ioaddr =
865 ioremap_nocache((u32)drv_data->aperture_base, 845 ioremap_nocache((u32)drv_data->aperture_base,
866 APERTURE_LEN); 846 APERTURE_LEN);
867 if (!drv_data->pti_ioaddr) { 847 if (!drv_data->pti_ioaddr) {
868 pci_release_region(pdev, pci_bar);
869 retval = -ENOMEM; 848 retval = -ENOMEM;
870 kfree(drv_data); 849 goto err_rel_reg;
871 return retval;
872 } 850 }
873 851
874 pci_set_drvdata(pdev, drv_data); 852 pci_set_drvdata(pdev, drv_data);
875 853
876 tty_port_init(&drv_data->port); 854 for (a = 0; a < PTITTY_MINOR_NUM; a++) {
877 drv_data->port.ops = &tty_port_ops; 855 struct tty_port *port = &drv_data->port[a];
856 tty_port_init(port);
857 port->ops = &tty_port_ops;
878 858
879 tty_register_device(pti_tty_driver, 0, &pdev->dev); 859 tty_port_register_device(port, pti_tty_driver, a, &pdev->dev);
880 tty_register_device(pti_tty_driver, 1, &pdev->dev); 860 }
881 861
882 register_console(&pti_console); 862 register_console(&pti_console);
883 863
864 return 0;
865err_rel_reg:
866 pci_release_region(pdev, pci_bar);
867err_free_dd:
868 kfree(drv_data);
869err_disable_pci:
870 pci_disable_device(pdev);
871err_unreg_misc:
872 misc_deregister(&pti_char_driver);
873err:
884 return retval; 874 return retval;
885} 875}
886 876
877/**
878 * pti_pci_remove()- Driver exit method to remove PTI from
879 * PCI bus.
880 * @pdev: variable containing pci info of PTI.
881 */
882static void __devexit pti_pci_remove(struct pci_dev *pdev)
883{
884 struct pti_dev *drv_data = pci_get_drvdata(pdev);
885
886 unregister_console(&pti_console);
887
888 tty_unregister_device(pti_tty_driver, 0);
889 tty_unregister_device(pti_tty_driver, 1);
890
891 iounmap(drv_data->pti_ioaddr);
892 pci_set_drvdata(pdev, NULL);
893 kfree(drv_data);
894 pci_release_region(pdev, 1);
895 pci_disable_device(pdev);
896
897 misc_deregister(&pti_char_driver);
898}
899
887static struct pci_driver pti_pci_driver = { 900static struct pci_driver pti_pci_driver = {
888 .name = PCINAME, 901 .name = PCINAME,
889 .id_table = pci_ids, 902 .id_table = pci_ids,
@@ -933,25 +946,24 @@ static int __init pti_init(void)
933 pr_err("%s(%d): Error value returned: %d\n", 946 pr_err("%s(%d): Error value returned: %d\n",
934 __func__, __LINE__, retval); 947 __func__, __LINE__, retval);
935 948
936 pti_tty_driver = NULL; 949 goto put_tty;
937 return retval;
938 } 950 }
939 951
940 retval = pci_register_driver(&pti_pci_driver); 952 retval = pci_register_driver(&pti_pci_driver);
941
942 if (retval) { 953 if (retval) {
943 pr_err("%s(%d): PCI registration failed of pti driver\n", 954 pr_err("%s(%d): PCI registration failed of pti driver\n",
944 __func__, __LINE__); 955 __func__, __LINE__);
945 pr_err("%s(%d): Error value returned: %d\n", 956 pr_err("%s(%d): Error value returned: %d\n",
946 __func__, __LINE__, retval); 957 __func__, __LINE__, retval);
947 958 goto unreg_tty;
948 tty_unregister_driver(pti_tty_driver);
949 pr_err("%s(%d): Unregistering TTY part of pti driver\n",
950 __func__, __LINE__);
951 pti_tty_driver = NULL;
952 return retval;
953 } 959 }
954 960
961 return 0;
962unreg_tty:
963 tty_unregister_driver(pti_tty_driver);
964put_tty:
965 put_tty_driver(pti_tty_driver);
966 pti_tty_driver = NULL;
955 return retval; 967 return retval;
956} 968}
957 969
@@ -960,31 +972,9 @@ static int __init pti_init(void)
960 */ 972 */
961static void __exit pti_exit(void) 973static void __exit pti_exit(void)
962{ 974{
963 int retval; 975 tty_unregister_driver(pti_tty_driver);
964
965 tty_unregister_device(pti_tty_driver, 0);
966 tty_unregister_device(pti_tty_driver, 1);
967
968 retval = tty_unregister_driver(pti_tty_driver);
969 if (retval) {
970 pr_err("%s(%d): TTY unregistration failed of pti driver\n",
971 __func__, __LINE__);
972 pr_err("%s(%d): Error value returned: %d\n",
973 __func__, __LINE__, retval);
974 }
975
976 pci_unregister_driver(&pti_pci_driver); 976 pci_unregister_driver(&pti_pci_driver);
977 977 put_tty_driver(pti_tty_driver);
978 retval = misc_deregister(&pti_char_driver);
979 if (retval) {
980 pr_err("%s(%d): CHAR unregistration failed of pti driver\n",
981 __func__, __LINE__);
982 pr_err("%s(%d): Error value returned: %d\n",
983 __func__, __LINE__, retval);
984 }
985
986 unregister_console(&pti_console);
987 return;
988} 978}
989 979
990module_init(pti_init); 980module_init(pti_init);