diff options
Diffstat (limited to 'drivers')
219 files changed, 15898 insertions, 4087 deletions
diff --git a/drivers/Kconfig b/drivers/Kconfig index 707650ab77a7..3e1c442deff9 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig | |||
@@ -8,6 +8,8 @@ source "drivers/connector/Kconfig" | |||
8 | 8 | ||
9 | source "drivers/mtd/Kconfig" | 9 | source "drivers/mtd/Kconfig" |
10 | 10 | ||
11 | source "drivers/of/Kconfig" | ||
12 | |||
11 | source "drivers/parport/Kconfig" | 13 | source "drivers/parport/Kconfig" |
12 | 14 | ||
13 | source "drivers/pnp/Kconfig" | 15 | source "drivers/pnp/Kconfig" |
diff --git a/drivers/Makefile b/drivers/Makefile index 0ea8e3237c0d..a9e4c5f922a0 100644 --- a/drivers/Makefile +++ b/drivers/Makefile | |||
@@ -86,3 +86,4 @@ obj-$(CONFIG_GENERIC_TIME) += clocksource/ | |||
86 | obj-$(CONFIG_DMA_ENGINE) += dma/ | 86 | obj-$(CONFIG_DMA_ENGINE) += dma/ |
87 | obj-$(CONFIG_HID) += hid/ | 87 | obj-$(CONFIG_HID) += hid/ |
88 | obj-$(CONFIG_PPC_PS3) += ps3/ | 88 | obj-$(CONFIG_PPC_PS3) += ps3/ |
89 | obj-$(CONFIG_OF) += of/ | ||
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c index 2e7ba615d760..00d53c2fd1e8 100644 --- a/drivers/acpi/osl.c +++ b/drivers/acpi/osl.c | |||
@@ -1098,7 +1098,7 @@ void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags) | |||
1098 | acpi_status | 1098 | acpi_status |
1099 | acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache) | 1099 | acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache) |
1100 | { | 1100 | { |
1101 | *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL); | 1101 | *cache = kmem_cache_create(name, size, 0, 0, NULL); |
1102 | if (*cache == NULL) | 1102 | if (*cache == NULL) |
1103 | return AE_ERROR; | 1103 | return AE_ERROR; |
1104 | else | 1104 | else |
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c index 11e4eb9f304e..06f212ff2b4f 100644 --- a/drivers/ata/ahci.c +++ b/drivers/ata/ahci.c | |||
@@ -99,6 +99,7 @@ enum { | |||
99 | HOST_CAP_SSC = (1 << 14), /* Slumber capable */ | 99 | HOST_CAP_SSC = (1 << 14), /* Slumber capable */ |
100 | HOST_CAP_CLO = (1 << 24), /* Command List Override support */ | 100 | HOST_CAP_CLO = (1 << 24), /* Command List Override support */ |
101 | HOST_CAP_SSS = (1 << 27), /* Staggered Spin-up */ | 101 | HOST_CAP_SSS = (1 << 27), /* Staggered Spin-up */ |
102 | HOST_CAP_SNTF = (1 << 29), /* SNotification register */ | ||
102 | HOST_CAP_NCQ = (1 << 30), /* Native Command Queueing */ | 103 | HOST_CAP_NCQ = (1 << 30), /* Native Command Queueing */ |
103 | HOST_CAP_64 = (1 << 31), /* PCI DAC (64-bit DMA) support */ | 104 | HOST_CAP_64 = (1 << 31), /* PCI DAC (64-bit DMA) support */ |
104 | 105 | ||
@@ -113,11 +114,11 @@ enum { | |||
113 | PORT_TFDATA = 0x20, /* taskfile data */ | 114 | PORT_TFDATA = 0x20, /* taskfile data */ |
114 | PORT_SIG = 0x24, /* device TF signature */ | 115 | PORT_SIG = 0x24, /* device TF signature */ |
115 | PORT_CMD_ISSUE = 0x38, /* command issue */ | 116 | PORT_CMD_ISSUE = 0x38, /* command issue */ |
116 | PORT_SCR = 0x28, /* SATA phy register block */ | ||
117 | PORT_SCR_STAT = 0x28, /* SATA phy register: SStatus */ | 117 | PORT_SCR_STAT = 0x28, /* SATA phy register: SStatus */ |
118 | PORT_SCR_CTL = 0x2c, /* SATA phy register: SControl */ | 118 | PORT_SCR_CTL = 0x2c, /* SATA phy register: SControl */ |
119 | PORT_SCR_ERR = 0x30, /* SATA phy register: SError */ | 119 | PORT_SCR_ERR = 0x30, /* SATA phy register: SError */ |
120 | PORT_SCR_ACT = 0x34, /* SATA phy register: SActive */ | 120 | PORT_SCR_ACT = 0x34, /* SATA phy register: SActive */ |
121 | PORT_SCR_NTF = 0x3c, /* SATA phy register: SNotification */ | ||
121 | 122 | ||
122 | /* PORT_IRQ_{STAT,MASK} bits */ | 123 | /* PORT_IRQ_{STAT,MASK} bits */ |
123 | PORT_IRQ_COLD_PRES = (1 << 31), /* cold presence detect */ | 124 | PORT_IRQ_COLD_PRES = (1 << 31), /* cold presence detect */ |
@@ -216,8 +217,8 @@ struct ahci_port_priv { | |||
216 | unsigned int ncq_saw_sdb:1; | 217 | unsigned int ncq_saw_sdb:1; |
217 | }; | 218 | }; |
218 | 219 | ||
219 | static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg); | 220 | static int ahci_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val); |
220 | static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); | 221 | static int ahci_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val); |
221 | static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); | 222 | static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); |
222 | static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc); | 223 | static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc); |
223 | static void ahci_irq_clear(struct ata_port *ap); | 224 | static void ahci_irq_clear(struct ata_port *ap); |
@@ -417,7 +418,10 @@ static const struct pci_device_id ahci_pci_tbl[] = { | |||
417 | 418 | ||
418 | /* ATI */ | 419 | /* ATI */ |
419 | { PCI_VDEVICE(ATI, 0x4380), board_ahci_sb600 }, /* ATI SB600 */ | 420 | { PCI_VDEVICE(ATI, 0x4380), board_ahci_sb600 }, /* ATI SB600 */ |
420 | { PCI_VDEVICE(ATI, 0x4390), board_ahci_sb600 }, /* ATI SB700 */ | 421 | { PCI_VDEVICE(ATI, 0x4390), board_ahci_sb600 }, /* ATI SB700 IDE */ |
422 | { PCI_VDEVICE(ATI, 0x4391), board_ahci_sb600 }, /* ATI SB700 AHCI */ | ||
423 | { PCI_VDEVICE(ATI, 0x4392), board_ahci_sb600 }, /* ATI SB700 nraid5 */ | ||
424 | { PCI_VDEVICE(ATI, 0x4393), board_ahci_sb600 }, /* ATI SB700 raid5 */ | ||
421 | 425 | ||
422 | /* VIA */ | 426 | /* VIA */ |
423 | { PCI_VDEVICE(VIA, 0x3349), board_ahci_vt8251 }, /* VIA VT8251 */ | 427 | { PCI_VDEVICE(VIA, 0x3349), board_ahci_vt8251 }, /* VIA VT8251 */ |
@@ -545,13 +549,19 @@ static void ahci_save_initial_config(struct pci_dev *pdev, | |||
545 | hpriv->saved_cap = cap = readl(mmio + HOST_CAP); | 549 | hpriv->saved_cap = cap = readl(mmio + HOST_CAP); |
546 | hpriv->saved_port_map = port_map = readl(mmio + HOST_PORTS_IMPL); | 550 | hpriv->saved_port_map = port_map = readl(mmio + HOST_PORTS_IMPL); |
547 | 551 | ||
548 | /* some chips lie about 64bit support */ | 552 | /* some chips have errata preventing 64bit use */ |
549 | if ((cap & HOST_CAP_64) && (pi->flags & AHCI_FLAG_32BIT_ONLY)) { | 553 | if ((cap & HOST_CAP_64) && (pi->flags & AHCI_FLAG_32BIT_ONLY)) { |
550 | dev_printk(KERN_INFO, &pdev->dev, | 554 | dev_printk(KERN_INFO, &pdev->dev, |
551 | "controller can't do 64bit DMA, forcing 32bit\n"); | 555 | "controller can't do 64bit DMA, forcing 32bit\n"); |
552 | cap &= ~HOST_CAP_64; | 556 | cap &= ~HOST_CAP_64; |
553 | } | 557 | } |
554 | 558 | ||
559 | if ((cap & HOST_CAP_NCQ) && (pi->flags & AHCI_FLAG_NO_NCQ)) { | ||
560 | dev_printk(KERN_INFO, &pdev->dev, | ||
561 | "controller can't do NCQ, turning off CAP_NCQ\n"); | ||
562 | cap &= ~HOST_CAP_NCQ; | ||
563 | } | ||
564 | |||
555 | /* fixup zero port_map */ | 565 | /* fixup zero port_map */ |
556 | if (!port_map) { | 566 | if (!port_map) { |
557 | port_map = (1 << ahci_nr_ports(cap)) - 1; | 567 | port_map = (1 << ahci_nr_ports(cap)) - 1; |
@@ -625,38 +635,45 @@ static void ahci_restore_initial_config(struct ata_host *host) | |||
625 | (void) readl(mmio + HOST_PORTS_IMPL); /* flush */ | 635 | (void) readl(mmio + HOST_PORTS_IMPL); /* flush */ |
626 | } | 636 | } |
627 | 637 | ||
628 | static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg_in) | 638 | static unsigned ahci_scr_offset(struct ata_port *ap, unsigned int sc_reg) |
629 | { | 639 | { |
630 | unsigned int sc_reg; | 640 | static const int offset[] = { |
631 | 641 | [SCR_STATUS] = PORT_SCR_STAT, | |
632 | switch (sc_reg_in) { | 642 | [SCR_CONTROL] = PORT_SCR_CTL, |
633 | case SCR_STATUS: sc_reg = 0; break; | 643 | [SCR_ERROR] = PORT_SCR_ERR, |
634 | case SCR_CONTROL: sc_reg = 1; break; | 644 | [SCR_ACTIVE] = PORT_SCR_ACT, |
635 | case SCR_ERROR: sc_reg = 2; break; | 645 | [SCR_NOTIFICATION] = PORT_SCR_NTF, |
636 | case SCR_ACTIVE: sc_reg = 3; break; | 646 | }; |
637 | default: | 647 | struct ahci_host_priv *hpriv = ap->host->private_data; |
638 | return 0xffffffffU; | ||
639 | } | ||
640 | 648 | ||
641 | return readl(ap->ioaddr.scr_addr + (sc_reg * 4)); | 649 | if (sc_reg < ARRAY_SIZE(offset) && |
650 | (sc_reg != SCR_NOTIFICATION || (hpriv->cap & HOST_CAP_SNTF))) | ||
651 | return offset[sc_reg]; | ||
652 | return 0; | ||
642 | } | 653 | } |
643 | 654 | ||
644 | 655 | static int ahci_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) | |
645 | static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg_in, | ||
646 | u32 val) | ||
647 | { | 656 | { |
648 | unsigned int sc_reg; | 657 | void __iomem *port_mmio = ahci_port_base(ap); |
649 | 658 | int offset = ahci_scr_offset(ap, sc_reg); | |
650 | switch (sc_reg_in) { | 659 | |
651 | case SCR_STATUS: sc_reg = 0; break; | 660 | if (offset) { |
652 | case SCR_CONTROL: sc_reg = 1; break; | 661 | *val = readl(port_mmio + offset); |
653 | case SCR_ERROR: sc_reg = 2; break; | 662 | return 0; |
654 | case SCR_ACTIVE: sc_reg = 3; break; | ||
655 | default: | ||
656 | return; | ||
657 | } | 663 | } |
664 | return -EINVAL; | ||
665 | } | ||
658 | 666 | ||
659 | writel(val, ap->ioaddr.scr_addr + (sc_reg * 4)); | 667 | static int ahci_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val) |
668 | { | ||
669 | void __iomem *port_mmio = ahci_port_base(ap); | ||
670 | int offset = ahci_scr_offset(ap, sc_reg); | ||
671 | |||
672 | if (offset) { | ||
673 | writel(val, port_mmio + offset); | ||
674 | return 0; | ||
675 | } | ||
676 | return -EINVAL; | ||
660 | } | 677 | } |
661 | 678 | ||
662 | static void ahci_start_engine(struct ata_port *ap) | 679 | static void ahci_start_engine(struct ata_port *ap) |
@@ -948,37 +965,87 @@ static void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag, | |||
948 | pp->cmd_slot[tag].tbl_addr_hi = cpu_to_le32((cmd_tbl_dma >> 16) >> 16); | 965 | pp->cmd_slot[tag].tbl_addr_hi = cpu_to_le32((cmd_tbl_dma >> 16) >> 16); |
949 | } | 966 | } |
950 | 967 | ||
951 | static int ahci_clo(struct ata_port *ap) | 968 | static int ahci_kick_engine(struct ata_port *ap, int force_restart) |
952 | { | 969 | { |
953 | void __iomem *port_mmio = ap->ioaddr.cmd_addr; | 970 | void __iomem *port_mmio = ap->ioaddr.cmd_addr; |
954 | struct ahci_host_priv *hpriv = ap->host->private_data; | 971 | struct ahci_host_priv *hpriv = ap->host->private_data; |
955 | u32 tmp; | 972 | u32 tmp; |
973 | int busy, rc; | ||
974 | |||
975 | /* do we need to kick the port? */ | ||
976 | busy = ahci_check_status(ap) & (ATA_BUSY | ATA_DRQ); | ||
977 | if (!busy && !force_restart) | ||
978 | return 0; | ||
979 | |||
980 | /* stop engine */ | ||
981 | rc = ahci_stop_engine(ap); | ||
982 | if (rc) | ||
983 | goto out_restart; | ||
956 | 984 | ||
957 | if (!(hpriv->cap & HOST_CAP_CLO)) | 985 | /* need to do CLO? */ |
958 | return -EOPNOTSUPP; | 986 | if (!busy) { |
987 | rc = 0; | ||
988 | goto out_restart; | ||
989 | } | ||
959 | 990 | ||
991 | if (!(hpriv->cap & HOST_CAP_CLO)) { | ||
992 | rc = -EOPNOTSUPP; | ||
993 | goto out_restart; | ||
994 | } | ||
995 | |||
996 | /* perform CLO */ | ||
960 | tmp = readl(port_mmio + PORT_CMD); | 997 | tmp = readl(port_mmio + PORT_CMD); |
961 | tmp |= PORT_CMD_CLO; | 998 | tmp |= PORT_CMD_CLO; |
962 | writel(tmp, port_mmio + PORT_CMD); | 999 | writel(tmp, port_mmio + PORT_CMD); |
963 | 1000 | ||
1001 | rc = 0; | ||
964 | tmp = ata_wait_register(port_mmio + PORT_CMD, | 1002 | tmp = ata_wait_register(port_mmio + PORT_CMD, |
965 | PORT_CMD_CLO, PORT_CMD_CLO, 1, 500); | 1003 | PORT_CMD_CLO, PORT_CMD_CLO, 1, 500); |
966 | if (tmp & PORT_CMD_CLO) | 1004 | if (tmp & PORT_CMD_CLO) |
967 | return -EIO; | 1005 | rc = -EIO; |
968 | 1006 | ||
969 | return 0; | 1007 | /* restart engine */ |
1008 | out_restart: | ||
1009 | ahci_start_engine(ap); | ||
1010 | return rc; | ||
970 | } | 1011 | } |
971 | 1012 | ||
972 | static int ahci_softreset(struct ata_port *ap, unsigned int *class, | 1013 | static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp, |
973 | unsigned long deadline) | 1014 | struct ata_taskfile *tf, int is_cmd, u16 flags, |
1015 | unsigned long timeout_msec) | ||
974 | { | 1016 | { |
1017 | const u32 cmd_fis_len = 5; /* five dwords */ | ||
975 | struct ahci_port_priv *pp = ap->private_data; | 1018 | struct ahci_port_priv *pp = ap->private_data; |
976 | void __iomem *port_mmio = ahci_port_base(ap); | 1019 | void __iomem *port_mmio = ahci_port_base(ap); |
977 | const u32 cmd_fis_len = 5; /* five dwords */ | 1020 | u8 *fis = pp->cmd_tbl; |
1021 | u32 tmp; | ||
1022 | |||
1023 | /* prep the command */ | ||
1024 | ata_tf_to_fis(tf, pmp, is_cmd, fis); | ||
1025 | ahci_fill_cmd_slot(pp, 0, cmd_fis_len | flags | (pmp << 12)); | ||
1026 | |||
1027 | /* issue & wait */ | ||
1028 | writel(1, port_mmio + PORT_CMD_ISSUE); | ||
1029 | |||
1030 | if (timeout_msec) { | ||
1031 | tmp = ata_wait_register(port_mmio + PORT_CMD_ISSUE, 0x1, 0x1, | ||
1032 | 1, timeout_msec); | ||
1033 | if (tmp & 0x1) { | ||
1034 | ahci_kick_engine(ap, 1); | ||
1035 | return -EBUSY; | ||
1036 | } | ||
1037 | } else | ||
1038 | readl(port_mmio + PORT_CMD_ISSUE); /* flush */ | ||
1039 | |||
1040 | return 0; | ||
1041 | } | ||
1042 | |||
1043 | static int ahci_do_softreset(struct ata_port *ap, unsigned int *class, | ||
1044 | int pmp, unsigned long deadline) | ||
1045 | { | ||
978 | const char *reason = NULL; | 1046 | const char *reason = NULL; |
1047 | unsigned long now, msecs; | ||
979 | struct ata_taskfile tf; | 1048 | struct ata_taskfile tf; |
980 | u32 tmp; | ||
981 | u8 *fis; | ||
982 | int rc; | 1049 | int rc; |
983 | 1050 | ||
984 | DPRINTK("ENTER\n"); | 1051 | DPRINTK("ENTER\n"); |
@@ -990,43 +1057,22 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class, | |||
990 | } | 1057 | } |
991 | 1058 | ||
992 | /* prepare for SRST (AHCI-1.1 10.4.1) */ | 1059 | /* prepare for SRST (AHCI-1.1 10.4.1) */ |
993 | rc = ahci_stop_engine(ap); | 1060 | rc = ahci_kick_engine(ap, 1); |
994 | if (rc) { | 1061 | if (rc) |
995 | reason = "failed to stop engine"; | 1062 | ata_port_printk(ap, KERN_WARNING, |
996 | goto fail_restart; | 1063 | "failed to reset engine (errno=%d)", rc); |
997 | } | ||
998 | |||
999 | /* check BUSY/DRQ, perform Command List Override if necessary */ | ||
1000 | if (ahci_check_status(ap) & (ATA_BUSY | ATA_DRQ)) { | ||
1001 | rc = ahci_clo(ap); | ||
1002 | |||
1003 | if (rc == -EOPNOTSUPP) { | ||
1004 | reason = "port busy but CLO unavailable"; | ||
1005 | goto fail_restart; | ||
1006 | } else if (rc) { | ||
1007 | reason = "port busy but CLO failed"; | ||
1008 | goto fail_restart; | ||
1009 | } | ||
1010 | } | ||
1011 | |||
1012 | /* restart engine */ | ||
1013 | ahci_start_engine(ap); | ||
1014 | 1064 | ||
1015 | ata_tf_init(ap->device, &tf); | 1065 | ata_tf_init(ap->device, &tf); |
1016 | fis = pp->cmd_tbl; | ||
1017 | 1066 | ||
1018 | /* issue the first D2H Register FIS */ | 1067 | /* issue the first D2H Register FIS */ |
1019 | ahci_fill_cmd_slot(pp, 0, | 1068 | msecs = 0; |
1020 | cmd_fis_len | AHCI_CMD_RESET | AHCI_CMD_CLR_BUSY); | 1069 | now = jiffies; |
1070 | if (time_after(now, deadline)) | ||
1071 | msecs = jiffies_to_msecs(deadline - now); | ||
1021 | 1072 | ||
1022 | tf.ctl |= ATA_SRST; | 1073 | tf.ctl |= ATA_SRST; |
1023 | ata_tf_to_fis(&tf, fis, 0); | 1074 | if (ahci_exec_polled_cmd(ap, pmp, &tf, 0, |
1024 | fis[1] &= ~(1 << 7); /* turn off Command FIS bit */ | 1075 | AHCI_CMD_RESET | AHCI_CMD_CLR_BUSY, msecs)) { |
1025 | |||
1026 | writel(1, port_mmio + PORT_CMD_ISSUE); | ||
1027 | |||
1028 | tmp = ata_wait_register(port_mmio + PORT_CMD_ISSUE, 0x1, 0x1, 1, 500); | ||
1029 | if (tmp & 0x1) { | ||
1030 | rc = -EIO; | 1076 | rc = -EIO; |
1031 | reason = "1st FIS failed"; | 1077 | reason = "1st FIS failed"; |
1032 | goto fail; | 1078 | goto fail; |
@@ -1036,14 +1082,8 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class, | |||
1036 | msleep(1); | 1082 | msleep(1); |
1037 | 1083 | ||
1038 | /* issue the second D2H Register FIS */ | 1084 | /* issue the second D2H Register FIS */ |
1039 | ahci_fill_cmd_slot(pp, 0, cmd_fis_len); | ||
1040 | |||
1041 | tf.ctl &= ~ATA_SRST; | 1085 | tf.ctl &= ~ATA_SRST; |
1042 | ata_tf_to_fis(&tf, fis, 0); | 1086 | ahci_exec_polled_cmd(ap, pmp, &tf, 0, 0, 0); |
1043 | fis[1] &= ~(1 << 7); /* turn off Command FIS bit */ | ||
1044 | |||
1045 | writel(1, port_mmio + PORT_CMD_ISSUE); | ||
1046 | readl(port_mmio + PORT_CMD_ISSUE); /* flush */ | ||
1047 | 1087 | ||
1048 | /* spec mandates ">= 2ms" before checking status. | 1088 | /* spec mandates ">= 2ms" before checking status. |
1049 | * We wait 150ms, because that was the magic delay used for | 1089 | * We wait 150ms, because that was the magic delay used for |
@@ -1066,13 +1106,17 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class, | |||
1066 | DPRINTK("EXIT, class=%u\n", *class); | 1106 | DPRINTK("EXIT, class=%u\n", *class); |
1067 | return 0; | 1107 | return 0; |
1068 | 1108 | ||
1069 | fail_restart: | ||
1070 | ahci_start_engine(ap); | ||
1071 | fail: | 1109 | fail: |
1072 | ata_port_printk(ap, KERN_ERR, "softreset failed (%s)\n", reason); | 1110 | ata_port_printk(ap, KERN_ERR, "softreset failed (%s)\n", reason); |
1073 | return rc; | 1111 | return rc; |
1074 | } | 1112 | } |
1075 | 1113 | ||
1114 | static int ahci_softreset(struct ata_port *ap, unsigned int *class, | ||
1115 | unsigned long deadline) | ||
1116 | { | ||
1117 | return ahci_do_softreset(ap, class, 0, deadline); | ||
1118 | } | ||
1119 | |||
1076 | static int ahci_hardreset(struct ata_port *ap, unsigned int *class, | 1120 | static int ahci_hardreset(struct ata_port *ap, unsigned int *class, |
1077 | unsigned long deadline) | 1121 | unsigned long deadline) |
1078 | { | 1122 | { |
@@ -1088,7 +1132,7 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class, | |||
1088 | /* clear D2H reception area to properly wait for D2H FIS */ | 1132 | /* clear D2H reception area to properly wait for D2H FIS */ |
1089 | ata_tf_init(ap->device, &tf); | 1133 | ata_tf_init(ap->device, &tf); |
1090 | tf.command = 0x80; | 1134 | tf.command = 0x80; |
1091 | ata_tf_to_fis(&tf, d2h_fis, 0); | 1135 | ata_tf_to_fis(&tf, 0, 0, d2h_fis); |
1092 | 1136 | ||
1093 | rc = sata_std_hardreset(ap, class, deadline); | 1137 | rc = sata_std_hardreset(ap, class, deadline); |
1094 | 1138 | ||
@@ -1106,6 +1150,7 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class, | |||
1106 | static int ahci_vt8251_hardreset(struct ata_port *ap, unsigned int *class, | 1150 | static int ahci_vt8251_hardreset(struct ata_port *ap, unsigned int *class, |
1107 | unsigned long deadline) | 1151 | unsigned long deadline) |
1108 | { | 1152 | { |
1153 | u32 serror; | ||
1109 | int rc; | 1154 | int rc; |
1110 | 1155 | ||
1111 | DPRINTK("ENTER\n"); | 1156 | DPRINTK("ENTER\n"); |
@@ -1116,7 +1161,8 @@ static int ahci_vt8251_hardreset(struct ata_port *ap, unsigned int *class, | |||
1116 | deadline); | 1161 | deadline); |
1117 | 1162 | ||
1118 | /* vt8251 needs SError cleared for the port to operate */ | 1163 | /* vt8251 needs SError cleared for the port to operate */ |
1119 | ahci_scr_write(ap, SCR_ERROR, ahci_scr_read(ap, SCR_ERROR)); | 1164 | ahci_scr_read(ap, SCR_ERROR, &serror); |
1165 | ahci_scr_write(ap, SCR_ERROR, serror); | ||
1120 | 1166 | ||
1121 | ahci_start_engine(ap); | 1167 | ahci_start_engine(ap); |
1122 | 1168 | ||
@@ -1205,7 +1251,7 @@ static void ahci_qc_prep(struct ata_queued_cmd *qc) | |||
1205 | */ | 1251 | */ |
1206 | cmd_tbl = pp->cmd_tbl + qc->tag * AHCI_CMD_TBL_SZ; | 1252 | cmd_tbl = pp->cmd_tbl + qc->tag * AHCI_CMD_TBL_SZ; |
1207 | 1253 | ||
1208 | ata_tf_to_fis(&qc->tf, cmd_tbl, 0); | 1254 | ata_tf_to_fis(&qc->tf, 0, 1, cmd_tbl); |
1209 | if (is_atapi) { | 1255 | if (is_atapi) { |
1210 | memset(cmd_tbl + AHCI_CMD_TBL_CDB, 0, 32); | 1256 | memset(cmd_tbl + AHCI_CMD_TBL_CDB, 0, 32); |
1211 | memcpy(cmd_tbl + AHCI_CMD_TBL_CDB, qc->cdb, qc->dev->cdb_len); | 1257 | memcpy(cmd_tbl + AHCI_CMD_TBL_CDB, qc->cdb, qc->dev->cdb_len); |
@@ -1238,7 +1284,7 @@ static void ahci_error_intr(struct ata_port *ap, u32 irq_stat) | |||
1238 | ata_ehi_clear_desc(ehi); | 1284 | ata_ehi_clear_desc(ehi); |
1239 | 1285 | ||
1240 | /* AHCI needs SError cleared; otherwise, it might lock up */ | 1286 | /* AHCI needs SError cleared; otherwise, it might lock up */ |
1241 | serror = ahci_scr_read(ap, SCR_ERROR); | 1287 | ahci_scr_read(ap, SCR_ERROR, &serror); |
1242 | ahci_scr_write(ap, SCR_ERROR, serror); | 1288 | ahci_scr_write(ap, SCR_ERROR, serror); |
1243 | 1289 | ||
1244 | /* analyze @irq_stat */ | 1290 | /* analyze @irq_stat */ |
@@ -1262,12 +1308,12 @@ static void ahci_error_intr(struct ata_port *ap, u32 irq_stat) | |||
1262 | if (irq_stat & PORT_IRQ_IF_ERR) { | 1308 | if (irq_stat & PORT_IRQ_IF_ERR) { |
1263 | err_mask |= AC_ERR_ATA_BUS; | 1309 | err_mask |= AC_ERR_ATA_BUS; |
1264 | action |= ATA_EH_SOFTRESET; | 1310 | action |= ATA_EH_SOFTRESET; |
1265 | ata_ehi_push_desc(ehi, ", interface fatal error"); | 1311 | ata_ehi_push_desc(ehi, "interface fatal error"); |
1266 | } | 1312 | } |
1267 | 1313 | ||
1268 | if (irq_stat & (PORT_IRQ_CONNECT | PORT_IRQ_PHYRDY)) { | 1314 | if (irq_stat & (PORT_IRQ_CONNECT | PORT_IRQ_PHYRDY)) { |
1269 | ata_ehi_hotplugged(ehi); | 1315 | ata_ehi_hotplugged(ehi); |
1270 | ata_ehi_push_desc(ehi, ", %s", irq_stat & PORT_IRQ_CONNECT ? | 1316 | ata_ehi_push_desc(ehi, "%s", irq_stat & PORT_IRQ_CONNECT ? |
1271 | "connection status changed" : "PHY RDY changed"); | 1317 | "connection status changed" : "PHY RDY changed"); |
1272 | } | 1318 | } |
1273 | 1319 | ||
@@ -1276,7 +1322,7 @@ static void ahci_error_intr(struct ata_port *ap, u32 irq_stat) | |||
1276 | 1322 | ||
1277 | err_mask |= AC_ERR_HSM; | 1323 | err_mask |= AC_ERR_HSM; |
1278 | action |= ATA_EH_SOFTRESET; | 1324 | action |= ATA_EH_SOFTRESET; |
1279 | ata_ehi_push_desc(ehi, ", unknown FIS %08x %08x %08x %08x", | 1325 | ata_ehi_push_desc(ehi, "unknown FIS %08x %08x %08x %08x", |
1280 | unk[0], unk[1], unk[2], unk[3]); | 1326 | unk[0], unk[1], unk[2], unk[3]); |
1281 | } | 1327 | } |
1282 | 1328 | ||
@@ -1512,11 +1558,17 @@ static void ahci_post_internal_cmd(struct ata_queued_cmd *qc) | |||
1512 | { | 1558 | { |
1513 | struct ata_port *ap = qc->ap; | 1559 | struct ata_port *ap = qc->ap; |
1514 | 1560 | ||
1515 | if (qc->flags & ATA_QCFLAG_FAILED) { | 1561 | /* make DMA engine forget about the failed command */ |
1516 | /* make DMA engine forget about the failed command */ | 1562 | if (qc->flags & ATA_QCFLAG_FAILED) |
1517 | ahci_stop_engine(ap); | 1563 | ahci_kick_engine(ap, 1); |
1518 | ahci_start_engine(ap); | 1564 | } |
1519 | } | 1565 | |
1566 | static int ahci_port_resume(struct ata_port *ap) | ||
1567 | { | ||
1568 | ahci_power_up(ap); | ||
1569 | ahci_start_port(ap); | ||
1570 | |||
1571 | return 0; | ||
1520 | } | 1572 | } |
1521 | 1573 | ||
1522 | #ifdef CONFIG_PM | 1574 | #ifdef CONFIG_PM |
@@ -1536,14 +1588,6 @@ static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg) | |||
1536 | return rc; | 1588 | return rc; |
1537 | } | 1589 | } |
1538 | 1590 | ||
1539 | static int ahci_port_resume(struct ata_port *ap) | ||
1540 | { | ||
1541 | ahci_power_up(ap); | ||
1542 | ahci_start_port(ap); | ||
1543 | |||
1544 | return 0; | ||
1545 | } | ||
1546 | |||
1547 | static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg) | 1591 | static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg) |
1548 | { | 1592 | { |
1549 | struct ata_host *host = dev_get_drvdata(&pdev->dev); | 1593 | struct ata_host *host = dev_get_drvdata(&pdev->dev); |
@@ -1734,12 +1778,13 @@ static void ahci_print_info(struct ata_host *host) | |||
1734 | 1778 | ||
1735 | dev_printk(KERN_INFO, &pdev->dev, | 1779 | dev_printk(KERN_INFO, &pdev->dev, |
1736 | "flags: " | 1780 | "flags: " |
1737 | "%s%s%s%s%s%s" | 1781 | "%s%s%s%s%s%s%s" |
1738 | "%s%s%s%s%s%s%s\n" | 1782 | "%s%s%s%s%s%s%s\n" |
1739 | , | 1783 | , |
1740 | 1784 | ||
1741 | cap & (1 << 31) ? "64bit " : "", | 1785 | cap & (1 << 31) ? "64bit " : "", |
1742 | cap & (1 << 30) ? "ncq " : "", | 1786 | cap & (1 << 30) ? "ncq " : "", |
1787 | cap & (1 << 29) ? "sntf " : "", | ||
1743 | cap & (1 << 28) ? "ilck " : "", | 1788 | cap & (1 << 28) ? "ilck " : "", |
1744 | cap & (1 << 27) ? "stag " : "", | 1789 | cap & (1 << 27) ? "stag " : "", |
1745 | cap & (1 << 26) ? "pm " : "", | 1790 | cap & (1 << 26) ? "pm " : "", |
@@ -1794,7 +1839,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
1794 | ahci_save_initial_config(pdev, &pi, hpriv); | 1839 | ahci_save_initial_config(pdev, &pi, hpriv); |
1795 | 1840 | ||
1796 | /* prepare host */ | 1841 | /* prepare host */ |
1797 | if (!(pi.flags & AHCI_FLAG_NO_NCQ) && (hpriv->cap & HOST_CAP_NCQ)) | 1842 | if (hpriv->cap & HOST_CAP_NCQ) |
1798 | pi.flags |= ATA_FLAG_NCQ; | 1843 | pi.flags |= ATA_FLAG_NCQ; |
1799 | 1844 | ||
1800 | host = ata_host_alloc_pinfo(&pdev->dev, ppi, fls(hpriv->port_map)); | 1845 | host = ata_host_alloc_pinfo(&pdev->dev, ppi, fls(hpriv->port_map)); |
@@ -1808,10 +1853,8 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
1808 | void __iomem *port_mmio = ahci_port_base(ap); | 1853 | void __iomem *port_mmio = ahci_port_base(ap); |
1809 | 1854 | ||
1810 | /* standard SATA port setup */ | 1855 | /* standard SATA port setup */ |
1811 | if (hpriv->port_map & (1 << i)) { | 1856 | if (hpriv->port_map & (1 << i)) |
1812 | ap->ioaddr.cmd_addr = port_mmio; | 1857 | ap->ioaddr.cmd_addr = port_mmio; |
1813 | ap->ioaddr.scr_addr = port_mmio + PORT_SCR; | ||
1814 | } | ||
1815 | 1858 | ||
1816 | /* disabled/not-implemented port */ | 1859 | /* disabled/not-implemented port */ |
1817 | else | 1860 | else |
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 88e2dd0983b5..6001aae0b884 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c | |||
@@ -111,8 +111,9 @@ MODULE_VERSION(DRV_VERSION); | |||
111 | /** | 111 | /** |
112 | * ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure | 112 | * ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure |
113 | * @tf: Taskfile to convert | 113 | * @tf: Taskfile to convert |
114 | * @fis: Buffer into which data will output | ||
115 | * @pmp: Port multiplier port | 114 | * @pmp: Port multiplier port |
115 | * @is_cmd: This FIS is for command | ||
116 | * @fis: Buffer into which data will output | ||
116 | * | 117 | * |
117 | * Converts a standard ATA taskfile to a Serial ATA | 118 | * Converts a standard ATA taskfile to a Serial ATA |
118 | * FIS structure (Register - Host to Device). | 119 | * FIS structure (Register - Host to Device). |
@@ -120,12 +121,13 @@ MODULE_VERSION(DRV_VERSION); | |||
120 | * LOCKING: | 121 | * LOCKING: |
121 | * Inherited from caller. | 122 | * Inherited from caller. |
122 | */ | 123 | */ |
123 | 124 | void ata_tf_to_fis(const struct ata_taskfile *tf, u8 pmp, int is_cmd, u8 *fis) | |
124 | void ata_tf_to_fis(const struct ata_taskfile *tf, u8 *fis, u8 pmp) | ||
125 | { | 125 | { |
126 | fis[0] = 0x27; /* Register - Host to Device FIS */ | 126 | fis[0] = 0x27; /* Register - Host to Device FIS */ |
127 | fis[1] = (pmp & 0xf) | (1 << 7); /* Port multiplier number, | 127 | fis[1] = pmp & 0xf; /* Port multiplier number*/ |
128 | bit 7 indicates Command FIS */ | 128 | if (is_cmd) |
129 | fis[1] |= (1 << 7); /* bit 7 indicates Command FIS */ | ||
130 | |||
129 | fis[2] = tf->command; | 131 | fis[2] = tf->command; |
130 | fis[3] = tf->feature; | 132 | fis[3] = tf->feature; |
131 | 133 | ||
@@ -2387,21 +2389,35 @@ int sata_down_spd_limit(struct ata_port *ap) | |||
2387 | u32 sstatus, spd, mask; | 2389 | u32 sstatus, spd, mask; |
2388 | int rc, highbit; | 2390 | int rc, highbit; |
2389 | 2391 | ||
2392 | if (!sata_scr_valid(ap)) | ||
2393 | return -EOPNOTSUPP; | ||
2394 | |||
2395 | /* If SCR can be read, use it to determine the current SPD. | ||
2396 | * If not, use cached value in ap->sata_spd. | ||
2397 | */ | ||
2390 | rc = sata_scr_read(ap, SCR_STATUS, &sstatus); | 2398 | rc = sata_scr_read(ap, SCR_STATUS, &sstatus); |
2391 | if (rc) | 2399 | if (rc == 0) |
2392 | return rc; | 2400 | spd = (sstatus >> 4) & 0xf; |
2401 | else | ||
2402 | spd = ap->sata_spd; | ||
2393 | 2403 | ||
2394 | mask = ap->sata_spd_limit; | 2404 | mask = ap->sata_spd_limit; |
2395 | if (mask <= 1) | 2405 | if (mask <= 1) |
2396 | return -EINVAL; | 2406 | return -EINVAL; |
2407 | |||
2408 | /* unconditionally mask off the highest bit */ | ||
2397 | highbit = fls(mask) - 1; | 2409 | highbit = fls(mask) - 1; |
2398 | mask &= ~(1 << highbit); | 2410 | mask &= ~(1 << highbit); |
2399 | 2411 | ||
2400 | spd = (sstatus >> 4) & 0xf; | 2412 | /* Mask off all speeds higher than or equal to the current |
2401 | if (spd <= 1) | 2413 | * one. Force 1.5Gbps if current SPD is not available. |
2402 | return -EINVAL; | 2414 | */ |
2403 | spd--; | 2415 | if (spd > 1) |
2404 | mask &= (1 << spd) - 1; | 2416 | mask &= (1 << (spd - 1)) - 1; |
2417 | else | ||
2418 | mask &= 1; | ||
2419 | |||
2420 | /* were we already at the bottom? */ | ||
2405 | if (!mask) | 2421 | if (!mask) |
2406 | return -EINVAL; | 2422 | return -EINVAL; |
2407 | 2423 | ||
@@ -3251,9 +3267,11 @@ int sata_phy_debounce(struct ata_port *ap, const unsigned long *params, | |||
3251 | last = cur; | 3267 | last = cur; |
3252 | last_jiffies = jiffies; | 3268 | last_jiffies = jiffies; |
3253 | 3269 | ||
3254 | /* check deadline */ | 3270 | /* Check deadline. If debouncing failed, return |
3271 | * -EPIPE to tell upper layer to lower link speed. | ||
3272 | */ | ||
3255 | if (time_after(jiffies, deadline)) | 3273 | if (time_after(jiffies, deadline)) |
3256 | return -EBUSY; | 3274 | return -EPIPE; |
3257 | } | 3275 | } |
3258 | } | 3276 | } |
3259 | 3277 | ||
@@ -3769,6 +3787,7 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = { | |||
3769 | { "Hitachi HTS541616J9SA00", "SB4OC70P", ATA_HORKAGE_NONCQ, }, | 3787 | { "Hitachi HTS541616J9SA00", "SB4OC70P", ATA_HORKAGE_NONCQ, }, |
3770 | { "WDC WD740ADFD-00NLR1", NULL, ATA_HORKAGE_NONCQ, }, | 3788 | { "WDC WD740ADFD-00NLR1", NULL, ATA_HORKAGE_NONCQ, }, |
3771 | { "FUJITSU MHV2080BH", "00840028", ATA_HORKAGE_NONCQ, }, | 3789 | { "FUJITSU MHV2080BH", "00840028", ATA_HORKAGE_NONCQ, }, |
3790 | { "ST9160821AS", "3.CLF", ATA_HORKAGE_NONCQ, }, | ||
3772 | 3791 | ||
3773 | /* Devices with NCQ limits */ | 3792 | /* Devices with NCQ limits */ |
3774 | 3793 | ||
@@ -5729,10 +5748,8 @@ int sata_scr_valid(struct ata_port *ap) | |||
5729 | */ | 5748 | */ |
5730 | int sata_scr_read(struct ata_port *ap, int reg, u32 *val) | 5749 | int sata_scr_read(struct ata_port *ap, int reg, u32 *val) |
5731 | { | 5750 | { |
5732 | if (sata_scr_valid(ap)) { | 5751 | if (sata_scr_valid(ap)) |
5733 | *val = ap->ops->scr_read(ap, reg); | 5752 | return ap->ops->scr_read(ap, reg, val); |
5734 | return 0; | ||
5735 | } | ||
5736 | return -EOPNOTSUPP; | 5753 | return -EOPNOTSUPP; |
5737 | } | 5754 | } |
5738 | 5755 | ||
@@ -5754,10 +5771,8 @@ int sata_scr_read(struct ata_port *ap, int reg, u32 *val) | |||
5754 | */ | 5771 | */ |
5755 | int sata_scr_write(struct ata_port *ap, int reg, u32 val) | 5772 | int sata_scr_write(struct ata_port *ap, int reg, u32 val) |
5756 | { | 5773 | { |
5757 | if (sata_scr_valid(ap)) { | 5774 | if (sata_scr_valid(ap)) |
5758 | ap->ops->scr_write(ap, reg, val); | 5775 | return ap->ops->scr_write(ap, reg, val); |
5759 | return 0; | ||
5760 | } | ||
5761 | return -EOPNOTSUPP; | 5776 | return -EOPNOTSUPP; |
5762 | } | 5777 | } |
5763 | 5778 | ||
@@ -5778,10 +5793,13 @@ int sata_scr_write(struct ata_port *ap, int reg, u32 val) | |||
5778 | */ | 5793 | */ |
5779 | int sata_scr_write_flush(struct ata_port *ap, int reg, u32 val) | 5794 | int sata_scr_write_flush(struct ata_port *ap, int reg, u32 val) |
5780 | { | 5795 | { |
5796 | int rc; | ||
5797 | |||
5781 | if (sata_scr_valid(ap)) { | 5798 | if (sata_scr_valid(ap)) { |
5782 | ap->ops->scr_write(ap, reg, val); | 5799 | rc = ap->ops->scr_write(ap, reg, val); |
5783 | ap->ops->scr_read(ap, reg); | 5800 | if (rc == 0) |
5784 | return 0; | 5801 | rc = ap->ops->scr_read(ap, reg, &val); |
5802 | return rc; | ||
5785 | } | 5803 | } |
5786 | return -EOPNOTSUPP; | 5804 | return -EOPNOTSUPP; |
5787 | } | 5805 | } |
@@ -5993,6 +6011,7 @@ void ata_dev_init(struct ata_device *dev) | |||
5993 | 6011 | ||
5994 | /* SATA spd limit is bound to the first device */ | 6012 | /* SATA spd limit is bound to the first device */ |
5995 | ap->sata_spd_limit = ap->hw_sata_spd_limit; | 6013 | ap->sata_spd_limit = ap->hw_sata_spd_limit; |
6014 | ap->sata_spd = 0; | ||
5996 | 6015 | ||
5997 | /* High bits of dev->flags are used to record warm plug | 6016 | /* High bits of dev->flags are used to record warm plug |
5998 | * requests which occur asynchronously. Synchronize using | 6017 | * requests which occur asynchronously. Synchronize using |
@@ -6058,6 +6077,9 @@ struct ata_port *ata_port_alloc(struct ata_host *host) | |||
6058 | INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan); | 6077 | INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan); |
6059 | INIT_LIST_HEAD(&ap->eh_done_q); | 6078 | INIT_LIST_HEAD(&ap->eh_done_q); |
6060 | init_waitqueue_head(&ap->eh_wait_q); | 6079 | init_waitqueue_head(&ap->eh_wait_q); |
6080 | init_timer_deferrable(&ap->fastdrain_timer); | ||
6081 | ap->fastdrain_timer.function = ata_eh_fastdrain_timerfn; | ||
6082 | ap->fastdrain_timer.data = (unsigned long)ap; | ||
6061 | 6083 | ||
6062 | ap->cbl = ATA_CBL_NONE; | 6084 | ap->cbl = ATA_CBL_NONE; |
6063 | 6085 | ||
@@ -6434,7 +6456,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht) | |||
6434 | for (i = 0; i < host->n_ports; i++) { | 6456 | for (i = 0; i < host->n_ports; i++) { |
6435 | struct ata_port *ap = host->ports[i]; | 6457 | struct ata_port *ap = host->ports[i]; |
6436 | 6458 | ||
6437 | ata_scsi_scan_host(ap); | 6459 | ata_scsi_scan_host(ap, 1); |
6438 | } | 6460 | } |
6439 | 6461 | ||
6440 | return 0; | 6462 | return 0; |
@@ -6942,6 +6964,9 @@ EXPORT_SYMBOL_GPL(ata_pci_default_filter); | |||
6942 | EXPORT_SYMBOL_GPL(ata_pci_clear_simplex); | 6964 | EXPORT_SYMBOL_GPL(ata_pci_clear_simplex); |
6943 | #endif /* CONFIG_PCI */ | 6965 | #endif /* CONFIG_PCI */ |
6944 | 6966 | ||
6967 | EXPORT_SYMBOL_GPL(__ata_ehi_push_desc); | ||
6968 | EXPORT_SYMBOL_GPL(ata_ehi_push_desc); | ||
6969 | EXPORT_SYMBOL_GPL(ata_ehi_clear_desc); | ||
6945 | EXPORT_SYMBOL_GPL(ata_eng_timeout); | 6970 | EXPORT_SYMBOL_GPL(ata_eng_timeout); |
6946 | EXPORT_SYMBOL_GPL(ata_port_schedule_eh); | 6971 | EXPORT_SYMBOL_GPL(ata_port_schedule_eh); |
6947 | EXPORT_SYMBOL_GPL(ata_port_abort); | 6972 | EXPORT_SYMBOL_GPL(ata_port_abort); |
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index 9aa62a0754f6..ac6ceed4bb60 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c | |||
@@ -56,6 +56,7 @@ enum { | |||
56 | */ | 56 | */ |
57 | enum { | 57 | enum { |
58 | ATA_EH_PRERESET_TIMEOUT = 10 * HZ, | 58 | ATA_EH_PRERESET_TIMEOUT = 10 * HZ, |
59 | ATA_EH_FASTDRAIN_INTERVAL = 3 * HZ, | ||
59 | }; | 60 | }; |
60 | 61 | ||
61 | /* The following table determines how we sequence resets. Each entry | 62 | /* The following table determines how we sequence resets. Each entry |
@@ -85,6 +86,71 @@ static void ata_eh_handle_port_resume(struct ata_port *ap) | |||
85 | { } | 86 | { } |
86 | #endif /* CONFIG_PM */ | 87 | #endif /* CONFIG_PM */ |
87 | 88 | ||
89 | static void __ata_ehi_pushv_desc(struct ata_eh_info *ehi, const char *fmt, | ||
90 | va_list args) | ||
91 | { | ||
92 | ehi->desc_len += vscnprintf(ehi->desc + ehi->desc_len, | ||
93 | ATA_EH_DESC_LEN - ehi->desc_len, | ||
94 | fmt, args); | ||
95 | } | ||
96 | |||
97 | /** | ||
98 | * __ata_ehi_push_desc - push error description without adding separator | ||
99 | * @ehi: target EHI | ||
100 | * @fmt: printf format string | ||
101 | * | ||
102 | * Format string according to @fmt and append it to @ehi->desc. | ||
103 | * | ||
104 | * LOCKING: | ||
105 | * spin_lock_irqsave(host lock) | ||
106 | */ | ||
107 | void __ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...) | ||
108 | { | ||
109 | va_list args; | ||
110 | |||
111 | va_start(args, fmt); | ||
112 | __ata_ehi_pushv_desc(ehi, fmt, args); | ||
113 | va_end(args); | ||
114 | } | ||
115 | |||
116 | /** | ||
117 | * ata_ehi_push_desc - push error description with separator | ||
118 | * @ehi: target EHI | ||
119 | * @fmt: printf format string | ||
120 | * | ||
121 | * Format string according to @fmt and append it to @ehi->desc. | ||
122 | * If @ehi->desc is not empty, ", " is added in-between. | ||
123 | * | ||
124 | * LOCKING: | ||
125 | * spin_lock_irqsave(host lock) | ||
126 | */ | ||
127 | void ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...) | ||
128 | { | ||
129 | va_list args; | ||
130 | |||
131 | if (ehi->desc_len) | ||
132 | __ata_ehi_push_desc(ehi, ", "); | ||
133 | |||
134 | va_start(args, fmt); | ||
135 | __ata_ehi_pushv_desc(ehi, fmt, args); | ||
136 | va_end(args); | ||
137 | } | ||
138 | |||
139 | /** | ||
140 | * ata_ehi_clear_desc - clean error description | ||
141 | * @ehi: target EHI | ||
142 | * | ||
143 | * Clear @ehi->desc. | ||
144 | * | ||
145 | * LOCKING: | ||
146 | * spin_lock_irqsave(host lock) | ||
147 | */ | ||
148 | void ata_ehi_clear_desc(struct ata_eh_info *ehi) | ||
149 | { | ||
150 | ehi->desc[0] = '\0'; | ||
151 | ehi->desc_len = 0; | ||
152 | } | ||
153 | |||
88 | static void ata_ering_record(struct ata_ering *ering, int is_io, | 154 | static void ata_ering_record(struct ata_ering *ering, int is_io, |
89 | unsigned int err_mask) | 155 | unsigned int err_mask) |
90 | { | 156 | { |
@@ -296,6 +362,9 @@ void ata_scsi_error(struct Scsi_Host *host) | |||
296 | repeat: | 362 | repeat: |
297 | /* invoke error handler */ | 363 | /* invoke error handler */ |
298 | if (ap->ops->error_handler) { | 364 | if (ap->ops->error_handler) { |
365 | /* kill fast drain timer */ | ||
366 | del_timer_sync(&ap->fastdrain_timer); | ||
367 | |||
299 | /* process port resume request */ | 368 | /* process port resume request */ |
300 | ata_eh_handle_port_resume(ap); | 369 | ata_eh_handle_port_resume(ap); |
301 | 370 | ||
@@ -511,6 +580,94 @@ void ata_eng_timeout(struct ata_port *ap) | |||
511 | DPRINTK("EXIT\n"); | 580 | DPRINTK("EXIT\n"); |
512 | } | 581 | } |
513 | 582 | ||
583 | static int ata_eh_nr_in_flight(struct ata_port *ap) | ||
584 | { | ||
585 | unsigned int tag; | ||
586 | int nr = 0; | ||
587 | |||
588 | /* count only non-internal commands */ | ||
589 | for (tag = 0; tag < ATA_MAX_QUEUE - 1; tag++) | ||
590 | if (ata_qc_from_tag(ap, tag)) | ||
591 | nr++; | ||
592 | |||
593 | return nr; | ||
594 | } | ||
595 | |||
596 | void ata_eh_fastdrain_timerfn(unsigned long arg) | ||
597 | { | ||
598 | struct ata_port *ap = (void *)arg; | ||
599 | unsigned long flags; | ||
600 | int cnt; | ||
601 | |||
602 | spin_lock_irqsave(ap->lock, flags); | ||
603 | |||
604 | cnt = ata_eh_nr_in_flight(ap); | ||
605 | |||
606 | /* are we done? */ | ||
607 | if (!cnt) | ||
608 | goto out_unlock; | ||
609 | |||
610 | if (cnt == ap->fastdrain_cnt) { | ||
611 | unsigned int tag; | ||
612 | |||
613 | /* No progress during the last interval, tag all | ||
614 | * in-flight qcs as timed out and freeze the port. | ||
615 | */ | ||
616 | for (tag = 0; tag < ATA_MAX_QUEUE - 1; tag++) { | ||
617 | struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag); | ||
618 | if (qc) | ||
619 | qc->err_mask |= AC_ERR_TIMEOUT; | ||
620 | } | ||
621 | |||
622 | ata_port_freeze(ap); | ||
623 | } else { | ||
624 | /* some qcs have finished, give it another chance */ | ||
625 | ap->fastdrain_cnt = cnt; | ||
626 | ap->fastdrain_timer.expires = | ||
627 | jiffies + ATA_EH_FASTDRAIN_INTERVAL; | ||
628 | add_timer(&ap->fastdrain_timer); | ||
629 | } | ||
630 | |||
631 | out_unlock: | ||
632 | spin_unlock_irqrestore(ap->lock, flags); | ||
633 | } | ||
634 | |||
635 | /** | ||
636 | * ata_eh_set_pending - set ATA_PFLAG_EH_PENDING and activate fast drain | ||
637 | * @ap: target ATA port | ||
638 | * @fastdrain: activate fast drain | ||
639 | * | ||
640 | * Set ATA_PFLAG_EH_PENDING and activate fast drain if @fastdrain | ||
641 | * is non-zero and EH wasn't pending before. Fast drain ensures | ||
642 | * that EH kicks in in timely manner. | ||
643 | * | ||
644 | * LOCKING: | ||
645 | * spin_lock_irqsave(host lock) | ||
646 | */ | ||
647 | static void ata_eh_set_pending(struct ata_port *ap, int fastdrain) | ||
648 | { | ||
649 | int cnt; | ||
650 | |||
651 | /* already scheduled? */ | ||
652 | if (ap->pflags & ATA_PFLAG_EH_PENDING) | ||
653 | return; | ||
654 | |||
655 | ap->pflags |= ATA_PFLAG_EH_PENDING; | ||
656 | |||
657 | if (!fastdrain) | ||
658 | return; | ||
659 | |||
660 | /* do we have in-flight qcs? */ | ||
661 | cnt = ata_eh_nr_in_flight(ap); | ||
662 | if (!cnt) | ||
663 | return; | ||
664 | |||
665 | /* activate fast drain */ | ||
666 | ap->fastdrain_cnt = cnt; | ||
667 | ap->fastdrain_timer.expires = jiffies + ATA_EH_FASTDRAIN_INTERVAL; | ||
668 | add_timer(&ap->fastdrain_timer); | ||
669 | } | ||
670 | |||
514 | /** | 671 | /** |
515 | * ata_qc_schedule_eh - schedule qc for error handling | 672 | * ata_qc_schedule_eh - schedule qc for error handling |
516 | * @qc: command to schedule error handling for | 673 | * @qc: command to schedule error handling for |
@@ -528,7 +685,7 @@ void ata_qc_schedule_eh(struct ata_queued_cmd *qc) | |||
528 | WARN_ON(!ap->ops->error_handler); | 685 | WARN_ON(!ap->ops->error_handler); |
529 | 686 | ||
530 | qc->flags |= ATA_QCFLAG_FAILED; | 687 | qc->flags |= ATA_QCFLAG_FAILED; |
531 | qc->ap->pflags |= ATA_PFLAG_EH_PENDING; | 688 | ata_eh_set_pending(ap, 1); |
532 | 689 | ||
533 | /* The following will fail if timeout has already expired. | 690 | /* The following will fail if timeout has already expired. |
534 | * ata_scsi_error() takes care of such scmds on EH entry. | 691 | * ata_scsi_error() takes care of such scmds on EH entry. |
@@ -555,7 +712,7 @@ void ata_port_schedule_eh(struct ata_port *ap) | |||
555 | if (ap->pflags & ATA_PFLAG_INITIALIZING) | 712 | if (ap->pflags & ATA_PFLAG_INITIALIZING) |
556 | return; | 713 | return; |
557 | 714 | ||
558 | ap->pflags |= ATA_PFLAG_EH_PENDING; | 715 | ata_eh_set_pending(ap, 1); |
559 | scsi_schedule_eh(ap->scsi_host); | 716 | scsi_schedule_eh(ap->scsi_host); |
560 | 717 | ||
561 | DPRINTK("port EH scheduled\n"); | 718 | DPRINTK("port EH scheduled\n"); |
@@ -579,6 +736,9 @@ int ata_port_abort(struct ata_port *ap) | |||
579 | 736 | ||
580 | WARN_ON(!ap->ops->error_handler); | 737 | WARN_ON(!ap->ops->error_handler); |
581 | 738 | ||
739 | /* we're gonna abort all commands, no need for fast drain */ | ||
740 | ata_eh_set_pending(ap, 0); | ||
741 | |||
582 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { | 742 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { |
583 | struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag); | 743 | struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag); |
584 | 744 | ||
@@ -1130,7 +1290,7 @@ static void ata_eh_analyze_ncq_error(struct ata_port *ap) | |||
1130 | /* we've got the perpetrator, condemn it */ | 1290 | /* we've got the perpetrator, condemn it */ |
1131 | qc = __ata_qc_from_tag(ap, tag); | 1291 | qc = __ata_qc_from_tag(ap, tag); |
1132 | memcpy(&qc->result_tf, &tf, sizeof(tf)); | 1292 | memcpy(&qc->result_tf, &tf, sizeof(tf)); |
1133 | qc->err_mask |= AC_ERR_DEV; | 1293 | qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ; |
1134 | ehc->i.err_mask &= ~AC_ERR_DEV; | 1294 | ehc->i.err_mask &= ~AC_ERR_DEV; |
1135 | } | 1295 | } |
1136 | 1296 | ||
@@ -1413,8 +1573,12 @@ static void ata_eh_autopsy(struct ata_port *ap) | |||
1413 | if (rc == 0) { | 1573 | if (rc == 0) { |
1414 | ehc->i.serror |= serror; | 1574 | ehc->i.serror |= serror; |
1415 | ata_eh_analyze_serror(ap); | 1575 | ata_eh_analyze_serror(ap); |
1416 | } else if (rc != -EOPNOTSUPP) | 1576 | } else if (rc != -EOPNOTSUPP) { |
1577 | /* SError read failed, force hardreset and probing */ | ||
1578 | ata_ehi_schedule_probe(&ehc->i); | ||
1417 | ehc->i.action |= ATA_EH_HARDRESET; | 1579 | ehc->i.action |= ATA_EH_HARDRESET; |
1580 | ehc->i.err_mask |= AC_ERR_OTHER; | ||
1581 | } | ||
1418 | 1582 | ||
1419 | /* analyze NCQ failure */ | 1583 | /* analyze NCQ failure */ |
1420 | ata_eh_analyze_ncq_error(ap); | 1584 | ata_eh_analyze_ncq_error(ap); |
@@ -1524,14 +1688,14 @@ static void ata_eh_report(struct ata_port *ap) | |||
1524 | ehc->i.err_mask, ap->sactive, ehc->i.serror, | 1688 | ehc->i.err_mask, ap->sactive, ehc->i.serror, |
1525 | ehc->i.action, frozen); | 1689 | ehc->i.action, frozen); |
1526 | if (desc) | 1690 | if (desc) |
1527 | ata_dev_printk(ehc->i.dev, KERN_ERR, "(%s)\n", desc); | 1691 | ata_dev_printk(ehc->i.dev, KERN_ERR, "%s\n", desc); |
1528 | } else { | 1692 | } else { |
1529 | ata_port_printk(ap, KERN_ERR, "exception Emask 0x%x " | 1693 | ata_port_printk(ap, KERN_ERR, "exception Emask 0x%x " |
1530 | "SAct 0x%x SErr 0x%x action 0x%x%s\n", | 1694 | "SAct 0x%x SErr 0x%x action 0x%x%s\n", |
1531 | ehc->i.err_mask, ap->sactive, ehc->i.serror, | 1695 | ehc->i.err_mask, ap->sactive, ehc->i.serror, |
1532 | ehc->i.action, frozen); | 1696 | ehc->i.action, frozen); |
1533 | if (desc) | 1697 | if (desc) |
1534 | ata_port_printk(ap, KERN_ERR, "(%s)\n", desc); | 1698 | ata_port_printk(ap, KERN_ERR, "%s\n", desc); |
1535 | } | 1699 | } |
1536 | 1700 | ||
1537 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { | 1701 | for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { |
@@ -1551,7 +1715,7 @@ static void ata_eh_report(struct ata_port *ap) | |||
1551 | "cmd %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x " | 1715 | "cmd %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x " |
1552 | "tag %d cdb 0x%x data %u %s\n " | 1716 | "tag %d cdb 0x%x data %u %s\n " |
1553 | "res %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x " | 1717 | "res %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x " |
1554 | "Emask 0x%x (%s)\n", | 1718 | "Emask 0x%x (%s)%s\n", |
1555 | cmd->command, cmd->feature, cmd->nsect, | 1719 | cmd->command, cmd->feature, cmd->nsect, |
1556 | cmd->lbal, cmd->lbam, cmd->lbah, | 1720 | cmd->lbal, cmd->lbam, cmd->lbah, |
1557 | cmd->hob_feature, cmd->hob_nsect, | 1721 | cmd->hob_feature, cmd->hob_nsect, |
@@ -1562,7 +1726,8 @@ static void ata_eh_report(struct ata_port *ap) | |||
1562 | res->lbal, res->lbam, res->lbah, | 1726 | res->lbal, res->lbam, res->lbah, |
1563 | res->hob_feature, res->hob_nsect, | 1727 | res->hob_feature, res->hob_nsect, |
1564 | res->hob_lbal, res->hob_lbam, res->hob_lbah, | 1728 | res->hob_lbal, res->hob_lbam, res->hob_lbah, |
1565 | res->device, qc->err_mask, ata_err_string(qc->err_mask)); | 1729 | res->device, qc->err_mask, ata_err_string(qc->err_mask), |
1730 | qc->err_mask & AC_ERR_NCQ ? " <F>" : ""); | ||
1566 | } | 1731 | } |
1567 | } | 1732 | } |
1568 | 1733 | ||
@@ -1648,7 +1813,7 @@ static int ata_eh_reset(struct ata_port *ap, int classify, | |||
1648 | } else | 1813 | } else |
1649 | ata_port_printk(ap, KERN_ERR, | 1814 | ata_port_printk(ap, KERN_ERR, |
1650 | "prereset failed (errno=%d)\n", rc); | 1815 | "prereset failed (errno=%d)\n", rc); |
1651 | return rc; | 1816 | goto out; |
1652 | } | 1817 | } |
1653 | } | 1818 | } |
1654 | 1819 | ||
@@ -1661,7 +1826,8 @@ static int ata_eh_reset(struct ata_port *ap, int classify, | |||
1661 | /* prereset told us not to reset, bang classes and return */ | 1826 | /* prereset told us not to reset, bang classes and return */ |
1662 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 1827 | for (i = 0; i < ATA_MAX_DEVICES; i++) |
1663 | classes[i] = ATA_DEV_NONE; | 1828 | classes[i] = ATA_DEV_NONE; |
1664 | return 0; | 1829 | rc = 0; |
1830 | goto out; | ||
1665 | } | 1831 | } |
1666 | 1832 | ||
1667 | /* did prereset() screw up? if so, fix up to avoid oopsing */ | 1833 | /* did prereset() screw up? if so, fix up to avoid oopsing */ |
@@ -1697,7 +1863,8 @@ static int ata_eh_reset(struct ata_port *ap, int classify, | |||
1697 | ata_port_printk(ap, KERN_ERR, | 1863 | ata_port_printk(ap, KERN_ERR, |
1698 | "follow-up softreset required " | 1864 | "follow-up softreset required " |
1699 | "but no softreset avaliable\n"); | 1865 | "but no softreset avaliable\n"); |
1700 | return -EINVAL; | 1866 | rc = -EINVAL; |
1867 | goto out; | ||
1701 | } | 1868 | } |
1702 | 1869 | ||
1703 | ata_eh_about_to_do(ap, NULL, ATA_EH_RESET_MASK); | 1870 | ata_eh_about_to_do(ap, NULL, ATA_EH_RESET_MASK); |
@@ -1707,7 +1874,8 @@ static int ata_eh_reset(struct ata_port *ap, int classify, | |||
1707 | classes[0] == ATA_DEV_UNKNOWN) { | 1874 | classes[0] == ATA_DEV_UNKNOWN) { |
1708 | ata_port_printk(ap, KERN_ERR, | 1875 | ata_port_printk(ap, KERN_ERR, |
1709 | "classification failed\n"); | 1876 | "classification failed\n"); |
1710 | return -EINVAL; | 1877 | rc = -EINVAL; |
1878 | goto out; | ||
1711 | } | 1879 | } |
1712 | } | 1880 | } |
1713 | 1881 | ||
@@ -1724,7 +1892,7 @@ static int ata_eh_reset(struct ata_port *ap, int classify, | |||
1724 | schedule_timeout_uninterruptible(delta); | 1892 | schedule_timeout_uninterruptible(delta); |
1725 | } | 1893 | } |
1726 | 1894 | ||
1727 | if (reset == hardreset && | 1895 | if (rc == -EPIPE || |
1728 | try == ARRAY_SIZE(ata_eh_reset_timeouts) - 1) | 1896 | try == ARRAY_SIZE(ata_eh_reset_timeouts) - 1) |
1729 | sata_down_spd_limit(ap); | 1897 | sata_down_spd_limit(ap); |
1730 | if (hardreset) | 1898 | if (hardreset) |
@@ -1733,12 +1901,18 @@ static int ata_eh_reset(struct ata_port *ap, int classify, | |||
1733 | } | 1901 | } |
1734 | 1902 | ||
1735 | if (rc == 0) { | 1903 | if (rc == 0) { |
1904 | u32 sstatus; | ||
1905 | |||
1736 | /* After the reset, the device state is PIO 0 and the | 1906 | /* After the reset, the device state is PIO 0 and the |
1737 | * controller state is undefined. Record the mode. | 1907 | * controller state is undefined. Record the mode. |
1738 | */ | 1908 | */ |
1739 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 1909 | for (i = 0; i < ATA_MAX_DEVICES; i++) |
1740 | ap->device[i].pio_mode = XFER_PIO_0; | 1910 | ap->device[i].pio_mode = XFER_PIO_0; |
1741 | 1911 | ||
1912 | /* record current link speed */ | ||
1913 | if (sata_scr_read(ap, SCR_STATUS, &sstatus) == 0) | ||
1914 | ap->sata_spd = (sstatus >> 4) & 0xf; | ||
1915 | |||
1742 | if (postreset) | 1916 | if (postreset) |
1743 | postreset(ap, classes); | 1917 | postreset(ap, classes); |
1744 | 1918 | ||
@@ -1746,7 +1920,9 @@ static int ata_eh_reset(struct ata_port *ap, int classify, | |||
1746 | ata_eh_done(ap, NULL, ehc->i.action & ATA_EH_RESET_MASK); | 1920 | ata_eh_done(ap, NULL, ehc->i.action & ATA_EH_RESET_MASK); |
1747 | ehc->i.action |= ATA_EH_REVALIDATE; | 1921 | ehc->i.action |= ATA_EH_REVALIDATE; |
1748 | } | 1922 | } |
1749 | 1923 | out: | |
1924 | /* clear hotplug flag */ | ||
1925 | ehc->i.flags &= ~ATA_EHI_HOTPLUGGED; | ||
1750 | return rc; | 1926 | return rc; |
1751 | } | 1927 | } |
1752 | 1928 | ||
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index cfde22da07ac..12ac0b511f79 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c | |||
@@ -2947,17 +2947,22 @@ int ata_scsi_add_hosts(struct ata_host *host, struct scsi_host_template *sht) | |||
2947 | return rc; | 2947 | return rc; |
2948 | } | 2948 | } |
2949 | 2949 | ||
2950 | void ata_scsi_scan_host(struct ata_port *ap) | 2950 | void ata_scsi_scan_host(struct ata_port *ap, int sync) |
2951 | { | 2951 | { |
2952 | int tries = 5; | ||
2953 | struct ata_device *last_failed_dev = NULL; | ||
2954 | struct ata_device *dev; | ||
2952 | unsigned int i; | 2955 | unsigned int i; |
2953 | 2956 | ||
2954 | if (ap->flags & ATA_FLAG_DISABLED) | 2957 | if (ap->flags & ATA_FLAG_DISABLED) |
2955 | return; | 2958 | return; |
2956 | 2959 | ||
2960 | repeat: | ||
2957 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | 2961 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
2958 | struct ata_device *dev = &ap->device[i]; | ||
2959 | struct scsi_device *sdev; | 2962 | struct scsi_device *sdev; |
2960 | 2963 | ||
2964 | dev = &ap->device[i]; | ||
2965 | |||
2961 | if (!ata_dev_enabled(dev) || dev->sdev) | 2966 | if (!ata_dev_enabled(dev) || dev->sdev) |
2962 | continue; | 2967 | continue; |
2963 | 2968 | ||
@@ -2967,6 +2972,45 @@ void ata_scsi_scan_host(struct ata_port *ap) | |||
2967 | scsi_device_put(sdev); | 2972 | scsi_device_put(sdev); |
2968 | } | 2973 | } |
2969 | } | 2974 | } |
2975 | |||
2976 | /* If we scanned while EH was in progress or allocation | ||
2977 | * failure occurred, scan would have failed silently. Check | ||
2978 | * whether all devices are attached. | ||
2979 | */ | ||
2980 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | ||
2981 | dev = &ap->device[i]; | ||
2982 | if (ata_dev_enabled(dev) && !dev->sdev) | ||
2983 | break; | ||
2984 | } | ||
2985 | if (i == ATA_MAX_DEVICES) | ||
2986 | return; | ||
2987 | |||
2988 | /* we're missing some SCSI devices */ | ||
2989 | if (sync) { | ||
2990 | /* If caller requested synchrnous scan && we've made | ||
2991 | * any progress, sleep briefly and repeat. | ||
2992 | */ | ||
2993 | if (dev != last_failed_dev) { | ||
2994 | msleep(100); | ||
2995 | last_failed_dev = dev; | ||
2996 | goto repeat; | ||
2997 | } | ||
2998 | |||
2999 | /* We might be failing to detect boot device, give it | ||
3000 | * a few more chances. | ||
3001 | */ | ||
3002 | if (--tries) { | ||
3003 | msleep(100); | ||
3004 | goto repeat; | ||
3005 | } | ||
3006 | |||
3007 | ata_port_printk(ap, KERN_ERR, "WARNING: synchronous SCSI scan " | ||
3008 | "failed without making any progress,\n" | ||
3009 | " switching to async\n"); | ||
3010 | } | ||
3011 | |||
3012 | queue_delayed_work(ata_aux_wq, &ap->hotplug_task, | ||
3013 | round_jiffies_relative(HZ)); | ||
2970 | } | 3014 | } |
2971 | 3015 | ||
2972 | /** | 3016 | /** |
@@ -3093,20 +3137,7 @@ void ata_scsi_hotplug(struct work_struct *work) | |||
3093 | } | 3137 | } |
3094 | 3138 | ||
3095 | /* scan for new ones */ | 3139 | /* scan for new ones */ |
3096 | ata_scsi_scan_host(ap); | 3140 | ata_scsi_scan_host(ap, 0); |
3097 | |||
3098 | /* If we scanned while EH was in progress, scan would have | ||
3099 | * failed silently. Requeue if there are enabled but | ||
3100 | * unattached devices. | ||
3101 | */ | ||
3102 | for (i = 0; i < ATA_MAX_DEVICES; i++) { | ||
3103 | struct ata_device *dev = &ap->device[i]; | ||
3104 | if (ata_dev_enabled(dev) && !dev->sdev) { | ||
3105 | queue_delayed_work(ata_aux_wq, &ap->hotplug_task, | ||
3106 | round_jiffies_relative(HZ)); | ||
3107 | break; | ||
3108 | } | ||
3109 | } | ||
3110 | 3141 | ||
3111 | DPRINTK("EXIT\n"); | 3142 | DPRINTK("EXIT\n"); |
3112 | } | 3143 | } |
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c index ca7d2245d684..6c289c7b1322 100644 --- a/drivers/ata/libata-sff.c +++ b/drivers/ata/libata-sff.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * libata-bmdma.c - helper library for PCI IDE BMDMA | 2 | * libata-sff.c - helper library for PCI IDE BMDMA |
3 | * | 3 | * |
4 | * Maintained by: Jeff Garzik <jgarzik@pobox.com> | 4 | * Maintained by: Jeff Garzik <jgarzik@pobox.com> |
5 | * Please ALWAYS copy linux-ide@vger.kernel.org | 5 | * Please ALWAYS copy linux-ide@vger.kernel.org |
@@ -211,6 +211,8 @@ void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf) | |||
211 | tf->hob_lbal = ioread8(ioaddr->lbal_addr); | 211 | tf->hob_lbal = ioread8(ioaddr->lbal_addr); |
212 | tf->hob_lbam = ioread8(ioaddr->lbam_addr); | 212 | tf->hob_lbam = ioread8(ioaddr->lbam_addr); |
213 | tf->hob_lbah = ioread8(ioaddr->lbah_addr); | 213 | tf->hob_lbah = ioread8(ioaddr->lbah_addr); |
214 | iowrite8(tf->ctl, ioaddr->ctl_addr); | ||
215 | ap->last_ctl = tf->ctl; | ||
214 | } | 216 | } |
215 | } | 217 | } |
216 | 218 | ||
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h index ba17fc5f2e99..564cd234c805 100644 --- a/drivers/ata/libata.h +++ b/drivers/ata/libata.h | |||
@@ -112,7 +112,7 @@ static inline int ata_acpi_on_devcfg(struct ata_device *adev) { return 0; } | |||
112 | /* libata-scsi.c */ | 112 | /* libata-scsi.c */ |
113 | extern int ata_scsi_add_hosts(struct ata_host *host, | 113 | extern int ata_scsi_add_hosts(struct ata_host *host, |
114 | struct scsi_host_template *sht); | 114 | struct scsi_host_template *sht); |
115 | extern void ata_scsi_scan_host(struct ata_port *ap); | 115 | extern void ata_scsi_scan_host(struct ata_port *ap, int sync); |
116 | extern int ata_scsi_offline_dev(struct ata_device *dev); | 116 | extern int ata_scsi_offline_dev(struct ata_device *dev); |
117 | extern void ata_scsi_hotplug(struct work_struct *work); | 117 | extern void ata_scsi_hotplug(struct work_struct *work); |
118 | extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf, | 118 | extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf, |
@@ -151,6 +151,7 @@ extern int ata_bus_probe(struct ata_port *ap); | |||
151 | extern enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd); | 151 | extern enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd); |
152 | extern void ata_scsi_error(struct Scsi_Host *host); | 152 | extern void ata_scsi_error(struct Scsi_Host *host); |
153 | extern void ata_port_wait_eh(struct ata_port *ap); | 153 | extern void ata_port_wait_eh(struct ata_port *ap); |
154 | extern void ata_eh_fastdrain_timerfn(unsigned long arg); | ||
154 | extern void ata_qc_schedule_eh(struct ata_queued_cmd *qc); | 155 | extern void ata_qc_schedule_eh(struct ata_queued_cmd *qc); |
155 | 156 | ||
156 | /* libata-sff.c */ | 157 | /* libata-sff.c */ |
diff --git a/drivers/ata/pata_cs5520.c b/drivers/ata/pata_cs5520.c index 6bf037d82b5a..7dc76e71bd55 100644 --- a/drivers/ata/pata_cs5520.c +++ b/drivers/ata/pata_cs5520.c | |||
@@ -275,7 +275,7 @@ static int __devinit cs5520_init_one(struct pci_dev *pdev, const struct pci_devi | |||
275 | 275 | ||
276 | for (i = 0; i < 2; i++) { | 276 | for (i = 0; i < 2; i++) { |
277 | static const int irq[] = { 14, 15 }; | 277 | static const int irq[] = { 14, 15 }; |
278 | struct ata_port *ap = host->ports[0]; | 278 | struct ata_port *ap = host->ports[i]; |
279 | 279 | ||
280 | if (ata_port_is_dummy(ap)) | 280 | if (ata_port_is_dummy(ap)) |
281 | continue; | 281 | continue; |
diff --git a/drivers/ata/pata_pcmcia.c b/drivers/ata/pata_pcmcia.c index a56257c98fe5..6da23feed039 100644 --- a/drivers/ata/pata_pcmcia.c +++ b/drivers/ata/pata_pcmcia.c | |||
@@ -382,6 +382,7 @@ static struct pcmcia_device_id pcmcia_devices[] = { | |||
382 | PCMCIA_DEVICE_PROD_ID12("HITACHI", "microdrive", 0xf4f43949, 0xa6d76178), | 382 | PCMCIA_DEVICE_PROD_ID12("HITACHI", "microdrive", 0xf4f43949, 0xa6d76178), |
383 | PCMCIA_DEVICE_PROD_ID12("IBM", "microdrive", 0xb569a6e5, 0xa6d76178), | 383 | PCMCIA_DEVICE_PROD_ID12("IBM", "microdrive", 0xb569a6e5, 0xa6d76178), |
384 | PCMCIA_DEVICE_PROD_ID12("IBM", "IBM17JSSFP20", 0xb569a6e5, 0xf2508753), | 384 | PCMCIA_DEVICE_PROD_ID12("IBM", "IBM17JSSFP20", 0xb569a6e5, 0xf2508753), |
385 | PCMCIA_DEVICE_PROD_ID12("KINGSTON", "CF8GB", 0x2e6d1829, 0xacbe682e), | ||
385 | PCMCIA_DEVICE_PROD_ID12("IO DATA", "CBIDE2 ", 0x547e66dc, 0x8671043b), | 386 | PCMCIA_DEVICE_PROD_ID12("IO DATA", "CBIDE2 ", 0x547e66dc, 0x8671043b), |
386 | PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDE", 0x547e66dc, 0x5c5ab149), | 387 | PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDE", 0x547e66dc, 0x5c5ab149), |
387 | PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDEII", 0x547e66dc, 0xb3662674), | 388 | PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDEII", 0x547e66dc, 0xb3662674), |
diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c index 79f841bca593..a909f793ffc1 100644 --- a/drivers/ata/pata_platform.c +++ b/drivers/ata/pata_platform.c | |||
@@ -213,8 +213,9 @@ static int __devinit pata_platform_probe(struct platform_device *pdev) | |||
213 | pata_platform_setup_port(&ap->ioaddr, pp_info); | 213 | pata_platform_setup_port(&ap->ioaddr, pp_info); |
214 | 214 | ||
215 | /* activate */ | 215 | /* activate */ |
216 | return ata_host_activate(host, platform_get_irq(pdev, 0), ata_interrupt, | 216 | return ata_host_activate(host, platform_get_irq(pdev, 0), |
217 | pp_info->irq_flags, &pata_platform_sht); | 217 | ata_interrupt, pp_info ? pp_info->irq_flags |
218 | : 0, &pata_platform_sht); | ||
218 | } | 219 | } |
219 | 220 | ||
220 | /** | 221 | /** |
diff --git a/drivers/ata/pata_scc.c b/drivers/ata/pata_scc.c index c55667e0eb65..36cdbd2b0bd5 100644 --- a/drivers/ata/pata_scc.c +++ b/drivers/ata/pata_scc.c | |||
@@ -238,12 +238,6 @@ static void scc_set_dmamode (struct ata_port *ap, struct ata_device *adev) | |||
238 | else | 238 | else |
239 | offset = 0; /* 100MHz */ | 239 | offset = 0; /* 100MHz */ |
240 | 240 | ||
241 | /* errata A308 workaround: limit ATAPI UDMA mode to UDMA4 */ | ||
242 | if (adev->class == ATA_DEV_ATAPI && speed > XFER_UDMA_4) { | ||
243 | printk(KERN_INFO "%s: limit ATAPI UDMA to UDMA4\n", DRV_NAME); | ||
244 | speed = XFER_UDMA_4; | ||
245 | } | ||
246 | |||
247 | if (speed >= XFER_UDMA_0) | 241 | if (speed >= XFER_UDMA_0) |
248 | idx = speed - XFER_UDMA_0; | 242 | idx = speed - XFER_UDMA_0; |
249 | else | 243 | else |
@@ -264,6 +258,17 @@ static void scc_set_dmamode (struct ata_port *ap, struct ata_device *adev) | |||
264 | JCTSStbl[offset][idx] << 16 | JCENVTtbl[offset][idx]); | 258 | JCTSStbl[offset][idx] << 16 | JCENVTtbl[offset][idx]); |
265 | } | 259 | } |
266 | 260 | ||
261 | unsigned long scc_mode_filter(struct ata_device *adev, unsigned long mask) | ||
262 | { | ||
263 | /* errata A308 workaround: limit ATAPI UDMA mode to UDMA4 */ | ||
264 | if (adev->class == ATA_DEV_ATAPI && | ||
265 | (mask & (0xE0 << ATA_SHIFT_UDMA))) { | ||
266 | printk(KERN_INFO "%s: limit ATAPI UDMA to UDMA4\n", DRV_NAME); | ||
267 | mask &= ~(0xE0 << ATA_SHIFT_UDMA); | ||
268 | } | ||
269 | return ata_pci_default_filter(adev, mask); | ||
270 | } | ||
271 | |||
267 | /** | 272 | /** |
268 | * scc_tf_load - send taskfile registers to host controller | 273 | * scc_tf_load - send taskfile registers to host controller |
269 | * @ap: Port to which output is sent | 274 | * @ap: Port to which output is sent |
@@ -358,6 +363,8 @@ static void scc_tf_read (struct ata_port *ap, struct ata_taskfile *tf) | |||
358 | tf->hob_lbal = in_be32(ioaddr->lbal_addr); | 363 | tf->hob_lbal = in_be32(ioaddr->lbal_addr); |
359 | tf->hob_lbam = in_be32(ioaddr->lbam_addr); | 364 | tf->hob_lbam = in_be32(ioaddr->lbam_addr); |
360 | tf->hob_lbah = in_be32(ioaddr->lbah_addr); | 365 | tf->hob_lbah = in_be32(ioaddr->lbah_addr); |
366 | out_be32(ioaddr->ctl_addr, tf->ctl); | ||
367 | ap->last_ctl = tf->ctl; | ||
361 | } | 368 | } |
362 | } | 369 | } |
363 | 370 | ||
@@ -741,7 +748,7 @@ static u8 scc_bmdma_status (struct ata_port *ap) | |||
741 | return host_stat; | 748 | return host_stat; |
742 | 749 | ||
743 | /* errata A252,A308 workaround: Step4 */ | 750 | /* errata A252,A308 workaround: Step4 */ |
744 | if (ata_altstatus(ap) & ATA_ERR && int_status & INTSTS_INTRQ) | 751 | if ((ata_altstatus(ap) & ATA_ERR) && (int_status & INTSTS_INTRQ)) |
745 | return (host_stat | ATA_DMA_INTR); | 752 | return (host_stat | ATA_DMA_INTR); |
746 | 753 | ||
747 | /* errata A308 workaround Step5 */ | 754 | /* errata A308 workaround Step5 */ |
@@ -752,11 +759,11 @@ static u8 scc_bmdma_status (struct ata_port *ap) | |||
752 | if ((qc->tf.protocol == ATA_PROT_DMA && | 759 | if ((qc->tf.protocol == ATA_PROT_DMA && |
753 | qc->dev->xfer_mode > XFER_UDMA_4)) { | 760 | qc->dev->xfer_mode > XFER_UDMA_4)) { |
754 | if (!(int_status & INTSTS_ACTEINT)) { | 761 | if (!(int_status & INTSTS_ACTEINT)) { |
755 | printk(KERN_WARNING "ata%u: data lost occurred. (ACTEINT==0, retry:%d)\n", | 762 | printk(KERN_WARNING "ata%u: operation failed (transfer data loss)\n", |
756 | ap->print_id, retry); | 763 | ap->print_id); |
757 | host_stat |= ATA_DMA_ERR; | 764 | host_stat |= ATA_DMA_ERR; |
758 | if (retry++) | 765 | if (retry++) |
759 | ap->udma_mask >>= 1; | 766 | ap->udma_mask &= ~(1 << qc->dev->xfer_mode); |
760 | } else | 767 | } else |
761 | retry = 0; | 768 | retry = 0; |
762 | } | 769 | } |
@@ -1016,7 +1023,7 @@ static const struct ata_port_operations scc_pata_ops = { | |||
1016 | .port_disable = ata_port_disable, | 1023 | .port_disable = ata_port_disable, |
1017 | .set_piomode = scc_set_piomode, | 1024 | .set_piomode = scc_set_piomode, |
1018 | .set_dmamode = scc_set_dmamode, | 1025 | .set_dmamode = scc_set_dmamode, |
1019 | .mode_filter = ata_pci_default_filter, | 1026 | .mode_filter = scc_mode_filter, |
1020 | 1027 | ||
1021 | .tf_load = scc_tf_load, | 1028 | .tf_load = scc_tf_load, |
1022 | .tf_read = scc_tf_read, | 1029 | .tf_read = scc_tf_read, |
diff --git a/drivers/ata/sata_inic162x.c b/drivers/ata/sata_inic162x.c index 3de183461c3c..a9c948d7604a 100644 --- a/drivers/ata/sata_inic162x.c +++ b/drivers/ata/sata_inic162x.c | |||
@@ -190,34 +190,34 @@ static void inic_reset_port(void __iomem *port_base) | |||
190 | writew(ctl, idma_ctl); | 190 | writew(ctl, idma_ctl); |
191 | } | 191 | } |
192 | 192 | ||
193 | static u32 inic_scr_read(struct ata_port *ap, unsigned sc_reg) | 193 | static int inic_scr_read(struct ata_port *ap, unsigned sc_reg, u32 *val) |
194 | { | 194 | { |
195 | void __iomem *scr_addr = ap->ioaddr.scr_addr; | 195 | void __iomem *scr_addr = ap->ioaddr.scr_addr; |
196 | void __iomem *addr; | 196 | void __iomem *addr; |
197 | u32 val; | ||
198 | 197 | ||
199 | if (unlikely(sc_reg >= ARRAY_SIZE(scr_map))) | 198 | if (unlikely(sc_reg >= ARRAY_SIZE(scr_map))) |
200 | return 0xffffffffU; | 199 | return -EINVAL; |
201 | 200 | ||
202 | addr = scr_addr + scr_map[sc_reg] * 4; | 201 | addr = scr_addr + scr_map[sc_reg] * 4; |
203 | val = readl(scr_addr + scr_map[sc_reg] * 4); | 202 | *val = readl(scr_addr + scr_map[sc_reg] * 4); |
204 | 203 | ||
205 | /* this controller has stuck DIAG.N, ignore it */ | 204 | /* this controller has stuck DIAG.N, ignore it */ |
206 | if (sc_reg == SCR_ERROR) | 205 | if (sc_reg == SCR_ERROR) |
207 | val &= ~SERR_PHYRDY_CHG; | 206 | *val &= ~SERR_PHYRDY_CHG; |
208 | return val; | 207 | return 0; |
209 | } | 208 | } |
210 | 209 | ||
211 | static void inic_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val) | 210 | static int inic_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val) |
212 | { | 211 | { |
213 | void __iomem *scr_addr = ap->ioaddr.scr_addr; | 212 | void __iomem *scr_addr = ap->ioaddr.scr_addr; |
214 | void __iomem *addr; | 213 | void __iomem *addr; |
215 | 214 | ||
216 | if (unlikely(sc_reg >= ARRAY_SIZE(scr_map))) | 215 | if (unlikely(sc_reg >= ARRAY_SIZE(scr_map))) |
217 | return; | 216 | return -EINVAL; |
218 | 217 | ||
219 | addr = scr_addr + scr_map[sc_reg] * 4; | 218 | addr = scr_addr + scr_map[sc_reg] * 4; |
220 | writel(val, scr_addr + scr_map[sc_reg] * 4); | 219 | writel(val, scr_addr + scr_map[sc_reg] * 4); |
220 | return 0; | ||
221 | } | 221 | } |
222 | 222 | ||
223 | /* | 223 | /* |
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c index fb8a749423ca..8ec520885b95 100644 --- a/drivers/ata/sata_mv.c +++ b/drivers/ata/sata_mv.c | |||
@@ -35,8 +35,6 @@ | |||
35 | 35 | ||
36 | 6) Add port multiplier support (intermediate) | 36 | 6) Add port multiplier support (intermediate) |
37 | 37 | ||
38 | 7) Test and verify 3.0 Gbps support | ||
39 | |||
40 | 8) Develop a low-power-consumption strategy, and implement it. | 38 | 8) Develop a low-power-consumption strategy, and implement it. |
41 | 39 | ||
42 | 9) [Experiment, low priority] See if ATAPI can be supported using | 40 | 9) [Experiment, low priority] See if ATAPI can be supported using |
@@ -227,26 +225,26 @@ enum { | |||
227 | 225 | ||
228 | EDMA_ERR_IRQ_CAUSE_OFS = 0x8, | 226 | EDMA_ERR_IRQ_CAUSE_OFS = 0x8, |
229 | EDMA_ERR_IRQ_MASK_OFS = 0xc, | 227 | EDMA_ERR_IRQ_MASK_OFS = 0xc, |
230 | EDMA_ERR_D_PAR = (1 << 0), | 228 | EDMA_ERR_D_PAR = (1 << 0), /* UDMA data parity err */ |
231 | EDMA_ERR_PRD_PAR = (1 << 1), | 229 | EDMA_ERR_PRD_PAR = (1 << 1), /* UDMA PRD parity err */ |
232 | EDMA_ERR_DEV = (1 << 2), | 230 | EDMA_ERR_DEV = (1 << 2), /* device error */ |
233 | EDMA_ERR_DEV_DCON = (1 << 3), | 231 | EDMA_ERR_DEV_DCON = (1 << 3), /* device disconnect */ |
234 | EDMA_ERR_DEV_CON = (1 << 4), | 232 | EDMA_ERR_DEV_CON = (1 << 4), /* device connected */ |
235 | EDMA_ERR_SERR = (1 << 5), | 233 | EDMA_ERR_SERR = (1 << 5), /* SError bits [WBDST] raised */ |
236 | EDMA_ERR_SELF_DIS = (1 << 7), /* Gen II/IIE self-disable */ | 234 | EDMA_ERR_SELF_DIS = (1 << 7), /* Gen II/IIE self-disable */ |
237 | EDMA_ERR_SELF_DIS_5 = (1 << 8), /* Gen I self-disable */ | 235 | EDMA_ERR_SELF_DIS_5 = (1 << 8), /* Gen I self-disable */ |
238 | EDMA_ERR_BIST_ASYNC = (1 << 8), | 236 | EDMA_ERR_BIST_ASYNC = (1 << 8), /* BIST FIS or Async Notify */ |
239 | EDMA_ERR_TRANS_IRQ_7 = (1 << 8), /* Gen IIE transprt layer irq */ | 237 | EDMA_ERR_TRANS_IRQ_7 = (1 << 8), /* Gen IIE transprt layer irq */ |
240 | EDMA_ERR_CRBQ_PAR = (1 << 9), | 238 | EDMA_ERR_CRQB_PAR = (1 << 9), /* CRQB parity error */ |
241 | EDMA_ERR_CRPB_PAR = (1 << 10), | 239 | EDMA_ERR_CRPB_PAR = (1 << 10), /* CRPB parity error */ |
242 | EDMA_ERR_INTRL_PAR = (1 << 11), | 240 | EDMA_ERR_INTRL_PAR = (1 << 11), /* internal parity error */ |
243 | EDMA_ERR_IORDY = (1 << 12), | 241 | EDMA_ERR_IORDY = (1 << 12), /* IORdy timeout */ |
244 | EDMA_ERR_LNK_CTRL_RX = (0xf << 13), | 242 | EDMA_ERR_LNK_CTRL_RX = (0xf << 13), /* link ctrl rx error */ |
245 | EDMA_ERR_LNK_CTRL_RX_2 = (1 << 15), | 243 | EDMA_ERR_LNK_CTRL_RX_2 = (1 << 15), |
246 | EDMA_ERR_LNK_DATA_RX = (0xf << 17), | 244 | EDMA_ERR_LNK_DATA_RX = (0xf << 17), /* link data rx error */ |
247 | EDMA_ERR_LNK_CTRL_TX = (0x1f << 21), | 245 | EDMA_ERR_LNK_CTRL_TX = (0x1f << 21), /* link ctrl tx error */ |
248 | EDMA_ERR_LNK_DATA_TX = (0x1f << 26), | 246 | EDMA_ERR_LNK_DATA_TX = (0x1f << 26), /* link data tx error */ |
249 | EDMA_ERR_TRANS_PROTO = (1 << 31), | 247 | EDMA_ERR_TRANS_PROTO = (1 << 31), /* transport protocol error */ |
250 | EDMA_ERR_OVERRUN_5 = (1 << 5), | 248 | EDMA_ERR_OVERRUN_5 = (1 << 5), |
251 | EDMA_ERR_UNDERRUN_5 = (1 << 6), | 249 | EDMA_ERR_UNDERRUN_5 = (1 << 6), |
252 | EDMA_EH_FREEZE = EDMA_ERR_D_PAR | | 250 | EDMA_EH_FREEZE = EDMA_ERR_D_PAR | |
@@ -255,7 +253,7 @@ enum { | |||
255 | EDMA_ERR_DEV_CON | | 253 | EDMA_ERR_DEV_CON | |
256 | EDMA_ERR_SERR | | 254 | EDMA_ERR_SERR | |
257 | EDMA_ERR_SELF_DIS | | 255 | EDMA_ERR_SELF_DIS | |
258 | EDMA_ERR_CRBQ_PAR | | 256 | EDMA_ERR_CRQB_PAR | |
259 | EDMA_ERR_CRPB_PAR | | 257 | EDMA_ERR_CRPB_PAR | |
260 | EDMA_ERR_INTRL_PAR | | 258 | EDMA_ERR_INTRL_PAR | |
261 | EDMA_ERR_IORDY | | 259 | EDMA_ERR_IORDY | |
@@ -270,7 +268,7 @@ enum { | |||
270 | EDMA_ERR_OVERRUN_5 | | 268 | EDMA_ERR_OVERRUN_5 | |
271 | EDMA_ERR_UNDERRUN_5 | | 269 | EDMA_ERR_UNDERRUN_5 | |
272 | EDMA_ERR_SELF_DIS_5 | | 270 | EDMA_ERR_SELF_DIS_5 | |
273 | EDMA_ERR_CRBQ_PAR | | 271 | EDMA_ERR_CRQB_PAR | |
274 | EDMA_ERR_CRPB_PAR | | 272 | EDMA_ERR_CRPB_PAR | |
275 | EDMA_ERR_INTRL_PAR | | 273 | EDMA_ERR_INTRL_PAR | |
276 | EDMA_ERR_IORDY, | 274 | EDMA_ERR_IORDY, |
@@ -286,10 +284,10 @@ enum { | |||
286 | EDMA_RSP_Q_OUT_PTR_OFS = 0x24, /* also contains BASE_LO */ | 284 | EDMA_RSP_Q_OUT_PTR_OFS = 0x24, /* also contains BASE_LO */ |
287 | EDMA_RSP_Q_PTR_SHIFT = 3, | 285 | EDMA_RSP_Q_PTR_SHIFT = 3, |
288 | 286 | ||
289 | EDMA_CMD_OFS = 0x28, | 287 | EDMA_CMD_OFS = 0x28, /* EDMA command register */ |
290 | EDMA_EN = (1 << 0), | 288 | EDMA_EN = (1 << 0), /* enable EDMA */ |
291 | EDMA_DS = (1 << 1), | 289 | EDMA_DS = (1 << 1), /* disable EDMA; self-negated */ |
292 | ATA_RST = (1 << 2), | 290 | ATA_RST = (1 << 2), /* reset trans/link/phy */ |
293 | 291 | ||
294 | EDMA_IORDY_TMOUT = 0x34, | 292 | EDMA_IORDY_TMOUT = 0x34, |
295 | EDMA_ARB_CFG = 0x38, | 293 | EDMA_ARB_CFG = 0x38, |
@@ -301,14 +299,13 @@ enum { | |||
301 | MV_HP_ERRATA_60X1B2 = (1 << 3), | 299 | MV_HP_ERRATA_60X1B2 = (1 << 3), |
302 | MV_HP_ERRATA_60X1C0 = (1 << 4), | 300 | MV_HP_ERRATA_60X1C0 = (1 << 4), |
303 | MV_HP_ERRATA_XX42A0 = (1 << 5), | 301 | MV_HP_ERRATA_XX42A0 = (1 << 5), |
304 | MV_HP_GEN_I = (1 << 6), | 302 | MV_HP_GEN_I = (1 << 6), /* Generation I: 50xx */ |
305 | MV_HP_GEN_II = (1 << 7), | 303 | MV_HP_GEN_II = (1 << 7), /* Generation II: 60xx */ |
306 | MV_HP_GEN_IIE = (1 << 8), | 304 | MV_HP_GEN_IIE = (1 << 8), /* Generation IIE: 6042/7042 */ |
307 | 305 | ||
308 | /* Port private flags (pp_flags) */ | 306 | /* Port private flags (pp_flags) */ |
309 | MV_PP_FLAG_EDMA_EN = (1 << 0), | 307 | MV_PP_FLAG_EDMA_EN = (1 << 0), /* is EDMA engine enabled? */ |
310 | MV_PP_FLAG_EDMA_DS_ACT = (1 << 1), | 308 | MV_PP_FLAG_HAD_A_RESET = (1 << 2), /* 1st hard reset complete? */ |
311 | MV_PP_FLAG_HAD_A_RESET = (1 << 2), | ||
312 | }; | 309 | }; |
313 | 310 | ||
314 | #define IS_GEN_I(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_I) | 311 | #define IS_GEN_I(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_I) |
@@ -318,8 +315,12 @@ enum { | |||
318 | enum { | 315 | enum { |
319 | MV_DMA_BOUNDARY = 0xffffffffU, | 316 | MV_DMA_BOUNDARY = 0xffffffffU, |
320 | 317 | ||
318 | /* mask of register bits containing lower 32 bits | ||
319 | * of EDMA request queue DMA address | ||
320 | */ | ||
321 | EDMA_REQ_Q_BASE_LO_MASK = 0xfffffc00U, | 321 | EDMA_REQ_Q_BASE_LO_MASK = 0xfffffc00U, |
322 | 322 | ||
323 | /* ditto, for response queue */ | ||
323 | EDMA_RSP_Q_BASE_LO_MASK = 0xffffff00U, | 324 | EDMA_RSP_Q_BASE_LO_MASK = 0xffffff00U, |
324 | }; | 325 | }; |
325 | 326 | ||
@@ -403,10 +404,10 @@ struct mv_host_priv { | |||
403 | }; | 404 | }; |
404 | 405 | ||
405 | static void mv_irq_clear(struct ata_port *ap); | 406 | static void mv_irq_clear(struct ata_port *ap); |
406 | static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in); | 407 | static int mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val); |
407 | static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); | 408 | static int mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); |
408 | static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in); | 409 | static int mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val); |
409 | static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); | 410 | static int mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); |
410 | static int mv_port_start(struct ata_port *ap); | 411 | static int mv_port_start(struct ata_port *ap); |
411 | static void mv_port_stop(struct ata_port *ap); | 412 | static void mv_port_stop(struct ata_port *ap); |
412 | static void mv_qc_prep(struct ata_queued_cmd *qc); | 413 | static void mv_qc_prep(struct ata_queued_cmd *qc); |
@@ -823,7 +824,7 @@ static void mv_start_dma(void __iomem *base, struct mv_host_priv *hpriv, | |||
823 | } | 824 | } |
824 | 825 | ||
825 | /** | 826 | /** |
826 | * mv_stop_dma - Disable eDMA engine | 827 | * __mv_stop_dma - Disable eDMA engine |
827 | * @ap: ATA channel to manipulate | 828 | * @ap: ATA channel to manipulate |
828 | * | 829 | * |
829 | * Verify the local cache of the eDMA state is accurate with a | 830 | * Verify the local cache of the eDMA state is accurate with a |
@@ -832,7 +833,7 @@ static void mv_start_dma(void __iomem *base, struct mv_host_priv *hpriv, | |||
832 | * LOCKING: | 833 | * LOCKING: |
833 | * Inherited from caller. | 834 | * Inherited from caller. |
834 | */ | 835 | */ |
835 | static int mv_stop_dma(struct ata_port *ap) | 836 | static int __mv_stop_dma(struct ata_port *ap) |
836 | { | 837 | { |
837 | void __iomem *port_mmio = mv_ap_base(ap); | 838 | void __iomem *port_mmio = mv_ap_base(ap); |
838 | struct mv_port_priv *pp = ap->private_data; | 839 | struct mv_port_priv *pp = ap->private_data; |
@@ -865,6 +866,18 @@ static int mv_stop_dma(struct ata_port *ap) | |||
865 | return err; | 866 | return err; |
866 | } | 867 | } |
867 | 868 | ||
869 | static int mv_stop_dma(struct ata_port *ap) | ||
870 | { | ||
871 | unsigned long flags; | ||
872 | int rc; | ||
873 | |||
874 | spin_lock_irqsave(&ap->host->lock, flags); | ||
875 | rc = __mv_stop_dma(ap); | ||
876 | spin_unlock_irqrestore(&ap->host->lock, flags); | ||
877 | |||
878 | return rc; | ||
879 | } | ||
880 | |||
868 | #ifdef ATA_DEBUG | 881 | #ifdef ATA_DEBUG |
869 | static void mv_dump_mem(void __iomem *start, unsigned bytes) | 882 | static void mv_dump_mem(void __iomem *start, unsigned bytes) |
870 | { | 883 | { |
@@ -961,22 +974,26 @@ static unsigned int mv_scr_offset(unsigned int sc_reg_in) | |||
961 | return ofs; | 974 | return ofs; |
962 | } | 975 | } |
963 | 976 | ||
964 | static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in) | 977 | static int mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val) |
965 | { | 978 | { |
966 | unsigned int ofs = mv_scr_offset(sc_reg_in); | 979 | unsigned int ofs = mv_scr_offset(sc_reg_in); |
967 | 980 | ||
968 | if (0xffffffffU != ofs) | 981 | if (ofs != 0xffffffffU) { |
969 | return readl(mv_ap_base(ap) + ofs); | 982 | *val = readl(mv_ap_base(ap) + ofs); |
970 | else | 983 | return 0; |
971 | return (u32) ofs; | 984 | } else |
985 | return -EINVAL; | ||
972 | } | 986 | } |
973 | 987 | ||
974 | static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) | 988 | static int mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) |
975 | { | 989 | { |
976 | unsigned int ofs = mv_scr_offset(sc_reg_in); | 990 | unsigned int ofs = mv_scr_offset(sc_reg_in); |
977 | 991 | ||
978 | if (0xffffffffU != ofs) | 992 | if (ofs != 0xffffffffU) { |
979 | writelfl(val, mv_ap_base(ap) + ofs); | 993 | writelfl(val, mv_ap_base(ap) + ofs); |
994 | return 0; | ||
995 | } else | ||
996 | return -EINVAL; | ||
980 | } | 997 | } |
981 | 998 | ||
982 | static void mv_edma_cfg(struct ata_port *ap, struct mv_host_priv *hpriv, | 999 | static void mv_edma_cfg(struct ata_port *ap, struct mv_host_priv *hpriv, |
@@ -1029,6 +1046,7 @@ static int mv_port_start(struct ata_port *ap) | |||
1029 | void __iomem *port_mmio = mv_ap_base(ap); | 1046 | void __iomem *port_mmio = mv_ap_base(ap); |
1030 | void *mem; | 1047 | void *mem; |
1031 | dma_addr_t mem_dma; | 1048 | dma_addr_t mem_dma; |
1049 | unsigned long flags; | ||
1032 | int rc; | 1050 | int rc; |
1033 | 1051 | ||
1034 | pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); | 1052 | pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); |
@@ -1067,10 +1085,14 @@ static int mv_port_start(struct ata_port *ap) | |||
1067 | pp->sg_tbl = mem; | 1085 | pp->sg_tbl = mem; |
1068 | pp->sg_tbl_dma = mem_dma; | 1086 | pp->sg_tbl_dma = mem_dma; |
1069 | 1087 | ||
1088 | spin_lock_irqsave(&ap->host->lock, flags); | ||
1089 | |||
1070 | mv_edma_cfg(ap, hpriv, port_mmio); | 1090 | mv_edma_cfg(ap, hpriv, port_mmio); |
1071 | 1091 | ||
1072 | mv_set_edma_ptrs(port_mmio, hpriv, pp); | 1092 | mv_set_edma_ptrs(port_mmio, hpriv, pp); |
1073 | 1093 | ||
1094 | spin_unlock_irqrestore(&ap->host->lock, flags); | ||
1095 | |||
1074 | /* Don't turn on EDMA here...do it before DMA commands only. Else | 1096 | /* Don't turn on EDMA here...do it before DMA commands only. Else |
1075 | * we'll be unable to send non-data, PIO, etc due to restricted access | 1097 | * we'll be unable to send non-data, PIO, etc due to restricted access |
1076 | * to shadow regs. | 1098 | * to shadow regs. |
@@ -1090,11 +1112,7 @@ static int mv_port_start(struct ata_port *ap) | |||
1090 | */ | 1112 | */ |
1091 | static void mv_port_stop(struct ata_port *ap) | 1113 | static void mv_port_stop(struct ata_port *ap) |
1092 | { | 1114 | { |
1093 | unsigned long flags; | ||
1094 | |||
1095 | spin_lock_irqsave(&ap->host->lock, flags); | ||
1096 | mv_stop_dma(ap); | 1115 | mv_stop_dma(ap); |
1097 | spin_unlock_irqrestore(&ap->host->lock, flags); | ||
1098 | } | 1116 | } |
1099 | 1117 | ||
1100 | /** | 1118 | /** |
@@ -1325,7 +1343,7 @@ static unsigned int mv_qc_issue(struct ata_queued_cmd *qc) | |||
1325 | * port. Turn off EDMA so there won't be problems accessing | 1343 | * port. Turn off EDMA so there won't be problems accessing |
1326 | * shadow block, etc registers. | 1344 | * shadow block, etc registers. |
1327 | */ | 1345 | */ |
1328 | mv_stop_dma(ap); | 1346 | __mv_stop_dma(ap); |
1329 | return ata_qc_issue_prot(qc); | 1347 | return ata_qc_issue_prot(qc); |
1330 | } | 1348 | } |
1331 | 1349 | ||
@@ -1393,16 +1411,16 @@ static void mv_err_intr(struct ata_port *ap, struct ata_queued_cmd *qc) | |||
1393 | if (edma_err_cause & EDMA_ERR_DEV) | 1411 | if (edma_err_cause & EDMA_ERR_DEV) |
1394 | err_mask |= AC_ERR_DEV; | 1412 | err_mask |= AC_ERR_DEV; |
1395 | if (edma_err_cause & (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR | | 1413 | if (edma_err_cause & (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR | |
1396 | EDMA_ERR_CRBQ_PAR | EDMA_ERR_CRPB_PAR | | 1414 | EDMA_ERR_CRQB_PAR | EDMA_ERR_CRPB_PAR | |
1397 | EDMA_ERR_INTRL_PAR)) { | 1415 | EDMA_ERR_INTRL_PAR)) { |
1398 | err_mask |= AC_ERR_ATA_BUS; | 1416 | err_mask |= AC_ERR_ATA_BUS; |
1399 | action |= ATA_EH_HARDRESET; | 1417 | action |= ATA_EH_HARDRESET; |
1400 | ata_ehi_push_desc(ehi, ", parity error"); | 1418 | ata_ehi_push_desc(ehi, "parity error"); |
1401 | } | 1419 | } |
1402 | if (edma_err_cause & (EDMA_ERR_DEV_DCON | EDMA_ERR_DEV_CON)) { | 1420 | if (edma_err_cause & (EDMA_ERR_DEV_DCON | EDMA_ERR_DEV_CON)) { |
1403 | ata_ehi_hotplugged(ehi); | 1421 | ata_ehi_hotplugged(ehi); |
1404 | ata_ehi_push_desc(ehi, edma_err_cause & EDMA_ERR_DEV_DCON ? | 1422 | ata_ehi_push_desc(ehi, edma_err_cause & EDMA_ERR_DEV_DCON ? |
1405 | ", dev disconnect" : ", dev connect"); | 1423 | "dev disconnect" : "dev connect"); |
1406 | } | 1424 | } |
1407 | 1425 | ||
1408 | if (IS_GEN_I(hpriv)) { | 1426 | if (IS_GEN_I(hpriv)) { |
@@ -1411,7 +1429,7 @@ static void mv_err_intr(struct ata_port *ap, struct ata_queued_cmd *qc) | |||
1411 | if (edma_err_cause & EDMA_ERR_SELF_DIS_5) { | 1429 | if (edma_err_cause & EDMA_ERR_SELF_DIS_5) { |
1412 | struct mv_port_priv *pp = ap->private_data; | 1430 | struct mv_port_priv *pp = ap->private_data; |
1413 | pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; | 1431 | pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; |
1414 | ata_ehi_push_desc(ehi, ", EDMA self-disable"); | 1432 | ata_ehi_push_desc(ehi, "EDMA self-disable"); |
1415 | } | 1433 | } |
1416 | } else { | 1434 | } else { |
1417 | eh_freeze_mask = EDMA_EH_FREEZE; | 1435 | eh_freeze_mask = EDMA_EH_FREEZE; |
@@ -1419,7 +1437,7 @@ static void mv_err_intr(struct ata_port *ap, struct ata_queued_cmd *qc) | |||
1419 | if (edma_err_cause & EDMA_ERR_SELF_DIS) { | 1437 | if (edma_err_cause & EDMA_ERR_SELF_DIS) { |
1420 | struct mv_port_priv *pp = ap->private_data; | 1438 | struct mv_port_priv *pp = ap->private_data; |
1421 | pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; | 1439 | pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; |
1422 | ata_ehi_push_desc(ehi, ", EDMA self-disable"); | 1440 | ata_ehi_push_desc(ehi, "EDMA self-disable"); |
1423 | } | 1441 | } |
1424 | 1442 | ||
1425 | if (edma_err_cause & EDMA_ERR_SERR) { | 1443 | if (edma_err_cause & EDMA_ERR_SERR) { |
@@ -1489,33 +1507,30 @@ static void mv_intr_edma(struct ata_port *ap) | |||
1489 | 1507 | ||
1490 | while (1) { | 1508 | while (1) { |
1491 | u16 status; | 1509 | u16 status; |
1510 | unsigned int tag; | ||
1492 | 1511 | ||
1493 | /* get s/w response queue last-read pointer, and compare */ | 1512 | /* get s/w response queue last-read pointer, and compare */ |
1494 | out_index = pp->resp_idx & MV_MAX_Q_DEPTH_MASK; | 1513 | out_index = pp->resp_idx & MV_MAX_Q_DEPTH_MASK; |
1495 | if (in_index == out_index) | 1514 | if (in_index == out_index) |
1496 | break; | 1515 | break; |
1497 | 1516 | ||
1498 | |||
1499 | /* 50xx: get active ATA command */ | 1517 | /* 50xx: get active ATA command */ |
1500 | if (IS_GEN_I(hpriv)) | 1518 | if (IS_GEN_I(hpriv)) |
1501 | qc = ata_qc_from_tag(ap, ap->active_tag); | 1519 | tag = ap->active_tag; |
1502 | 1520 | ||
1503 | /* 60xx: get active ATA command via tag, to enable support | 1521 | /* Gen II/IIE: get active ATA command via tag, to enable |
1504 | * for queueing. this works transparently for queued and | 1522 | * support for queueing. this works transparently for |
1505 | * non-queued modes. | 1523 | * queued and non-queued modes. |
1506 | */ | 1524 | */ |
1507 | else { | 1525 | else if (IS_GEN_II(hpriv)) |
1508 | unsigned int tag; | 1526 | tag = (le16_to_cpu(pp->crpb[out_index].id) |
1527 | >> CRPB_IOID_SHIFT_6) & 0x3f; | ||
1509 | 1528 | ||
1510 | if (IS_GEN_II(hpriv)) | 1529 | else /* IS_GEN_IIE */ |
1511 | tag = (le16_to_cpu(pp->crpb[out_index].id) | 1530 | tag = (le16_to_cpu(pp->crpb[out_index].id) |
1512 | >> CRPB_IOID_SHIFT_6) & 0x3f; | 1531 | >> CRPB_IOID_SHIFT_7) & 0x3f; |
1513 | else | ||
1514 | tag = (le16_to_cpu(pp->crpb[out_index].id) | ||
1515 | >> CRPB_IOID_SHIFT_7) & 0x3f; | ||
1516 | 1532 | ||
1517 | qc = ata_qc_from_tag(ap, tag); | 1533 | qc = ata_qc_from_tag(ap, tag); |
1518 | } | ||
1519 | 1534 | ||
1520 | /* lower 8 bits of status are EDMA_ERR_IRQ_CAUSE_OFS | 1535 | /* lower 8 bits of status are EDMA_ERR_IRQ_CAUSE_OFS |
1521 | * bits (WARNING: might not necessarily be associated | 1536 | * bits (WARNING: might not necessarily be associated |
@@ -1535,7 +1550,7 @@ static void mv_intr_edma(struct ata_port *ap) | |||
1535 | ata_qc_complete(qc); | 1550 | ata_qc_complete(qc); |
1536 | } | 1551 | } |
1537 | 1552 | ||
1538 | /* advance software response queue pointer, to | 1553 | /* advance software response queue pointer, to |
1539 | * indicate (after the loop completes) to hardware | 1554 | * indicate (after the loop completes) to hardware |
1540 | * that we have consumed a response queue entry. | 1555 | * that we have consumed a response queue entry. |
1541 | */ | 1556 | */ |
@@ -1741,26 +1756,30 @@ static unsigned int mv5_scr_offset(unsigned int sc_reg_in) | |||
1741 | return ofs; | 1756 | return ofs; |
1742 | } | 1757 | } |
1743 | 1758 | ||
1744 | static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in) | 1759 | static int mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val) |
1745 | { | 1760 | { |
1746 | void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; | 1761 | void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; |
1747 | void __iomem *addr = mv5_phy_base(mmio, ap->port_no); | 1762 | void __iomem *addr = mv5_phy_base(mmio, ap->port_no); |
1748 | unsigned int ofs = mv5_scr_offset(sc_reg_in); | 1763 | unsigned int ofs = mv5_scr_offset(sc_reg_in); |
1749 | 1764 | ||
1750 | if (ofs != 0xffffffffU) | 1765 | if (ofs != 0xffffffffU) { |
1751 | return readl(addr + ofs); | 1766 | *val = readl(addr + ofs); |
1752 | else | 1767 | return 0; |
1753 | return (u32) ofs; | 1768 | } else |
1769 | return -EINVAL; | ||
1754 | } | 1770 | } |
1755 | 1771 | ||
1756 | static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) | 1772 | static int mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) |
1757 | { | 1773 | { |
1758 | void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; | 1774 | void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; |
1759 | void __iomem *addr = mv5_phy_base(mmio, ap->port_no); | 1775 | void __iomem *addr = mv5_phy_base(mmio, ap->port_no); |
1760 | unsigned int ofs = mv5_scr_offset(sc_reg_in); | 1776 | unsigned int ofs = mv5_scr_offset(sc_reg_in); |
1761 | 1777 | ||
1762 | if (ofs != 0xffffffffU) | 1778 | if (ofs != 0xffffffffU) { |
1763 | writelfl(val, addr + ofs); | 1779 | writelfl(val, addr + ofs); |
1780 | return 0; | ||
1781 | } else | ||
1782 | return -EINVAL; | ||
1764 | } | 1783 | } |
1765 | 1784 | ||
1766 | static void mv5_reset_bus(struct pci_dev *pdev, void __iomem *mmio) | 1785 | static void mv5_reset_bus(struct pci_dev *pdev, void __iomem *mmio) |
@@ -2138,9 +2157,17 @@ static void mv_phy_reset(struct ata_port *ap, unsigned int *class, | |||
2138 | 2157 | ||
2139 | VPRINTK("ENTER, port %u, mmio 0x%p\n", ap->port_no, port_mmio); | 2158 | VPRINTK("ENTER, port %u, mmio 0x%p\n", ap->port_no, port_mmio); |
2140 | 2159 | ||
2141 | DPRINTK("S-regs after ATA_RST: SStat 0x%08x SErr 0x%08x " | 2160 | #ifdef DEBUG |
2142 | "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS), | 2161 | { |
2143 | mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL)); | 2162 | u32 sstatus, serror, scontrol; |
2163 | |||
2164 | mv_scr_read(ap, SCR_STATUS, &sstatus); | ||
2165 | mv_scr_read(ap, SCR_ERROR, &serror); | ||
2166 | mv_scr_read(ap, SCR_CONTROL, &scontrol); | ||
2167 | DPRINTK("S-regs after ATA_RST: SStat 0x%08x SErr 0x%08x " | ||
2168 | "SCtrl 0x%08x\n", status, serror, scontrol); | ||
2169 | } | ||
2170 | #endif | ||
2144 | 2171 | ||
2145 | /* Issue COMRESET via SControl */ | 2172 | /* Issue COMRESET via SControl */ |
2146 | comreset_retry: | 2173 | comreset_retry: |
@@ -2164,9 +2191,17 @@ comreset_retry: | |||
2164 | (retry-- > 0)) | 2191 | (retry-- > 0)) |
2165 | goto comreset_retry; | 2192 | goto comreset_retry; |
2166 | 2193 | ||
2167 | DPRINTK("S-regs after PHY wake: SStat 0x%08x SErr 0x%08x " | 2194 | #ifdef DEBUG |
2168 | "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS), | 2195 | { |
2169 | mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL)); | 2196 | u32 sstatus, serror, scontrol; |
2197 | |||
2198 | mv_scr_read(ap, SCR_STATUS, &sstatus); | ||
2199 | mv_scr_read(ap, SCR_ERROR, &serror); | ||
2200 | mv_scr_read(ap, SCR_CONTROL, &scontrol); | ||
2201 | DPRINTK("S-regs after PHY wake: SStat 0x%08x SErr 0x%08x " | ||
2202 | "SCtrl 0x%08x\n", sstatus, serror, scontrol); | ||
2203 | } | ||
2204 | #endif | ||
2170 | 2205 | ||
2171 | if (ata_port_offline(ap)) { | 2206 | if (ata_port_offline(ap)) { |
2172 | *class = ATA_DEV_NONE; | 2207 | *class = ATA_DEV_NONE; |
@@ -2209,7 +2244,7 @@ static int mv_prereset(struct ata_port *ap, unsigned long deadline) | |||
2209 | struct mv_port_priv *pp = ap->private_data; | 2244 | struct mv_port_priv *pp = ap->private_data; |
2210 | struct ata_eh_context *ehc = &ap->eh_context; | 2245 | struct ata_eh_context *ehc = &ap->eh_context; |
2211 | int rc; | 2246 | int rc; |
2212 | 2247 | ||
2213 | rc = mv_stop_dma(ap); | 2248 | rc = mv_stop_dma(ap); |
2214 | if (rc) | 2249 | if (rc) |
2215 | ehc->i.action |= ATA_EH_HARDRESET; | 2250 | ehc->i.action |= ATA_EH_HARDRESET; |
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c index db81e3efa5ec..0b58c4df6fd2 100644 --- a/drivers/ata/sata_nv.c +++ b/drivers/ata/sata_nv.c | |||
@@ -236,8 +236,8 @@ static void nv_ck804_host_stop(struct ata_host *host); | |||
236 | static irqreturn_t nv_generic_interrupt(int irq, void *dev_instance); | 236 | static irqreturn_t nv_generic_interrupt(int irq, void *dev_instance); |
237 | static irqreturn_t nv_nf2_interrupt(int irq, void *dev_instance); | 237 | static irqreturn_t nv_nf2_interrupt(int irq, void *dev_instance); |
238 | static irqreturn_t nv_ck804_interrupt(int irq, void *dev_instance); | 238 | static irqreturn_t nv_ck804_interrupt(int irq, void *dev_instance); |
239 | static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg); | 239 | static int nv_scr_read (struct ata_port *ap, unsigned int sc_reg, u32 *val); |
240 | static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); | 240 | static int nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); |
241 | 241 | ||
242 | static void nv_nf2_freeze(struct ata_port *ap); | 242 | static void nv_nf2_freeze(struct ata_port *ap); |
243 | static void nv_nf2_thaw(struct ata_port *ap); | 243 | static void nv_nf2_thaw(struct ata_port *ap); |
@@ -715,19 +715,20 @@ static int nv_adma_check_cpb(struct ata_port *ap, int cpb_num, int force_err) | |||
715 | int freeze = 0; | 715 | int freeze = 0; |
716 | 716 | ||
717 | ata_ehi_clear_desc(ehi); | 717 | ata_ehi_clear_desc(ehi); |
718 | ata_ehi_push_desc(ehi, "CPB resp_flags 0x%x", flags ); | 718 | __ata_ehi_push_desc(ehi, "CPB resp_flags 0x%x: ", flags ); |
719 | if (flags & NV_CPB_RESP_ATA_ERR) { | 719 | if (flags & NV_CPB_RESP_ATA_ERR) { |
720 | ata_ehi_push_desc(ehi, ": ATA error"); | 720 | ata_ehi_push_desc(ehi, "ATA error"); |
721 | ehi->err_mask |= AC_ERR_DEV; | 721 | ehi->err_mask |= AC_ERR_DEV; |
722 | } else if (flags & NV_CPB_RESP_CMD_ERR) { | 722 | } else if (flags & NV_CPB_RESP_CMD_ERR) { |
723 | ata_ehi_push_desc(ehi, ": CMD error"); | 723 | ata_ehi_push_desc(ehi, "CMD error"); |
724 | ehi->err_mask |= AC_ERR_DEV; | 724 | ehi->err_mask |= AC_ERR_DEV; |
725 | } else if (flags & NV_CPB_RESP_CPB_ERR) { | 725 | } else if (flags & NV_CPB_RESP_CPB_ERR) { |
726 | ata_ehi_push_desc(ehi, ": CPB error"); | 726 | ata_ehi_push_desc(ehi, "CPB error"); |
727 | ehi->err_mask |= AC_ERR_SYSTEM; | 727 | ehi->err_mask |= AC_ERR_SYSTEM; |
728 | freeze = 1; | 728 | freeze = 1; |
729 | } else { | 729 | } else { |
730 | /* notifier error, but no error in CPB flags? */ | 730 | /* notifier error, but no error in CPB flags? */ |
731 | ata_ehi_push_desc(ehi, "unknown"); | ||
731 | ehi->err_mask |= AC_ERR_OTHER; | 732 | ehi->err_mask |= AC_ERR_OTHER; |
732 | freeze = 1; | 733 | freeze = 1; |
733 | } | 734 | } |
@@ -854,20 +855,21 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance) | |||
854 | struct ata_eh_info *ehi = &ap->eh_info; | 855 | struct ata_eh_info *ehi = &ap->eh_info; |
855 | 856 | ||
856 | ata_ehi_clear_desc(ehi); | 857 | ata_ehi_clear_desc(ehi); |
857 | ata_ehi_push_desc(ehi, "ADMA status 0x%08x", status ); | 858 | __ata_ehi_push_desc(ehi, "ADMA status 0x%08x: ", status ); |
858 | if (status & NV_ADMA_STAT_TIMEOUT) { | 859 | if (status & NV_ADMA_STAT_TIMEOUT) { |
859 | ehi->err_mask |= AC_ERR_SYSTEM; | 860 | ehi->err_mask |= AC_ERR_SYSTEM; |
860 | ata_ehi_push_desc(ehi, ": timeout"); | 861 | ata_ehi_push_desc(ehi, "timeout"); |
861 | } else if (status & NV_ADMA_STAT_HOTPLUG) { | 862 | } else if (status & NV_ADMA_STAT_HOTPLUG) { |
862 | ata_ehi_hotplugged(ehi); | 863 | ata_ehi_hotplugged(ehi); |
863 | ata_ehi_push_desc(ehi, ": hotplug"); | 864 | ata_ehi_push_desc(ehi, "hotplug"); |
864 | } else if (status & NV_ADMA_STAT_HOTUNPLUG) { | 865 | } else if (status & NV_ADMA_STAT_HOTUNPLUG) { |
865 | ata_ehi_hotplugged(ehi); | 866 | ata_ehi_hotplugged(ehi); |
866 | ata_ehi_push_desc(ehi, ": hot unplug"); | 867 | ata_ehi_push_desc(ehi, "hot unplug"); |
867 | } else if (status & NV_ADMA_STAT_SERROR) { | 868 | } else if (status & NV_ADMA_STAT_SERROR) { |
868 | /* let libata analyze SError and figure out the cause */ | 869 | /* let libata analyze SError and figure out the cause */ |
869 | ata_ehi_push_desc(ehi, ": SError"); | 870 | ata_ehi_push_desc(ehi, "SError"); |
870 | } | 871 | } else |
872 | ata_ehi_push_desc(ehi, "unknown"); | ||
871 | ata_port_freeze(ap); | 873 | ata_port_freeze(ap); |
872 | continue; | 874 | continue; |
873 | } | 875 | } |
@@ -1391,20 +1393,22 @@ static irqreturn_t nv_ck804_interrupt(int irq, void *dev_instance) | |||
1391 | return ret; | 1393 | return ret; |
1392 | } | 1394 | } |
1393 | 1395 | ||
1394 | static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg) | 1396 | static int nv_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) |
1395 | { | 1397 | { |
1396 | if (sc_reg > SCR_CONTROL) | 1398 | if (sc_reg > SCR_CONTROL) |
1397 | return 0xffffffffU; | 1399 | return -EINVAL; |
1398 | 1400 | ||
1399 | return ioread32(ap->ioaddr.scr_addr + (sc_reg * 4)); | 1401 | *val = ioread32(ap->ioaddr.scr_addr + (sc_reg * 4)); |
1402 | return 0; | ||
1400 | } | 1403 | } |
1401 | 1404 | ||
1402 | static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) | 1405 | static int nv_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val) |
1403 | { | 1406 | { |
1404 | if (sc_reg > SCR_CONTROL) | 1407 | if (sc_reg > SCR_CONTROL) |
1405 | return; | 1408 | return -EINVAL; |
1406 | 1409 | ||
1407 | iowrite32(val, ap->ioaddr.scr_addr + (sc_reg * 4)); | 1410 | iowrite32(val, ap->ioaddr.scr_addr + (sc_reg * 4)); |
1411 | return 0; | ||
1408 | } | 1412 | } |
1409 | 1413 | ||
1410 | static void nv_nf2_freeze(struct ata_port *ap) | 1414 | static void nv_nf2_freeze(struct ata_port *ap) |
diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c index d2fcb9a6bec2..d39ebc23c4a9 100644 --- a/drivers/ata/sata_promise.c +++ b/drivers/ata/sata_promise.c | |||
@@ -128,8 +128,8 @@ struct pdc_port_priv { | |||
128 | dma_addr_t pkt_dma; | 128 | dma_addr_t pkt_dma; |
129 | }; | 129 | }; |
130 | 130 | ||
131 | static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg); | 131 | static int pdc_sata_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val); |
132 | static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); | 132 | static int pdc_sata_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val); |
133 | static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); | 133 | static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); |
134 | static int pdc_common_port_start(struct ata_port *ap); | 134 | static int pdc_common_port_start(struct ata_port *ap); |
135 | static int pdc_sata_port_start(struct ata_port *ap); | 135 | static int pdc_sata_port_start(struct ata_port *ap); |
@@ -427,19 +427,20 @@ static int pdc_sata_cable_detect(struct ata_port *ap) | |||
427 | return ATA_CBL_SATA; | 427 | return ATA_CBL_SATA; |
428 | } | 428 | } |
429 | 429 | ||
430 | static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg) | 430 | static int pdc_sata_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) |
431 | { | 431 | { |
432 | if (sc_reg > SCR_CONTROL) | 432 | if (sc_reg > SCR_CONTROL) |
433 | return 0xffffffffU; | 433 | return -EINVAL; |
434 | return readl(ap->ioaddr.scr_addr + (sc_reg * 4)); | 434 | *val = readl(ap->ioaddr.scr_addr + (sc_reg * 4)); |
435 | return 0; | ||
435 | } | 436 | } |
436 | 437 | ||
437 | static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, | 438 | static int pdc_sata_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val) |
438 | u32 val) | ||
439 | { | 439 | { |
440 | if (sc_reg > SCR_CONTROL) | 440 | if (sc_reg > SCR_CONTROL) |
441 | return; | 441 | return -EINVAL; |
442 | writel(val, ap->ioaddr.scr_addr + (sc_reg * 4)); | 442 | writel(val, ap->ioaddr.scr_addr + (sc_reg * 4)); |
443 | return 0; | ||
443 | } | 444 | } |
444 | 445 | ||
445 | static void pdc_atapi_pkt(struct ata_queued_cmd *qc) | 446 | static void pdc_atapi_pkt(struct ata_queued_cmd *qc) |
@@ -642,8 +643,12 @@ static void pdc_error_intr(struct ata_port *ap, struct ata_queued_cmd *qc, | |||
642 | | PDC_PCI_SYS_ERR | PDC1_PCI_PARITY_ERR)) | 643 | | PDC_PCI_SYS_ERR | PDC1_PCI_PARITY_ERR)) |
643 | ac_err_mask |= AC_ERR_HOST_BUS; | 644 | ac_err_mask |= AC_ERR_HOST_BUS; |
644 | 645 | ||
645 | if (sata_scr_valid(ap)) | 646 | if (sata_scr_valid(ap)) { |
646 | ehi->serror |= pdc_sata_scr_read(ap, SCR_ERROR); | 647 | u32 serror; |
648 | |||
649 | pdc_sata_scr_read(ap, SCR_ERROR, &serror); | ||
650 | ehi->serror |= serror; | ||
651 | } | ||
647 | 652 | ||
648 | qc->err_mask |= ac_err_mask; | 653 | qc->err_mask |= ac_err_mask; |
649 | 654 | ||
diff --git a/drivers/ata/sata_qstor.c b/drivers/ata/sata_qstor.c index 9ab554da89bf..c8f9242e7f44 100644 --- a/drivers/ata/sata_qstor.c +++ b/drivers/ata/sata_qstor.c | |||
@@ -111,8 +111,8 @@ struct qs_port_priv { | |||
111 | qs_state_t state; | 111 | qs_state_t state; |
112 | }; | 112 | }; |
113 | 113 | ||
114 | static u32 qs_scr_read (struct ata_port *ap, unsigned int sc_reg); | 114 | static int qs_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val); |
115 | static void qs_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); | 115 | static int qs_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val); |
116 | static int qs_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); | 116 | static int qs_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); |
117 | static int qs_port_start(struct ata_port *ap); | 117 | static int qs_port_start(struct ata_port *ap); |
118 | static void qs_host_stop(struct ata_host *host); | 118 | static void qs_host_stop(struct ata_host *host); |
@@ -255,18 +255,20 @@ static void qs_eng_timeout(struct ata_port *ap) | |||
255 | ata_eng_timeout(ap); | 255 | ata_eng_timeout(ap); |
256 | } | 256 | } |
257 | 257 | ||
258 | static u32 qs_scr_read (struct ata_port *ap, unsigned int sc_reg) | 258 | static int qs_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) |
259 | { | 259 | { |
260 | if (sc_reg > SCR_CONTROL) | 260 | if (sc_reg > SCR_CONTROL) |
261 | return ~0U; | 261 | return -EINVAL; |
262 | return readl(ap->ioaddr.scr_addr + (sc_reg * 8)); | 262 | *val = readl(ap->ioaddr.scr_addr + (sc_reg * 8)); |
263 | return 0; | ||
263 | } | 264 | } |
264 | 265 | ||
265 | static void qs_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) | 266 | static int qs_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val) |
266 | { | 267 | { |
267 | if (sc_reg > SCR_CONTROL) | 268 | if (sc_reg > SCR_CONTROL) |
268 | return; | 269 | return -EINVAL; |
269 | writel(val, ap->ioaddr.scr_addr + (sc_reg * 8)); | 270 | writel(val, ap->ioaddr.scr_addr + (sc_reg * 8)); |
271 | return 0; | ||
270 | } | 272 | } |
271 | 273 | ||
272 | static unsigned int qs_fill_sg(struct ata_queued_cmd *qc) | 274 | static unsigned int qs_fill_sg(struct ata_queued_cmd *qc) |
@@ -337,7 +339,7 @@ static void qs_qc_prep(struct ata_queued_cmd *qc) | |||
337 | buf[28] = dflags; | 339 | buf[28] = dflags; |
338 | 340 | ||
339 | /* frame information structure (FIS) */ | 341 | /* frame information structure (FIS) */ |
340 | ata_tf_to_fis(&qc->tf, &buf[32], 0); | 342 | ata_tf_to_fis(&qc->tf, 0, 1, &buf[32]); |
341 | } | 343 | } |
342 | 344 | ||
343 | static inline void qs_packet_start(struct ata_queued_cmd *qc) | 345 | static inline void qs_packet_start(struct ata_queued_cmd *qc) |
diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c index 2a86dc4598d0..db6763758952 100644 --- a/drivers/ata/sata_sil.c +++ b/drivers/ata/sata_sil.c | |||
@@ -115,8 +115,8 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); | |||
115 | static int sil_pci_device_resume(struct pci_dev *pdev); | 115 | static int sil_pci_device_resume(struct pci_dev *pdev); |
116 | #endif | 116 | #endif |
117 | static void sil_dev_config(struct ata_device *dev); | 117 | static void sil_dev_config(struct ata_device *dev); |
118 | static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg); | 118 | static int sil_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val); |
119 | static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); | 119 | static int sil_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val); |
120 | static int sil_set_mode (struct ata_port *ap, struct ata_device **r_failed); | 120 | static int sil_set_mode (struct ata_port *ap, struct ata_device **r_failed); |
121 | static void sil_freeze(struct ata_port *ap); | 121 | static void sil_freeze(struct ata_port *ap); |
122 | static void sil_thaw(struct ata_port *ap); | 122 | static void sil_thaw(struct ata_port *ap); |
@@ -350,19 +350,26 @@ static inline void __iomem *sil_scr_addr(struct ata_port *ap, unsigned int sc_re | |||
350 | return NULL; | 350 | return NULL; |
351 | } | 351 | } |
352 | 352 | ||
353 | static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg) | 353 | static int sil_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) |
354 | { | 354 | { |
355 | void __iomem *mmio = sil_scr_addr(ap, sc_reg); | 355 | void __iomem *mmio = sil_scr_addr(ap, sc_reg); |
356 | if (mmio) | 356 | |
357 | return readl(mmio); | 357 | if (mmio) { |
358 | return 0xffffffffU; | 358 | *val = readl(mmio); |
359 | return 0; | ||
360 | } | ||
361 | return -EINVAL; | ||
359 | } | 362 | } |
360 | 363 | ||
361 | static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) | 364 | static int sil_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val) |
362 | { | 365 | { |
363 | void __iomem *mmio = sil_scr_addr(ap, sc_reg); | 366 | void __iomem *mmio = sil_scr_addr(ap, sc_reg); |
364 | if (mmio) | 367 | |
368 | if (mmio) { | ||
365 | writel(val, mmio); | 369 | writel(val, mmio); |
370 | return 0; | ||
371 | } | ||
372 | return -EINVAL; | ||
366 | } | 373 | } |
367 | 374 | ||
368 | static void sil_host_intr(struct ata_port *ap, u32 bmdma2) | 375 | static void sil_host_intr(struct ata_port *ap, u32 bmdma2) |
@@ -378,7 +385,7 @@ static void sil_host_intr(struct ata_port *ap, u32 bmdma2) | |||
378 | * controllers continue to assert IRQ as long as | 385 | * controllers continue to assert IRQ as long as |
379 | * SError bits are pending. Clear SError immediately. | 386 | * SError bits are pending. Clear SError immediately. |
380 | */ | 387 | */ |
381 | serror = sil_scr_read(ap, SCR_ERROR); | 388 | sil_scr_read(ap, SCR_ERROR, &serror); |
382 | sil_scr_write(ap, SCR_ERROR, serror); | 389 | sil_scr_write(ap, SCR_ERROR, serror); |
383 | 390 | ||
384 | /* Trigger hotplug and accumulate SError only if the | 391 | /* Trigger hotplug and accumulate SError only if the |
diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c index ac43a30ebe29..46fbbe7f121c 100644 --- a/drivers/ata/sata_sil24.c +++ b/drivers/ata/sata_sil24.c | |||
@@ -326,8 +326,8 @@ struct sil24_port_priv { | |||
326 | 326 | ||
327 | static void sil24_dev_config(struct ata_device *dev); | 327 | static void sil24_dev_config(struct ata_device *dev); |
328 | static u8 sil24_check_status(struct ata_port *ap); | 328 | static u8 sil24_check_status(struct ata_port *ap); |
329 | static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg); | 329 | static int sil24_scr_read(struct ata_port *ap, unsigned sc_reg, u32 *val); |
330 | static void sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val); | 330 | static int sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val); |
331 | static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf); | 331 | static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf); |
332 | static void sil24_qc_prep(struct ata_queued_cmd *qc); | 332 | static void sil24_qc_prep(struct ata_queued_cmd *qc); |
333 | static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc); | 333 | static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc); |
@@ -464,15 +464,15 @@ static void sil24_dev_config(struct ata_device *dev) | |||
464 | writel(PORT_CS_CDB16, port + PORT_CTRL_CLR); | 464 | writel(PORT_CS_CDB16, port + PORT_CTRL_CLR); |
465 | } | 465 | } |
466 | 466 | ||
467 | static inline void sil24_update_tf(struct ata_port *ap) | 467 | static void sil24_read_tf(struct ata_port *ap, int tag, struct ata_taskfile *tf) |
468 | { | 468 | { |
469 | struct sil24_port_priv *pp = ap->private_data; | ||
470 | void __iomem *port = ap->ioaddr.cmd_addr; | 469 | void __iomem *port = ap->ioaddr.cmd_addr; |
471 | struct sil24_prb __iomem *prb = port; | 470 | struct sil24_prb __iomem *prb; |
472 | u8 fis[6 * 4]; | 471 | u8 fis[6 * 4]; |
473 | 472 | ||
474 | memcpy_fromio(fis, prb->fis, 6 * 4); | 473 | prb = port + PORT_LRAM + sil24_tag(tag) * PORT_LRAM_SLOT_SZ; |
475 | ata_tf_from_fis(fis, &pp->tf); | 474 | memcpy_fromio(fis, prb->fis, sizeof(fis)); |
475 | ata_tf_from_fis(fis, tf); | ||
476 | } | 476 | } |
477 | 477 | ||
478 | static u8 sil24_check_status(struct ata_port *ap) | 478 | static u8 sil24_check_status(struct ata_port *ap) |
@@ -488,25 +488,30 @@ static int sil24_scr_map[] = { | |||
488 | [SCR_ACTIVE] = 3, | 488 | [SCR_ACTIVE] = 3, |
489 | }; | 489 | }; |
490 | 490 | ||
491 | static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg) | 491 | static int sil24_scr_read(struct ata_port *ap, unsigned sc_reg, u32 *val) |
492 | { | 492 | { |
493 | void __iomem *scr_addr = ap->ioaddr.scr_addr; | 493 | void __iomem *scr_addr = ap->ioaddr.scr_addr; |
494 | |||
494 | if (sc_reg < ARRAY_SIZE(sil24_scr_map)) { | 495 | if (sc_reg < ARRAY_SIZE(sil24_scr_map)) { |
495 | void __iomem *addr; | 496 | void __iomem *addr; |
496 | addr = scr_addr + sil24_scr_map[sc_reg] * 4; | 497 | addr = scr_addr + sil24_scr_map[sc_reg] * 4; |
497 | return readl(scr_addr + sil24_scr_map[sc_reg] * 4); | 498 | *val = readl(scr_addr + sil24_scr_map[sc_reg] * 4); |
499 | return 0; | ||
498 | } | 500 | } |
499 | return 0xffffffffU; | 501 | return -EINVAL; |
500 | } | 502 | } |
501 | 503 | ||
502 | static void sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val) | 504 | static int sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val) |
503 | { | 505 | { |
504 | void __iomem *scr_addr = ap->ioaddr.scr_addr; | 506 | void __iomem *scr_addr = ap->ioaddr.scr_addr; |
507 | |||
505 | if (sc_reg < ARRAY_SIZE(sil24_scr_map)) { | 508 | if (sc_reg < ARRAY_SIZE(sil24_scr_map)) { |
506 | void __iomem *addr; | 509 | void __iomem *addr; |
507 | addr = scr_addr + sil24_scr_map[sc_reg] * 4; | 510 | addr = scr_addr + sil24_scr_map[sc_reg] * 4; |
508 | writel(val, scr_addr + sil24_scr_map[sc_reg] * 4); | 511 | writel(val, scr_addr + sil24_scr_map[sc_reg] * 4); |
512 | return 0; | ||
509 | } | 513 | } |
514 | return -EINVAL; | ||
510 | } | 515 | } |
511 | 516 | ||
512 | static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf) | 517 | static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf) |
@@ -531,15 +536,60 @@ static int sil24_init_port(struct ata_port *ap) | |||
531 | return 0; | 536 | return 0; |
532 | } | 537 | } |
533 | 538 | ||
534 | static int sil24_softreset(struct ata_port *ap, unsigned int *class, | 539 | static int sil24_exec_polled_cmd(struct ata_port *ap, int pmp, |
535 | unsigned long deadline) | 540 | const struct ata_taskfile *tf, |
541 | int is_cmd, u32 ctrl, | ||
542 | unsigned long timeout_msec) | ||
536 | { | 543 | { |
537 | void __iomem *port = ap->ioaddr.cmd_addr; | 544 | void __iomem *port = ap->ioaddr.cmd_addr; |
538 | struct sil24_port_priv *pp = ap->private_data; | 545 | struct sil24_port_priv *pp = ap->private_data; |
539 | struct sil24_prb *prb = &pp->cmd_block[0].ata.prb; | 546 | struct sil24_prb *prb = &pp->cmd_block[0].ata.prb; |
540 | dma_addr_t paddr = pp->cmd_block_dma; | 547 | dma_addr_t paddr = pp->cmd_block_dma; |
541 | u32 mask, irq_stat; | 548 | u32 irq_enabled, irq_mask, irq_stat; |
549 | int rc; | ||
550 | |||
551 | prb->ctrl = cpu_to_le16(ctrl); | ||
552 | ata_tf_to_fis(tf, pmp, is_cmd, prb->fis); | ||
553 | |||
554 | /* temporarily plug completion and error interrupts */ | ||
555 | irq_enabled = readl(port + PORT_IRQ_ENABLE_SET); | ||
556 | writel(PORT_IRQ_COMPLETE | PORT_IRQ_ERROR, port + PORT_IRQ_ENABLE_CLR); | ||
557 | |||
558 | writel((u32)paddr, port + PORT_CMD_ACTIVATE); | ||
559 | writel((u64)paddr >> 32, port + PORT_CMD_ACTIVATE + 4); | ||
560 | |||
561 | irq_mask = (PORT_IRQ_COMPLETE | PORT_IRQ_ERROR) << PORT_IRQ_RAW_SHIFT; | ||
562 | irq_stat = ata_wait_register(port + PORT_IRQ_STAT, irq_mask, 0x0, | ||
563 | 10, timeout_msec); | ||
564 | |||
565 | writel(irq_mask, port + PORT_IRQ_STAT); /* clear IRQs */ | ||
566 | irq_stat >>= PORT_IRQ_RAW_SHIFT; | ||
567 | |||
568 | if (irq_stat & PORT_IRQ_COMPLETE) | ||
569 | rc = 0; | ||
570 | else { | ||
571 | /* force port into known state */ | ||
572 | sil24_init_port(ap); | ||
573 | |||
574 | if (irq_stat & PORT_IRQ_ERROR) | ||
575 | rc = -EIO; | ||
576 | else | ||
577 | rc = -EBUSY; | ||
578 | } | ||
579 | |||
580 | /* restore IRQ enabled */ | ||
581 | writel(irq_enabled, port + PORT_IRQ_ENABLE_SET); | ||
582 | |||
583 | return rc; | ||
584 | } | ||
585 | |||
586 | static int sil24_do_softreset(struct ata_port *ap, unsigned int *class, | ||
587 | int pmp, unsigned long deadline) | ||
588 | { | ||
589 | unsigned long timeout_msec = 0; | ||
590 | struct ata_taskfile tf; | ||
542 | const char *reason; | 591 | const char *reason; |
592 | int rc; | ||
543 | 593 | ||
544 | DPRINTK("ENTER\n"); | 594 | DPRINTK("ENTER\n"); |
545 | 595 | ||
@@ -556,29 +606,22 @@ static int sil24_softreset(struct ata_port *ap, unsigned int *class, | |||
556 | } | 606 | } |
557 | 607 | ||
558 | /* do SRST */ | 608 | /* do SRST */ |
559 | prb->ctrl = cpu_to_le16(PRB_CTRL_SRST); | 609 | if (time_after(deadline, jiffies)) |
560 | prb->fis[1] = 0; /* no PMP yet */ | 610 | timeout_msec = jiffies_to_msecs(deadline - jiffies); |
561 | 611 | ||
562 | writel((u32)paddr, port + PORT_CMD_ACTIVATE); | 612 | ata_tf_init(ap->device, &tf); /* doesn't really matter */ |
563 | writel((u64)paddr >> 32, port + PORT_CMD_ACTIVATE + 4); | 613 | rc = sil24_exec_polled_cmd(ap, pmp, &tf, 0, PRB_CTRL_SRST, |
564 | 614 | timeout_msec); | |
565 | mask = (PORT_IRQ_COMPLETE | PORT_IRQ_ERROR) << PORT_IRQ_RAW_SHIFT; | 615 | if (rc == -EBUSY) { |
566 | irq_stat = ata_wait_register(port + PORT_IRQ_STAT, mask, 0x0, | 616 | reason = "timeout"; |
567 | 100, jiffies_to_msecs(deadline - jiffies)); | 617 | goto err; |
568 | 618 | } else if (rc) { | |
569 | writel(irq_stat, port + PORT_IRQ_STAT); /* clear IRQs */ | 619 | reason = "SRST command error"; |
570 | irq_stat >>= PORT_IRQ_RAW_SHIFT; | ||
571 | |||
572 | if (!(irq_stat & PORT_IRQ_COMPLETE)) { | ||
573 | if (irq_stat & PORT_IRQ_ERROR) | ||
574 | reason = "SRST command error"; | ||
575 | else | ||
576 | reason = "timeout"; | ||
577 | goto err; | 620 | goto err; |
578 | } | 621 | } |
579 | 622 | ||
580 | sil24_update_tf(ap); | 623 | sil24_read_tf(ap, 0, &tf); |
581 | *class = ata_dev_classify(&pp->tf); | 624 | *class = ata_dev_classify(&tf); |
582 | 625 | ||
583 | if (*class == ATA_DEV_UNKNOWN) | 626 | if (*class == ATA_DEV_UNKNOWN) |
584 | *class = ATA_DEV_NONE; | 627 | *class = ATA_DEV_NONE; |
@@ -592,6 +635,12 @@ static int sil24_softreset(struct ata_port *ap, unsigned int *class, | |||
592 | return -EIO; | 635 | return -EIO; |
593 | } | 636 | } |
594 | 637 | ||
638 | static int sil24_softreset(struct ata_port *ap, unsigned int *class, | ||
639 | unsigned long deadline) | ||
640 | { | ||
641 | return sil24_do_softreset(ap, class, 0, deadline); | ||
642 | } | ||
643 | |||
595 | static int sil24_hardreset(struct ata_port *ap, unsigned int *class, | 644 | static int sil24_hardreset(struct ata_port *ap, unsigned int *class, |
596 | unsigned long deadline) | 645 | unsigned long deadline) |
597 | { | 646 | { |
@@ -699,7 +748,7 @@ static void sil24_qc_prep(struct ata_queued_cmd *qc) | |||
699 | } | 748 | } |
700 | 749 | ||
701 | prb->ctrl = cpu_to_le16(ctrl); | 750 | prb->ctrl = cpu_to_le16(ctrl); |
702 | ata_tf_to_fis(&qc->tf, prb->fis, 0); | 751 | ata_tf_to_fis(&qc->tf, 0, 1, prb->fis); |
703 | 752 | ||
704 | if (qc->flags & ATA_QCFLAG_DMAMAP) | 753 | if (qc->flags & ATA_QCFLAG_DMAMAP) |
705 | sil24_fill_sg(qc, sge); | 754 | sil24_fill_sg(qc, sge); |
@@ -754,6 +803,7 @@ static void sil24_thaw(struct ata_port *ap) | |||
754 | static void sil24_error_intr(struct ata_port *ap) | 803 | static void sil24_error_intr(struct ata_port *ap) |
755 | { | 804 | { |
756 | void __iomem *port = ap->ioaddr.cmd_addr; | 805 | void __iomem *port = ap->ioaddr.cmd_addr; |
806 | struct sil24_port_priv *pp = ap->private_data; | ||
757 | struct ata_eh_info *ehi = &ap->eh_info; | 807 | struct ata_eh_info *ehi = &ap->eh_info; |
758 | int freeze = 0; | 808 | int freeze = 0; |
759 | u32 irq_stat; | 809 | u32 irq_stat; |
@@ -769,16 +819,16 @@ static void sil24_error_intr(struct ata_port *ap) | |||
769 | 819 | ||
770 | if (irq_stat & (PORT_IRQ_PHYRDY_CHG | PORT_IRQ_DEV_XCHG)) { | 820 | if (irq_stat & (PORT_IRQ_PHYRDY_CHG | PORT_IRQ_DEV_XCHG)) { |
771 | ata_ehi_hotplugged(ehi); | 821 | ata_ehi_hotplugged(ehi); |
772 | ata_ehi_push_desc(ehi, ", %s", | 822 | ata_ehi_push_desc(ehi, "%s", |
773 | irq_stat & PORT_IRQ_PHYRDY_CHG ? | 823 | irq_stat & PORT_IRQ_PHYRDY_CHG ? |
774 | "PHY RDY changed" : "device exchanged"); | 824 | "PHY RDY changed" : "device exchanged"); |
775 | freeze = 1; | 825 | freeze = 1; |
776 | } | 826 | } |
777 | 827 | ||
778 | if (irq_stat & PORT_IRQ_UNK_FIS) { | 828 | if (irq_stat & PORT_IRQ_UNK_FIS) { |
779 | ehi->err_mask |= AC_ERR_HSM; | 829 | ehi->err_mask |= AC_ERR_HSM; |
780 | ehi->action |= ATA_EH_SOFTRESET; | 830 | ehi->action |= ATA_EH_SOFTRESET; |
781 | ata_ehi_push_desc(ehi , ", unknown FIS"); | 831 | ata_ehi_push_desc(ehi, "unknown FIS"); |
782 | freeze = 1; | 832 | freeze = 1; |
783 | } | 833 | } |
784 | 834 | ||
@@ -797,18 +847,18 @@ static void sil24_error_intr(struct ata_port *ap) | |||
797 | if (ci && ci->desc) { | 847 | if (ci && ci->desc) { |
798 | err_mask |= ci->err_mask; | 848 | err_mask |= ci->err_mask; |
799 | action |= ci->action; | 849 | action |= ci->action; |
800 | ata_ehi_push_desc(ehi, ", %s", ci->desc); | 850 | ata_ehi_push_desc(ehi, "%s", ci->desc); |
801 | } else { | 851 | } else { |
802 | err_mask |= AC_ERR_OTHER; | 852 | err_mask |= AC_ERR_OTHER; |
803 | action |= ATA_EH_SOFTRESET; | 853 | action |= ATA_EH_SOFTRESET; |
804 | ata_ehi_push_desc(ehi, ", unknown command error %d", | 854 | ata_ehi_push_desc(ehi, "unknown command error %d", |
805 | cerr); | 855 | cerr); |
806 | } | 856 | } |
807 | 857 | ||
808 | /* record error info */ | 858 | /* record error info */ |
809 | qc = ata_qc_from_tag(ap, ap->active_tag); | 859 | qc = ata_qc_from_tag(ap, ap->active_tag); |
810 | if (qc) { | 860 | if (qc) { |
811 | sil24_update_tf(ap); | 861 | sil24_read_tf(ap, qc->tag, &pp->tf); |
812 | qc->err_mask |= err_mask; | 862 | qc->err_mask |= err_mask; |
813 | } else | 863 | } else |
814 | ehi->err_mask |= err_mask; | 864 | ehi->err_mask |= err_mask; |
@@ -825,8 +875,11 @@ static void sil24_error_intr(struct ata_port *ap) | |||
825 | 875 | ||
826 | static void sil24_finish_qc(struct ata_queued_cmd *qc) | 876 | static void sil24_finish_qc(struct ata_queued_cmd *qc) |
827 | { | 877 | { |
878 | struct ata_port *ap = qc->ap; | ||
879 | struct sil24_port_priv *pp = ap->private_data; | ||
880 | |||
828 | if (qc->flags & ATA_QCFLAG_RESULT_TF) | 881 | if (qc->flags & ATA_QCFLAG_RESULT_TF) |
829 | sil24_update_tf(qc->ap); | 882 | sil24_read_tf(ap, qc->tag, &pp->tf); |
830 | } | 883 | } |
831 | 884 | ||
832 | static inline void sil24_host_intr(struct ata_port *ap) | 885 | static inline void sil24_host_intr(struct ata_port *ap) |
diff --git a/drivers/ata/sata_sis.c b/drivers/ata/sata_sis.c index 33716b00c6b7..31a2f55aae66 100644 --- a/drivers/ata/sata_sis.c +++ b/drivers/ata/sata_sis.c | |||
@@ -64,8 +64,8 @@ enum { | |||
64 | }; | 64 | }; |
65 | 65 | ||
66 | static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); | 66 | static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); |
67 | static u32 sis_scr_read (struct ata_port *ap, unsigned int sc_reg); | 67 | static int sis_scr_read (struct ata_port *ap, unsigned int sc_reg, u32 *val); |
68 | static void sis_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); | 68 | static int sis_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); |
69 | 69 | ||
70 | static const struct pci_device_id sis_pci_tbl[] = { | 70 | static const struct pci_device_id sis_pci_tbl[] = { |
71 | { PCI_VDEVICE(SI, 0x0180), sis_180 }, /* SiS 964/180 */ | 71 | { PCI_VDEVICE(SI, 0x0180), sis_180 }, /* SiS 964/180 */ |
@@ -207,36 +207,37 @@ static void sis_scr_cfg_write (struct ata_port *ap, unsigned int sc_reg, u32 val | |||
207 | pci_write_config_dword(pdev, cfg_addr+0x10, val); | 207 | pci_write_config_dword(pdev, cfg_addr+0x10, val); |
208 | } | 208 | } |
209 | 209 | ||
210 | static u32 sis_scr_read (struct ata_port *ap, unsigned int sc_reg) | 210 | static int sis_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) |
211 | { | 211 | { |
212 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); | 212 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
213 | u32 val, val2 = 0; | ||
214 | u8 pmr; | 213 | u8 pmr; |
215 | 214 | ||
216 | if (sc_reg > SCR_CONTROL) | 215 | if (sc_reg > SCR_CONTROL) |
217 | return 0xffffffffU; | 216 | return -EINVAL; |
218 | 217 | ||
219 | if (ap->flags & SIS_FLAG_CFGSCR) | 218 | if (ap->flags & SIS_FLAG_CFGSCR) |
220 | return sis_scr_cfg_read(ap, sc_reg); | 219 | return sis_scr_cfg_read(ap, sc_reg); |
221 | 220 | ||
222 | pci_read_config_byte(pdev, SIS_PMR, &pmr); | 221 | pci_read_config_byte(pdev, SIS_PMR, &pmr); |
223 | 222 | ||
224 | val = ioread32(ap->ioaddr.scr_addr + (sc_reg * 4)); | 223 | *val = ioread32(ap->ioaddr.scr_addr + (sc_reg * 4)); |
225 | 224 | ||
226 | if ((pdev->device == 0x0182) || (pdev->device == 0x0183) || | 225 | if ((pdev->device == 0x0182) || (pdev->device == 0x0183) || |
227 | (pdev->device == 0x1182) || (pmr & SIS_PMR_COMBINED)) | 226 | (pdev->device == 0x1182) || (pmr & SIS_PMR_COMBINED)) |
228 | val2 = ioread32(ap->ioaddr.scr_addr + (sc_reg * 4) + 0x10); | 227 | *val |= ioread32(ap->ioaddr.scr_addr + (sc_reg * 4) + 0x10); |
228 | |||
229 | *val &= 0xfffffffb; | ||
229 | 230 | ||
230 | return (val | val2) & 0xfffffffb; | 231 | return 0; |
231 | } | 232 | } |
232 | 233 | ||
233 | static void sis_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) | 234 | static int sis_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val) |
234 | { | 235 | { |
235 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); | 236 | struct pci_dev *pdev = to_pci_dev(ap->host->dev); |
236 | u8 pmr; | 237 | u8 pmr; |
237 | 238 | ||
238 | if (sc_reg > SCR_CONTROL) | 239 | if (sc_reg > SCR_CONTROL) |
239 | return; | 240 | return -EINVAL; |
240 | 241 | ||
241 | pci_read_config_byte(pdev, SIS_PMR, &pmr); | 242 | pci_read_config_byte(pdev, SIS_PMR, &pmr); |
242 | 243 | ||
@@ -248,6 +249,7 @@ static void sis_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) | |||
248 | (pdev->device == 0x1182) || (pmr & SIS_PMR_COMBINED)) | 249 | (pdev->device == 0x1182) || (pmr & SIS_PMR_COMBINED)) |
249 | iowrite32(val, ap->ioaddr.scr_addr + (sc_reg * 4)+0x10); | 250 | iowrite32(val, ap->ioaddr.scr_addr + (sc_reg * 4)+0x10); |
250 | } | 251 | } |
252 | return 0; | ||
251 | } | 253 | } |
252 | 254 | ||
253 | static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) | 255 | static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) |
diff --git a/drivers/ata/sata_svw.c b/drivers/ata/sata_svw.c index 63fe99afd59f..92e877075037 100644 --- a/drivers/ata/sata_svw.c +++ b/drivers/ata/sata_svw.c | |||
@@ -103,20 +103,21 @@ static int k2_sata_check_atapi_dma(struct ata_queued_cmd *qc) | |||
103 | return 0; | 103 | return 0; |
104 | } | 104 | } |
105 | 105 | ||
106 | static u32 k2_sata_scr_read (struct ata_port *ap, unsigned int sc_reg) | 106 | static int k2_sata_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) |
107 | { | 107 | { |
108 | if (sc_reg > SCR_CONTROL) | 108 | if (sc_reg > SCR_CONTROL) |
109 | return 0xffffffffU; | 109 | return -EINVAL; |
110 | return readl(ap->ioaddr.scr_addr + (sc_reg * 4)); | 110 | *val = readl(ap->ioaddr.scr_addr + (sc_reg * 4)); |
111 | return 0; | ||
111 | } | 112 | } |
112 | 113 | ||
113 | 114 | ||
114 | static void k2_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, | 115 | static int k2_sata_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val) |
115 | u32 val) | ||
116 | { | 116 | { |
117 | if (sc_reg > SCR_CONTROL) | 117 | if (sc_reg > SCR_CONTROL) |
118 | return; | 118 | return -EINVAL; |
119 | writel(val, ap->ioaddr.scr_addr + (sc_reg * 4)); | 119 | writel(val, ap->ioaddr.scr_addr + (sc_reg * 4)); |
120 | return 0; | ||
120 | } | 121 | } |
121 | 122 | ||
122 | 123 | ||
diff --git a/drivers/ata/sata_uli.c b/drivers/ata/sata_uli.c index b52f83ab056a..78c28512f01c 100644 --- a/drivers/ata/sata_uli.c +++ b/drivers/ata/sata_uli.c | |||
@@ -57,8 +57,8 @@ struct uli_priv { | |||
57 | }; | 57 | }; |
58 | 58 | ||
59 | static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); | 59 | static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); |
60 | static u32 uli_scr_read (struct ata_port *ap, unsigned int sc_reg); | 60 | static int uli_scr_read (struct ata_port *ap, unsigned int sc_reg, u32 *val); |
61 | static void uli_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); | 61 | static int uli_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); |
62 | 62 | ||
63 | static const struct pci_device_id uli_pci_tbl[] = { | 63 | static const struct pci_device_id uli_pci_tbl[] = { |
64 | { PCI_VDEVICE(AL, 0x5289), uli_5289 }, | 64 | { PCI_VDEVICE(AL, 0x5289), uli_5289 }, |
@@ -164,20 +164,22 @@ static void uli_scr_cfg_write (struct ata_port *ap, unsigned int scr, u32 val) | |||
164 | pci_write_config_dword(pdev, cfg_addr, val); | 164 | pci_write_config_dword(pdev, cfg_addr, val); |
165 | } | 165 | } |
166 | 166 | ||
167 | static u32 uli_scr_read (struct ata_port *ap, unsigned int sc_reg) | 167 | static int uli_scr_read (struct ata_port *ap, unsigned int sc_reg, u32 *val) |
168 | { | 168 | { |
169 | if (sc_reg > SCR_CONTROL) | 169 | if (sc_reg > SCR_CONTROL) |
170 | return 0xffffffffU; | 170 | return -EINVAL; |
171 | 171 | ||
172 | return uli_scr_cfg_read(ap, sc_reg); | 172 | *val = uli_scr_cfg_read(ap, sc_reg); |
173 | return 0; | ||
173 | } | 174 | } |
174 | 175 | ||
175 | static void uli_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) | 176 | static int uli_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) |
176 | { | 177 | { |
177 | if (sc_reg > SCR_CONTROL) //SCR_CONTROL=2, SCR_ERROR=1, SCR_STATUS=0 | 178 | if (sc_reg > SCR_CONTROL) //SCR_CONTROL=2, SCR_ERROR=1, SCR_STATUS=0 |
178 | return; | 179 | return -EINVAL; |
179 | 180 | ||
180 | uli_scr_cfg_write(ap, sc_reg, val); | 181 | uli_scr_cfg_write(ap, sc_reg, val); |
182 | return 0; | ||
181 | } | 183 | } |
182 | 184 | ||
183 | static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) | 185 | static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) |
diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c index c4124475f754..86b7bfc17324 100644 --- a/drivers/ata/sata_via.c +++ b/drivers/ata/sata_via.c | |||
@@ -72,8 +72,8 @@ enum { | |||
72 | }; | 72 | }; |
73 | 73 | ||
74 | static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); | 74 | static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); |
75 | static u32 svia_scr_read (struct ata_port *ap, unsigned int sc_reg); | 75 | static int svia_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val); |
76 | static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); | 76 | static int svia_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val); |
77 | static void svia_noop_freeze(struct ata_port *ap); | 77 | static void svia_noop_freeze(struct ata_port *ap); |
78 | static void vt6420_error_handler(struct ata_port *ap); | 78 | static void vt6420_error_handler(struct ata_port *ap); |
79 | static int vt6421_pata_cable_detect(struct ata_port *ap); | 79 | static int vt6421_pata_cable_detect(struct ata_port *ap); |
@@ -249,18 +249,20 @@ MODULE_LICENSE("GPL"); | |||
249 | MODULE_DEVICE_TABLE(pci, svia_pci_tbl); | 249 | MODULE_DEVICE_TABLE(pci, svia_pci_tbl); |
250 | MODULE_VERSION(DRV_VERSION); | 250 | MODULE_VERSION(DRV_VERSION); |
251 | 251 | ||
252 | static u32 svia_scr_read (struct ata_port *ap, unsigned int sc_reg) | 252 | static int svia_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) |
253 | { | 253 | { |
254 | if (sc_reg > SCR_CONTROL) | 254 | if (sc_reg > SCR_CONTROL) |
255 | return 0xffffffffU; | 255 | return -EINVAL; |
256 | return ioread32(ap->ioaddr.scr_addr + (4 * sc_reg)); | 256 | *val = ioread32(ap->ioaddr.scr_addr + (4 * sc_reg)); |
257 | return 0; | ||
257 | } | 258 | } |
258 | 259 | ||
259 | static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) | 260 | static int svia_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val) |
260 | { | 261 | { |
261 | if (sc_reg > SCR_CONTROL) | 262 | if (sc_reg > SCR_CONTROL) |
262 | return; | 263 | return -EINVAL; |
263 | iowrite32(val, ap->ioaddr.scr_addr + (4 * sc_reg)); | 264 | iowrite32(val, ap->ioaddr.scr_addr + (4 * sc_reg)); |
265 | return 0; | ||
264 | } | 266 | } |
265 | 267 | ||
266 | static void svia_noop_freeze(struct ata_port *ap) | 268 | static void svia_noop_freeze(struct ata_port *ap) |
@@ -305,18 +307,19 @@ static int vt6420_prereset(struct ata_port *ap, unsigned long deadline) | |||
305 | 307 | ||
306 | /* Resume phy. This is the old SATA resume sequence */ | 308 | /* Resume phy. This is the old SATA resume sequence */ |
307 | svia_scr_write(ap, SCR_CONTROL, 0x300); | 309 | svia_scr_write(ap, SCR_CONTROL, 0x300); |
308 | svia_scr_read(ap, SCR_CONTROL); /* flush */ | 310 | svia_scr_read(ap, SCR_CONTROL, &scontrol); /* flush */ |
309 | 311 | ||
310 | /* wait for phy to become ready, if necessary */ | 312 | /* wait for phy to become ready, if necessary */ |
311 | do { | 313 | do { |
312 | msleep(200); | 314 | msleep(200); |
313 | if ((svia_scr_read(ap, SCR_STATUS) & 0xf) != 1) | 315 | svia_scr_read(ap, SCR_STATUS, &sstatus); |
316 | if ((sstatus & 0xf) != 1) | ||
314 | break; | 317 | break; |
315 | } while (time_before(jiffies, timeout)); | 318 | } while (time_before(jiffies, timeout)); |
316 | 319 | ||
317 | /* open code sata_print_link_status() */ | 320 | /* open code sata_print_link_status() */ |
318 | sstatus = svia_scr_read(ap, SCR_STATUS); | 321 | svia_scr_read(ap, SCR_STATUS, &sstatus); |
319 | scontrol = svia_scr_read(ap, SCR_CONTROL); | 322 | svia_scr_read(ap, SCR_CONTROL, &scontrol); |
320 | 323 | ||
321 | online = (sstatus & 0xf) == 0x3; | 324 | online = (sstatus & 0xf) == 0x3; |
322 | 325 | ||
@@ -325,7 +328,7 @@ static int vt6420_prereset(struct ata_port *ap, unsigned long deadline) | |||
325 | online ? "up" : "down", sstatus, scontrol); | 328 | online ? "up" : "down", sstatus, scontrol); |
326 | 329 | ||
327 | /* SStatus is read one more time */ | 330 | /* SStatus is read one more time */ |
328 | svia_scr_read(ap, SCR_STATUS); | 331 | svia_scr_read(ap, SCR_STATUS, &sstatus); |
329 | 332 | ||
330 | if (!online) { | 333 | if (!online) { |
331 | /* tell EH to bail */ | 334 | /* tell EH to bail */ |
diff --git a/drivers/ata/sata_vsc.c b/drivers/ata/sata_vsc.c index 1b5d81faa102..24344d0d0575 100644 --- a/drivers/ata/sata_vsc.c +++ b/drivers/ata/sata_vsc.c | |||
@@ -98,20 +98,21 @@ enum { | |||
98 | VSC_SATA_INT_PHY_CHANGE), | 98 | VSC_SATA_INT_PHY_CHANGE), |
99 | }; | 99 | }; |
100 | 100 | ||
101 | static u32 vsc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg) | 101 | static int vsc_sata_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val) |
102 | { | 102 | { |
103 | if (sc_reg > SCR_CONTROL) | 103 | if (sc_reg > SCR_CONTROL) |
104 | return 0xffffffffU; | 104 | return -EINVAL; |
105 | return readl(ap->ioaddr.scr_addr + (sc_reg * 4)); | 105 | *val = readl(ap->ioaddr.scr_addr + (sc_reg * 4)); |
106 | return 0; | ||
106 | } | 107 | } |
107 | 108 | ||
108 | 109 | ||
109 | static void vsc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, | 110 | static int vsc_sata_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val) |
110 | u32 val) | ||
111 | { | 111 | { |
112 | if (sc_reg > SCR_CONTROL) | 112 | if (sc_reg > SCR_CONTROL) |
113 | return; | 113 | return -EINVAL; |
114 | writel(val, ap->ioaddr.scr_addr + (sc_reg * 4)); | 114 | writel(val, ap->ioaddr.scr_addr + (sc_reg * 4)); |
115 | return 0; | ||
115 | } | 116 | } |
116 | 117 | ||
117 | 118 | ||
diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c index 478489c568a4..4f598270fa31 100644 --- a/drivers/block/aoe/aoeblk.c +++ b/drivers/block/aoe/aoeblk.c | |||
@@ -257,9 +257,9 @@ aoeblk_exit(void) | |||
257 | int __init | 257 | int __init |
258 | aoeblk_init(void) | 258 | aoeblk_init(void) |
259 | { | 259 | { |
260 | buf_pool_cache = kmem_cache_create("aoe_bufs", | 260 | buf_pool_cache = kmem_cache_create("aoe_bufs", |
261 | sizeof(struct buf), | 261 | sizeof(struct buf), |
262 | 0, 0, NULL, NULL); | 262 | 0, 0, NULL); |
263 | if (buf_pool_cache == NULL) | 263 | if (buf_pool_cache == NULL) |
264 | return -ENOMEM; | 264 | return -ENOMEM; |
265 | 265 | ||
diff --git a/drivers/block/sunvdc.c b/drivers/block/sunvdc.c index 2288b55d916f..d50b82381155 100644 --- a/drivers/block/sunvdc.c +++ b/drivers/block/sunvdc.c | |||
@@ -64,7 +64,6 @@ struct vdc_port { | |||
64 | u64 operations; | 64 | u64 operations; |
65 | u32 vdisk_size; | 65 | u32 vdisk_size; |
66 | u8 vdisk_type; | 66 | u8 vdisk_type; |
67 | u8 dev_no; | ||
68 | 67 | ||
69 | char disk_name[32]; | 68 | char disk_name[32]; |
70 | 69 | ||
@@ -703,7 +702,7 @@ static int probe_disk(struct vdc_port *port) | |||
703 | blk_queue_max_phys_segments(q, port->ring_cookies); | 702 | blk_queue_max_phys_segments(q, port->ring_cookies); |
704 | blk_queue_max_sectors(q, port->max_xfer_size); | 703 | blk_queue_max_sectors(q, port->max_xfer_size); |
705 | g->major = vdc_major; | 704 | g->major = vdc_major; |
706 | g->first_minor = port->dev_no << PARTITION_SHIFT; | 705 | g->first_minor = port->vio.vdev->dev_no << PARTITION_SHIFT; |
707 | strcpy(g->disk_name, port->disk_name); | 706 | strcpy(g->disk_name, port->disk_name); |
708 | 707 | ||
709 | g->fops = &vdc_fops; | 708 | g->fops = &vdc_fops; |
@@ -747,21 +746,16 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev, | |||
747 | { | 746 | { |
748 | struct mdesc_handle *hp; | 747 | struct mdesc_handle *hp; |
749 | struct vdc_port *port; | 748 | struct vdc_port *port; |
750 | const u64 *port_id; | ||
751 | int err; | 749 | int err; |
752 | 750 | ||
753 | print_version(); | 751 | print_version(); |
754 | 752 | ||
755 | hp = mdesc_grab(); | 753 | hp = mdesc_grab(); |
756 | 754 | ||
757 | port_id = mdesc_get_property(hp, vdev->mp, "id", NULL); | ||
758 | err = -ENODEV; | 755 | err = -ENODEV; |
759 | if (!port_id) { | 756 | if ((vdev->dev_no << PARTITION_SHIFT) & ~(u64)MINORMASK) { |
760 | printk(KERN_ERR PFX "Port lacks id property.\n"); | 757 | printk(KERN_ERR PFX "Port id [%lu] too large.\n", |
761 | goto err_out_release_mdesc; | 758 | vdev->dev_no); |
762 | } | ||
763 | if ((*port_id << PARTITION_SHIFT) & ~(u64)MINORMASK) { | ||
764 | printk(KERN_ERR PFX "Port id [%lu] too large.\n", *port_id); | ||
765 | goto err_out_release_mdesc; | 759 | goto err_out_release_mdesc; |
766 | } | 760 | } |
767 | 761 | ||
@@ -772,16 +766,14 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev, | |||
772 | goto err_out_release_mdesc; | 766 | goto err_out_release_mdesc; |
773 | } | 767 | } |
774 | 768 | ||
775 | port->dev_no = *port_id; | 769 | if (vdev->dev_no >= 26) |
776 | |||
777 | if (port->dev_no >= 26) | ||
778 | snprintf(port->disk_name, sizeof(port->disk_name), | 770 | snprintf(port->disk_name, sizeof(port->disk_name), |
779 | VDCBLK_NAME "%c%c", | 771 | VDCBLK_NAME "%c%c", |
780 | 'a' + (port->dev_no / 26) - 1, | 772 | 'a' + ((int)vdev->dev_no / 26) - 1, |
781 | 'a' + (port->dev_no % 26)); | 773 | 'a' + ((int)vdev->dev_no % 26)); |
782 | else | 774 | else |
783 | snprintf(port->disk_name, sizeof(port->disk_name), | 775 | snprintf(port->disk_name, sizeof(port->disk_name), |
784 | VDCBLK_NAME "%c", 'a' + (port->dev_no % 26)); | 776 | VDCBLK_NAME "%c", 'a' + ((int)vdev->dev_no % 26)); |
785 | 777 | ||
786 | err = vio_driver_init(&port->vio, vdev, VDEV_DISK, | 778 | err = vio_driver_init(&port->vio, vdev, VDEV_DISK, |
787 | vdc_versions, ARRAY_SIZE(vdc_versions), | 779 | vdc_versions, ARRAY_SIZE(vdc_versions), |
@@ -849,7 +841,7 @@ static struct vio_device_id vdc_port_match[] = { | |||
849 | }, | 841 | }, |
850 | {}, | 842 | {}, |
851 | }; | 843 | }; |
852 | MODULE_DEVICE_TABLE(vio, vdc_match); | 844 | MODULE_DEVICE_TABLE(vio, vdc_port_match); |
853 | 845 | ||
854 | static struct vio_driver vdc_port_driver = { | 846 | static struct vio_driver vdc_port_driver = { |
855 | .id_table = vdc_port_match, | 847 | .id_table = vdc_port_match, |
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index 9e8f21410d2d..4373d7cdc5d2 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig | |||
@@ -185,7 +185,7 @@ config ESPSERIAL | |||
185 | 185 | ||
186 | config MOXA_INTELLIO | 186 | config MOXA_INTELLIO |
187 | tristate "Moxa Intellio support" | 187 | tristate "Moxa Intellio support" |
188 | depends on SERIAL_NONSTANDARD | 188 | depends on SERIAL_NONSTANDARD && (ISA || EISA || PCI) |
189 | help | 189 | help |
190 | Say Y here if you have a Moxa Intellio multiport serial card. | 190 | Say Y here if you have a Moxa Intellio multiport serial card. |
191 | 191 | ||
@@ -241,7 +241,7 @@ config SYNCLINK | |||
241 | 241 | ||
242 | config SYNCLINKMP | 242 | config SYNCLINKMP |
243 | tristate "SyncLink Multiport support" | 243 | tristate "SyncLink Multiport support" |
244 | depends on SERIAL_NONSTANDARD | 244 | depends on SERIAL_NONSTANDARD && PCI |
245 | help | 245 | help |
246 | Enable support for the SyncLink Multiport (2 or 4 ports) | 246 | Enable support for the SyncLink Multiport (2 or 4 ports) |
247 | serial adapter, running asynchronous and HDLC communications up | 247 | serial adapter, running asynchronous and HDLC communications up |
diff --git a/drivers/char/random.c b/drivers/char/random.c index 7f5271272f91..397c714cf2ba 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c | |||
@@ -693,9 +693,14 @@ static void xfer_secondary_pool(struct entropy_store *r, size_t nbytes) | |||
693 | 693 | ||
694 | if (r->pull && r->entropy_count < nbytes * 8 && | 694 | if (r->pull && r->entropy_count < nbytes * 8 && |
695 | r->entropy_count < r->poolinfo->POOLBITS) { | 695 | r->entropy_count < r->poolinfo->POOLBITS) { |
696 | int bytes = max_t(int, random_read_wakeup_thresh / 8, | 696 | /* If we're limited, always leave two wakeup worth's BITS */ |
697 | min_t(int, nbytes, sizeof(tmp))); | ||
698 | int rsvd = r->limit ? 0 : random_read_wakeup_thresh/4; | 697 | int rsvd = r->limit ? 0 : random_read_wakeup_thresh/4; |
698 | int bytes = nbytes; | ||
699 | |||
700 | /* pull at least as many as BYTES as wakeup BITS */ | ||
701 | bytes = max_t(int, bytes, random_read_wakeup_thresh / 8); | ||
702 | /* but never more than the buffer size */ | ||
703 | bytes = min_t(int, bytes, sizeof(tmp)); | ||
699 | 704 | ||
700 | DEBUG_ENT("going to reseed %s with %d bits " | 705 | DEBUG_ENT("going to reseed %s with %d bits " |
701 | "(%d of %d requested)\n", | 706 | "(%d of %d requested)\n", |
diff --git a/drivers/char/serial167.c b/drivers/char/serial167.c index c585b4738f86..f1497cecffd8 100644 --- a/drivers/char/serial167.c +++ b/drivers/char/serial167.c | |||
@@ -2573,16 +2573,10 @@ static struct tty_driver *serial167_console_device(struct console *c, | |||
2573 | return cy_serial_driver; | 2573 | return cy_serial_driver; |
2574 | } | 2574 | } |
2575 | 2575 | ||
2576 | static int __init serial167_console_setup(struct console *co, char *options) | ||
2577 | { | ||
2578 | return 0; | ||
2579 | } | ||
2580 | |||
2581 | static struct console sercons = { | 2576 | static struct console sercons = { |
2582 | .name = "ttyS", | 2577 | .name = "ttyS", |
2583 | .write = serial167_console_write, | 2578 | .write = serial167_console_write, |
2584 | .device = serial167_console_device, | 2579 | .device = serial167_console_device, |
2585 | .setup = serial167_console_setup, | ||
2586 | .flags = CON_PRINTBUFFER, | 2580 | .flags = CON_PRINTBUFFER, |
2587 | .index = -1, | 2581 | .index = -1, |
2588 | }; | 2582 | }; |
diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c index 4eba32b23b29..8677fc6a545e 100644 --- a/drivers/char/tpm/tpm_bios.c +++ b/drivers/char/tpm/tpm_bios.c | |||
@@ -427,7 +427,7 @@ static int tpm_ascii_bios_measurements_open(struct inode *inode, | |||
427 | return -ENOMEM; | 427 | return -ENOMEM; |
428 | 428 | ||
429 | if ((err = read_log(log))) | 429 | if ((err = read_log(log))) |
430 | return err; | 430 | goto out_free; |
431 | 431 | ||
432 | /* now register seq file */ | 432 | /* now register seq file */ |
433 | err = seq_open(file, &tpm_ascii_b_measurments_seqops); | 433 | err = seq_open(file, &tpm_ascii_b_measurments_seqops); |
@@ -435,10 +435,15 @@ static int tpm_ascii_bios_measurements_open(struct inode *inode, | |||
435 | seq = file->private_data; | 435 | seq = file->private_data; |
436 | seq->private = log; | 436 | seq->private = log; |
437 | } else { | 437 | } else { |
438 | kfree(log->bios_event_log); | 438 | goto out_free; |
439 | kfree(log); | ||
440 | } | 439 | } |
440 | |||
441 | out: | ||
441 | return err; | 442 | return err; |
443 | out_free: | ||
444 | kfree(log->bios_event_log); | ||
445 | kfree(log); | ||
446 | goto out; | ||
442 | } | 447 | } |
443 | 448 | ||
444 | const struct file_operations tpm_ascii_bios_measurements_ops = { | 449 | const struct file_operations tpm_ascii_bios_measurements_ops = { |
@@ -460,7 +465,7 @@ static int tpm_binary_bios_measurements_open(struct inode *inode, | |||
460 | return -ENOMEM; | 465 | return -ENOMEM; |
461 | 466 | ||
462 | if ((err = read_log(log))) | 467 | if ((err = read_log(log))) |
463 | return err; | 468 | goto out_free; |
464 | 469 | ||
465 | /* now register seq file */ | 470 | /* now register seq file */ |
466 | err = seq_open(file, &tpm_binary_b_measurments_seqops); | 471 | err = seq_open(file, &tpm_binary_b_measurments_seqops); |
@@ -468,10 +473,15 @@ static int tpm_binary_bios_measurements_open(struct inode *inode, | |||
468 | seq = file->private_data; | 473 | seq = file->private_data; |
469 | seq->private = log; | 474 | seq->private = log; |
470 | } else { | 475 | } else { |
471 | kfree(log->bios_event_log); | 476 | goto out_free; |
472 | kfree(log); | ||
473 | } | 477 | } |
478 | |||
479 | out: | ||
474 | return err; | 480 | return err; |
481 | out_free: | ||
482 | kfree(log->bios_event_log); | ||
483 | kfree(log); | ||
484 | goto out; | ||
475 | } | 485 | } |
476 | 486 | ||
477 | const struct file_operations tpm_binary_bios_measurements_ops = { | 487 | const struct file_operations tpm_binary_bios_measurements_ops = { |
diff --git a/drivers/char/vme_scc.c b/drivers/char/vme_scc.c index bef6d886d4fb..e122a0e87bb0 100644 --- a/drivers/char/vme_scc.c +++ b/drivers/char/vme_scc.c | |||
@@ -1013,18 +1013,10 @@ static struct tty_driver *scc_console_device(struct console *c, int *index) | |||
1013 | return scc_driver; | 1013 | return scc_driver; |
1014 | } | 1014 | } |
1015 | 1015 | ||
1016 | |||
1017 | static int __init scc_console_setup(struct console *co, char *options) | ||
1018 | { | ||
1019 | return 0; | ||
1020 | } | ||
1021 | |||
1022 | |||
1023 | static struct console sercons = { | 1016 | static struct console sercons = { |
1024 | .name = "ttyS", | 1017 | .name = "ttyS", |
1025 | .write = scc_console_write, | 1018 | .write = scc_console_write, |
1026 | .device = scc_console_device, | 1019 | .device = scc_console_device, |
1027 | .setup = scc_console_setup, | ||
1028 | .flags = CON_PRINTBUFFER, | 1020 | .flags = CON_PRINTBUFFER, |
1029 | .index = -1, | 1021 | .index = -1, |
1030 | }; | 1022 | }; |
diff --git a/drivers/char/watchdog/Kconfig b/drivers/char/watchdog/Kconfig index 2f48ba329961..ad5cc5f6862f 100644 --- a/drivers/char/watchdog/Kconfig +++ b/drivers/char/watchdog/Kconfig | |||
@@ -602,7 +602,7 @@ config ZVM_WATCHDOG | |||
602 | 602 | ||
603 | config SH_WDT | 603 | config SH_WDT |
604 | tristate "SuperH Watchdog" | 604 | tristate "SuperH Watchdog" |
605 | depends on SUPERH | 605 | depends on SUPERH && (CPU_SH3 || CPU_SH4) |
606 | help | 606 | help |
607 | This driver adds watchdog support for the integrated watchdog in the | 607 | This driver adds watchdog support for the integrated watchdog in the |
608 | SuperH processors. If you have one of these processors and wish | 608 | SuperH processors. If you have one of these processors and wish |
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 13eea47dceb3..dbdca6f10e46 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig | |||
@@ -29,17 +29,34 @@ config HWMON_VID | |||
29 | default n | 29 | default n |
30 | 30 | ||
31 | config SENSORS_ABITUGURU | 31 | config SENSORS_ABITUGURU |
32 | tristate "Abit uGuru" | 32 | tristate "Abit uGuru (rev 1 & 2)" |
33 | depends on EXPERIMENTAL | 33 | depends on EXPERIMENTAL |
34 | help | 34 | help |
35 | If you say yes here you get support for the Abit uGuru chips | 35 | If you say yes here you get support for the sensor part of the first |
36 | sensor part. The voltage and frequency control parts of the Abit | 36 | and second revision of the Abit uGuru chip. The voltage and frequency |
37 | uGuru are not supported. The Abit uGuru chip can be found on Abit | 37 | control parts of the Abit uGuru are not supported. The Abit uGuru |
38 | uGuru featuring motherboards (most modern Abit motherboards). | 38 | chip can be found on Abit uGuru featuring motherboards (most modern |
39 | Abit motherboards from before end 2005). For more info and a list | ||
40 | of which motherboards have which revision see | ||
41 | Documentation/hwmon/abituguru | ||
39 | 42 | ||
40 | This driver can also be built as a module. If so, the module | 43 | This driver can also be built as a module. If so, the module |
41 | will be called abituguru. | 44 | will be called abituguru. |
42 | 45 | ||
46 | config SENSORS_ABITUGURU3 | ||
47 | tristate "Abit uGuru (rev 3)" | ||
48 | depends on HWMON && EXPERIMENTAL | ||
49 | help | ||
50 | If you say yes here you get support for the sensor part of the | ||
51 | third revision of the Abit uGuru chip. Only reading the sensors | ||
52 | and their settings is supported. The third revision of the Abit | ||
53 | uGuru chip can be found on recent Abit motherboards (since end | ||
54 | 2005). For more info and a list of which motherboards have which | ||
55 | revision see Documentation/hwmon/abituguru3 | ||
56 | |||
57 | This driver can also be built as a module. If so, the module | ||
58 | will be called abituguru3. | ||
59 | |||
43 | config SENSORS_AD7418 | 60 | config SENSORS_AD7418 |
44 | tristate "Analog Devices AD7416, AD7417 and AD7418" | 61 | tristate "Analog Devices AD7416, AD7417 and AD7418" |
45 | depends on I2C && EXPERIMENTAL | 62 | depends on I2C && EXPERIMENTAL |
@@ -250,12 +267,10 @@ config SENSORS_CORETEMP | |||
250 | 267 | ||
251 | config SENSORS_IT87 | 268 | config SENSORS_IT87 |
252 | tristate "ITE IT87xx and compatibles" | 269 | tristate "ITE IT87xx and compatibles" |
253 | depends on I2C | ||
254 | select I2C_ISA | ||
255 | select HWMON_VID | 270 | select HWMON_VID |
256 | help | 271 | help |
257 | If you say yes here you get support for ITE IT8705F, IT8712F, | 272 | If you say yes here you get support for ITE IT8705F, IT8712F, |
258 | IT8716F and IT8718F sensor chips, and the SiS960 clone. | 273 | IT8716F, IT8718F and IT8726F sensor chips, and the SiS960 clone. |
259 | 274 | ||
260 | This driver can also be built as a module. If so, the module | 275 | This driver can also be built as a module. If so, the module |
261 | will be called it87. | 276 | will be called it87. |
@@ -365,8 +380,8 @@ config SENSORS_LM90 | |||
365 | depends on I2C | 380 | depends on I2C |
366 | help | 381 | help |
367 | If you say yes here you get support for National Semiconductor LM90, | 382 | If you say yes here you get support for National Semiconductor LM90, |
368 | LM86, LM89 and LM99, Analog Devices ADM1032 and Maxim MAX6657 and | 383 | LM86, LM89 and LM99, Analog Devices ADM1032 and Maxim MAX6657, |
369 | MAX6658 sensor chips. | 384 | MAX6658, MAX6659, MAX6680 and MAX6681 sensor chips. |
370 | 385 | ||
371 | The Analog Devices ADT7461 sensor chip is also supported, but only | 386 | The Analog Devices ADT7461 sensor chip is also supported, but only |
372 | if found in ADM1032 compatibility mode. | 387 | if found in ADM1032 compatibility mode. |
@@ -384,6 +399,17 @@ config SENSORS_LM92 | |||
384 | This driver can also be built as a module. If so, the module | 399 | This driver can also be built as a module. If so, the module |
385 | will be called lm92. | 400 | will be called lm92. |
386 | 401 | ||
402 | config SENSORS_LM93 | ||
403 | tristate "National Semiconductor LM93 and compatibles" | ||
404 | depends on HWMON && I2C | ||
405 | select HWMON_VID | ||
406 | help | ||
407 | If you say yes here you get support for National Semiconductor LM93 | ||
408 | sensor chips. | ||
409 | |||
410 | This driver can also be built as a module. If so, the module | ||
411 | will be called lm93. | ||
412 | |||
387 | config SENSORS_MAX1619 | 413 | config SENSORS_MAX1619 |
388 | tristate "Maxim MAX1619 sensor chip" | 414 | tristate "Maxim MAX1619 sensor chip" |
389 | depends on I2C | 415 | depends on I2C |
@@ -405,8 +431,6 @@ config SENSORS_MAX6650 | |||
405 | 431 | ||
406 | config SENSORS_PC87360 | 432 | config SENSORS_PC87360 |
407 | tristate "National Semiconductor PC87360 family" | 433 | tristate "National Semiconductor PC87360 family" |
408 | depends on I2C && EXPERIMENTAL | ||
409 | select I2C_ISA | ||
410 | select HWMON_VID | 434 | select HWMON_VID |
411 | help | 435 | help |
412 | If you say yes here you get access to the hardware monitoring | 436 | If you say yes here you get access to the hardware monitoring |
@@ -433,8 +457,7 @@ config SENSORS_PC87427 | |||
433 | 457 | ||
434 | config SENSORS_SIS5595 | 458 | config SENSORS_SIS5595 |
435 | tristate "Silicon Integrated Systems Corp. SiS5595" | 459 | tristate "Silicon Integrated Systems Corp. SiS5595" |
436 | depends on I2C && PCI && EXPERIMENTAL | 460 | depends on PCI |
437 | select I2C_ISA | ||
438 | help | 461 | help |
439 | If you say yes here you get support for the integrated sensors in | 462 | If you say yes here you get support for the integrated sensors in |
440 | SiS5595 South Bridges. | 463 | SiS5595 South Bridges. |
@@ -442,6 +465,18 @@ config SENSORS_SIS5595 | |||
442 | This driver can also be built as a module. If so, the module | 465 | This driver can also be built as a module. If so, the module |
443 | will be called sis5595. | 466 | will be called sis5595. |
444 | 467 | ||
468 | config SENSORS_DME1737 | ||
469 | tristate "SMSC DME1737 and compatibles" | ||
470 | depends on I2C && EXPERIMENTAL | ||
471 | select HWMON_VID | ||
472 | help | ||
473 | If you say yes here you get support for the hardware monitoring | ||
474 | and fan control features of the SMSC DME1737 (and compatibles | ||
475 | like the Asus A8000) Super-I/O chip. | ||
476 | |||
477 | This driver can also be built as a module. If so, the module | ||
478 | will be called dme1737. | ||
479 | |||
445 | config SENSORS_SMSC47M1 | 480 | config SENSORS_SMSC47M1 |
446 | tristate "SMSC LPC47M10x and compatibles" | 481 | tristate "SMSC LPC47M10x and compatibles" |
447 | help | 482 | help |
@@ -487,8 +522,7 @@ config SENSORS_SMSC47B397 | |||
487 | 522 | ||
488 | config SENSORS_VIA686A | 523 | config SENSORS_VIA686A |
489 | tristate "VIA686A" | 524 | tristate "VIA686A" |
490 | depends on I2C && PCI | 525 | depends on PCI |
491 | select I2C_ISA | ||
492 | help | 526 | help |
493 | If you say yes here you get support for the integrated sensors in | 527 | If you say yes here you get support for the integrated sensors in |
494 | Via 686A/B South Bridges. | 528 | Via 686A/B South Bridges. |
@@ -509,9 +543,8 @@ config SENSORS_VT1211 | |||
509 | 543 | ||
510 | config SENSORS_VT8231 | 544 | config SENSORS_VT8231 |
511 | tristate "VIA VT8231" | 545 | tristate "VIA VT8231" |
512 | depends on I2C && PCI && EXPERIMENTAL | 546 | depends on PCI |
513 | select HWMON_VID | 547 | select HWMON_VID |
514 | select I2C_ISA | ||
515 | help | 548 | help |
516 | If you say yes here then you get support for the integrated sensors | 549 | If you say yes here then you get support for the integrated sensors |
517 | in the VIA VT8231 device. | 550 | in the VIA VT8231 device. |
@@ -584,17 +617,16 @@ config SENSORS_W83627HF | |||
584 | will be called w83627hf. | 617 | will be called w83627hf. |
585 | 618 | ||
586 | config SENSORS_W83627EHF | 619 | config SENSORS_W83627EHF |
587 | tristate "Winbond W83627EHF" | 620 | tristate "Winbond W83627EHF/DHG" |
588 | depends on I2C && EXPERIMENTAL | 621 | select HWMON_VID |
589 | select I2C_ISA | ||
590 | help | 622 | help |
591 | If you say yes here you get preliminary support for the hardware | 623 | If you say yes here you get support for the hardware |
592 | monitoring functionality of the Winbond W83627EHF Super-I/O chip. | 624 | monitoring functionality of the Winbond W83627EHF Super-I/O chip. |
593 | Only fan and temperature inputs are supported at the moment, while | ||
594 | the chip does much more than that. | ||
595 | 625 | ||
596 | This driver also supports the W83627EHG, which is the lead-free | 626 | This driver also supports the W83627EHG, which is the lead-free |
597 | version of the W83627EHF. | 627 | version of the W83627EHF, and the W83627DHG, which is a similar |
628 | chip suited for specific Intel processors that use PECI such as | ||
629 | the Core 2 Duo. | ||
598 | 630 | ||
599 | This driver can also be built as a module. If so, the module | 631 | This driver can also be built as a module. If so, the module |
600 | will be called w83627ehf. | 632 | will be called w83627ehf. |
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index cfaf338919dd..59f81fae40a0 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile | |||
@@ -14,6 +14,7 @@ obj-$(CONFIG_SENSORS_W83781D) += w83781d.o | |||
14 | obj-$(CONFIG_SENSORS_W83791D) += w83791d.o | 14 | obj-$(CONFIG_SENSORS_W83791D) += w83791d.o |
15 | 15 | ||
16 | obj-$(CONFIG_SENSORS_ABITUGURU) += abituguru.o | 16 | obj-$(CONFIG_SENSORS_ABITUGURU) += abituguru.o |
17 | obj-$(CONFIG_SENSORS_ABITUGURU3)+= abituguru3.o | ||
17 | obj-$(CONFIG_SENSORS_AD7418) += ad7418.o | 18 | obj-$(CONFIG_SENSORS_AD7418) += ad7418.o |
18 | obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o | 19 | obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o |
19 | obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o | 20 | obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o |
@@ -25,6 +26,7 @@ obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o | |||
25 | obj-$(CONFIG_SENSORS_AMS) += ams/ | 26 | obj-$(CONFIG_SENSORS_AMS) += ams/ |
26 | obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o | 27 | obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o |
27 | obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o | 28 | obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o |
29 | obj-$(CONFIG_SENSORS_DME1737) += dme1737.o | ||
28 | obj-$(CONFIG_SENSORS_DS1621) += ds1621.o | 30 | obj-$(CONFIG_SENSORS_DS1621) += ds1621.o |
29 | obj-$(CONFIG_SENSORS_F71805F) += f71805f.o | 31 | obj-$(CONFIG_SENSORS_F71805F) += f71805f.o |
30 | obj-$(CONFIG_SENSORS_FSCHER) += fscher.o | 32 | obj-$(CONFIG_SENSORS_FSCHER) += fscher.o |
@@ -45,6 +47,7 @@ obj-$(CONFIG_SENSORS_LM85) += lm85.o | |||
45 | obj-$(CONFIG_SENSORS_LM87) += lm87.o | 47 | obj-$(CONFIG_SENSORS_LM87) += lm87.o |
46 | obj-$(CONFIG_SENSORS_LM90) += lm90.o | 48 | obj-$(CONFIG_SENSORS_LM90) += lm90.o |
47 | obj-$(CONFIG_SENSORS_LM92) += lm92.o | 49 | obj-$(CONFIG_SENSORS_LM92) += lm92.o |
50 | obj-$(CONFIG_SENSORS_LM93) += lm93.o | ||
48 | obj-$(CONFIG_SENSORS_MAX1619) += max1619.o | 51 | obj-$(CONFIG_SENSORS_MAX1619) += max1619.o |
49 | obj-$(CONFIG_SENSORS_MAX6650) += max6650.o | 52 | obj-$(CONFIG_SENSORS_MAX6650) += max6650.o |
50 | obj-$(CONFIG_SENSORS_PC87360) += pc87360.o | 53 | obj-$(CONFIG_SENSORS_PC87360) += pc87360.o |
diff --git a/drivers/hwmon/abituguru.c b/drivers/hwmon/abituguru.c index bede4d990ea6..d575ee958de5 100644 --- a/drivers/hwmon/abituguru.c +++ b/drivers/hwmon/abituguru.c | |||
@@ -16,9 +16,9 @@ | |||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | */ | 17 | */ |
18 | /* | 18 | /* |
19 | This driver supports the sensor part of the custom Abit uGuru chip found | 19 | This driver supports the sensor part of the first and second revision of |
20 | on Abit uGuru motherboards. Note: because of lack of specs the CPU / RAM / | 20 | the custom Abit uGuru chip found on Abit uGuru motherboards. Note: because |
21 | etc voltage & frequency control is not supported! | 21 | of lack of specs the CPU/RAM voltage & frequency control is not supported! |
22 | */ | 22 | */ |
23 | #include <linux/module.h> | 23 | #include <linux/module.h> |
24 | #include <linux/sched.h> | 24 | #include <linux/sched.h> |
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/platform_device.h> | 31 | #include <linux/platform_device.h> |
32 | #include <linux/hwmon.h> | 32 | #include <linux/hwmon.h> |
33 | #include <linux/hwmon-sysfs.h> | 33 | #include <linux/hwmon-sysfs.h> |
34 | #include <linux/dmi.h> | ||
34 | #include <asm/io.h> | 35 | #include <asm/io.h> |
35 | 36 | ||
36 | /* Banks */ | 37 | /* Banks */ |
@@ -418,7 +419,7 @@ static int __devinit | |||
418 | abituguru_detect_bank1_sensor_type(struct abituguru_data *data, | 419 | abituguru_detect_bank1_sensor_type(struct abituguru_data *data, |
419 | u8 sensor_addr) | 420 | u8 sensor_addr) |
420 | { | 421 | { |
421 | u8 val, buf[3]; | 422 | u8 val, test_flag, buf[3]; |
422 | int i, ret = -ENODEV; /* error is the most common used retval :| */ | 423 | int i, ret = -ENODEV; /* error is the most common used retval :| */ |
423 | 424 | ||
424 | /* If overriden by the user return the user selected type */ | 425 | /* If overriden by the user return the user selected type */ |
@@ -436,7 +437,7 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data, | |||
436 | return -ENODEV; | 437 | return -ENODEV; |
437 | 438 | ||
438 | /* Test val is sane / usable for sensor type detection. */ | 439 | /* Test val is sane / usable for sensor type detection. */ |
439 | if ((val < 10u) || (val > 240u)) { | 440 | if ((val < 10u) || (val > 250u)) { |
440 | printk(KERN_WARNING ABIT_UGURU_NAME | 441 | printk(KERN_WARNING ABIT_UGURU_NAME |
441 | ": bank1-sensor: %d reading (%d) too close to limits, " | 442 | ": bank1-sensor: %d reading (%d) too close to limits, " |
442 | "unable to determine sensor type, skipping sensor\n", | 443 | "unable to determine sensor type, skipping sensor\n", |
@@ -449,10 +450,20 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data, | |||
449 | 450 | ||
450 | ABIT_UGURU_DEBUG(2, "testing bank1 sensor %d\n", (int)sensor_addr); | 451 | ABIT_UGURU_DEBUG(2, "testing bank1 sensor %d\n", (int)sensor_addr); |
451 | /* Volt sensor test, enable volt low alarm, set min value ridicously | 452 | /* Volt sensor test, enable volt low alarm, set min value ridicously |
452 | high. If its a volt sensor this should always give us an alarm. */ | 453 | high, or vica versa if the reading is very high. If its a volt |
453 | buf[0] = ABIT_UGURU_VOLT_LOW_ALARM_ENABLE; | 454 | sensor this should always give us an alarm. */ |
454 | buf[1] = 245; | 455 | if (val <= 240u) { |
455 | buf[2] = 250; | 456 | buf[0] = ABIT_UGURU_VOLT_LOW_ALARM_ENABLE; |
457 | buf[1] = 245; | ||
458 | buf[2] = 250; | ||
459 | test_flag = ABIT_UGURU_VOLT_LOW_ALARM_FLAG; | ||
460 | } else { | ||
461 | buf[0] = ABIT_UGURU_VOLT_HIGH_ALARM_ENABLE; | ||
462 | buf[1] = 5; | ||
463 | buf[2] = 10; | ||
464 | test_flag = ABIT_UGURU_VOLT_HIGH_ALARM_FLAG; | ||
465 | } | ||
466 | |||
456 | if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, | 467 | if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, |
457 | buf, 3) != 3) | 468 | buf, 3) != 3) |
458 | goto abituguru_detect_bank1_sensor_type_exit; | 469 | goto abituguru_detect_bank1_sensor_type_exit; |
@@ -469,13 +480,13 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data, | |||
469 | sensor_addr, buf, 3, | 480 | sensor_addr, buf, 3, |
470 | ABIT_UGURU_MAX_RETRIES) != 3) | 481 | ABIT_UGURU_MAX_RETRIES) != 3) |
471 | goto abituguru_detect_bank1_sensor_type_exit; | 482 | goto abituguru_detect_bank1_sensor_type_exit; |
472 | if (buf[0] & ABIT_UGURU_VOLT_LOW_ALARM_FLAG) { | 483 | if (buf[0] & test_flag) { |
473 | ABIT_UGURU_DEBUG(2, " found volt sensor\n"); | 484 | ABIT_UGURU_DEBUG(2, " found volt sensor\n"); |
474 | ret = ABIT_UGURU_IN_SENSOR; | 485 | ret = ABIT_UGURU_IN_SENSOR; |
475 | goto abituguru_detect_bank1_sensor_type_exit; | 486 | goto abituguru_detect_bank1_sensor_type_exit; |
476 | } else | 487 | } else |
477 | ABIT_UGURU_DEBUG(2, " alarm raised during volt " | 488 | ABIT_UGURU_DEBUG(2, " alarm raised during volt " |
478 | "sensor test, but volt low flag not set\n"); | 489 | "sensor test, but volt range flag not set\n"); |
479 | } else | 490 | } else |
480 | ABIT_UGURU_DEBUG(2, " alarm not raised during volt sensor " | 491 | ABIT_UGURU_DEBUG(2, " alarm not raised during volt sensor " |
481 | "test\n"); | 492 | "test\n"); |
@@ -1287,6 +1298,7 @@ abituguru_probe_error: | |||
1287 | for (i = 0; i < ARRAY_SIZE(abituguru_sysfs_attr); i++) | 1298 | for (i = 0; i < ARRAY_SIZE(abituguru_sysfs_attr); i++) |
1288 | device_remove_file(&pdev->dev, | 1299 | device_remove_file(&pdev->dev, |
1289 | &abituguru_sysfs_attr[i].dev_attr); | 1300 | &abituguru_sysfs_attr[i].dev_attr); |
1301 | platform_set_drvdata(pdev, NULL); | ||
1290 | kfree(data); | 1302 | kfree(data); |
1291 | return res; | 1303 | return res; |
1292 | } | 1304 | } |
@@ -1296,13 +1308,13 @@ static int __devexit abituguru_remove(struct platform_device *pdev) | |||
1296 | int i; | 1308 | int i; |
1297 | struct abituguru_data *data = platform_get_drvdata(pdev); | 1309 | struct abituguru_data *data = platform_get_drvdata(pdev); |
1298 | 1310 | ||
1299 | platform_set_drvdata(pdev, NULL); | ||
1300 | hwmon_device_unregister(data->class_dev); | 1311 | hwmon_device_unregister(data->class_dev); |
1301 | for (i = 0; data->sysfs_attr[i].dev_attr.attr.name; i++) | 1312 | for (i = 0; data->sysfs_attr[i].dev_attr.attr.name; i++) |
1302 | device_remove_file(&pdev->dev, &data->sysfs_attr[i].dev_attr); | 1313 | device_remove_file(&pdev->dev, &data->sysfs_attr[i].dev_attr); |
1303 | for (i = 0; i < ARRAY_SIZE(abituguru_sysfs_attr); i++) | 1314 | for (i = 0; i < ARRAY_SIZE(abituguru_sysfs_attr); i++) |
1304 | device_remove_file(&pdev->dev, | 1315 | device_remove_file(&pdev->dev, |
1305 | &abituguru_sysfs_attr[i].dev_attr); | 1316 | &abituguru_sysfs_attr[i].dev_attr); |
1317 | platform_set_drvdata(pdev, NULL); | ||
1306 | kfree(data); | 1318 | kfree(data); |
1307 | 1319 | ||
1308 | return 0; | 1320 | return 0; |
@@ -1436,6 +1448,15 @@ static int __init abituguru_init(void) | |||
1436 | int address, err; | 1448 | int address, err; |
1437 | struct resource res = { .flags = IORESOURCE_IO }; | 1449 | struct resource res = { .flags = IORESOURCE_IO }; |
1438 | 1450 | ||
1451 | #ifdef CONFIG_DMI | ||
1452 | char *board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR); | ||
1453 | |||
1454 | /* safety check, refuse to load on non Abit motherboards */ | ||
1455 | if (!force && (!board_vendor || | ||
1456 | strcmp(board_vendor, "http://www.abit.com.tw/"))) | ||
1457 | return -ENODEV; | ||
1458 | #endif | ||
1459 | |||
1439 | address = abituguru_detect(); | 1460 | address = abituguru_detect(); |
1440 | if (address < 0) | 1461 | if (address < 0) |
1441 | return address; | 1462 | return address; |
diff --git a/drivers/hwmon/abituguru3.c b/drivers/hwmon/abituguru3.c new file mode 100644 index 000000000000..a003d104ca45 --- /dev/null +++ b/drivers/hwmon/abituguru3.c | |||
@@ -0,0 +1,1140 @@ | |||
1 | /* | ||
2 | abituguru3.c Copyright (c) 2006 Hans de Goede <j.w.r.degoede@hhs.nl> | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
17 | */ | ||
18 | /* | ||
19 | This driver supports the sensor part of revision 3 of the custom Abit uGuru | ||
20 | chip found on newer Abit uGuru motherboards. Note: because of lack of specs | ||
21 | only reading the sensors and their settings is supported. | ||
22 | */ | ||
23 | #include <linux/module.h> | ||
24 | #include <linux/init.h> | ||
25 | #include <linux/slab.h> | ||
26 | #include <linux/jiffies.h> | ||
27 | #include <linux/mutex.h> | ||
28 | #include <linux/err.h> | ||
29 | #include <linux/delay.h> | ||
30 | #include <linux/platform_device.h> | ||
31 | #include <linux/hwmon.h> | ||
32 | #include <linux/hwmon-sysfs.h> | ||
33 | #include <asm/io.h> | ||
34 | |||
35 | /* uGuru3 bank addresses */ | ||
36 | #define ABIT_UGURU3_SETTINGS_BANK 0x01 | ||
37 | #define ABIT_UGURU3_SENSORS_BANK 0x08 | ||
38 | #define ABIT_UGURU3_MISC_BANK 0x09 | ||
39 | #define ABIT_UGURU3_ALARMS_START 0x1E | ||
40 | #define ABIT_UGURU3_SETTINGS_START 0x24 | ||
41 | #define ABIT_UGURU3_VALUES_START 0x80 | ||
42 | #define ABIT_UGURU3_BOARD_ID 0x0A | ||
43 | /* uGuru3 sensor bank flags */ /* Alarm if: */ | ||
44 | #define ABIT_UGURU3_TEMP_HIGH_ALARM_ENABLE 0x01 /* temp over warn */ | ||
45 | #define ABIT_UGURU3_VOLT_HIGH_ALARM_ENABLE 0x02 /* volt over max */ | ||
46 | #define ABIT_UGURU3_VOLT_LOW_ALARM_ENABLE 0x04 /* volt under min */ | ||
47 | #define ABIT_UGURU3_TEMP_HIGH_ALARM_FLAG 0x10 /* temp is over warn */ | ||
48 | #define ABIT_UGURU3_VOLT_HIGH_ALARM_FLAG 0x20 /* volt is over max */ | ||
49 | #define ABIT_UGURU3_VOLT_LOW_ALARM_FLAG 0x40 /* volt is under min */ | ||
50 | #define ABIT_UGURU3_FAN_LOW_ALARM_ENABLE 0x01 /* fan under min */ | ||
51 | #define ABIT_UGURU3_BEEP_ENABLE 0x08 /* beep if alarm */ | ||
52 | #define ABIT_UGURU3_SHUTDOWN_ENABLE 0x80 /* shutdown if alarm */ | ||
53 | /* sensor types */ | ||
54 | #define ABIT_UGURU3_IN_SENSOR 0 | ||
55 | #define ABIT_UGURU3_TEMP_SENSOR 1 | ||
56 | #define ABIT_UGURU3_FAN_SENSOR 2 | ||
57 | |||
58 | /* Timeouts / Retries, if these turn out to need a lot of fiddling we could | ||
59 | convert them to params. Determined by trial and error. I assume this is | ||
60 | cpu-speed independent, since the ISA-bus and not the CPU should be the | ||
61 | bottleneck. */ | ||
62 | #define ABIT_UGURU3_WAIT_TIMEOUT 250 | ||
63 | /* Normally the 0xAC at the end of synchronize() is reported after the | ||
64 | first read, but sometimes not and we need to poll */ | ||
65 | #define ABIT_UGURU3_SYNCHRONIZE_TIMEOUT 5 | ||
66 | /* utility macros */ | ||
67 | #define ABIT_UGURU3_NAME "abituguru3" | ||
68 | #define ABIT_UGURU3_DEBUG(format, arg...) \ | ||
69 | if (verbose) \ | ||
70 | printk(KERN_DEBUG ABIT_UGURU3_NAME ": " format , ## arg) | ||
71 | |||
72 | /* Macros to help calculate the sysfs_names array length */ | ||
73 | #define ABIT_UGURU3_MAX_NO_SENSORS 26 | ||
74 | /* sum of strlen +1 of: in??_input\0, in??_{min,max}\0, in??_{min,max}_alarm\0, | ||
75 | in??_{min,max}_alarm_enable\0, in??_beep\0, in??_shutdown\0, in??_label\0 */ | ||
76 | #define ABIT_UGURU3_IN_NAMES_LENGTH (11 + 2 * 9 + 2 * 15 + 2 * 22 + 10 + 14 + 11) | ||
77 | /* sum of strlen +1 of: temp??_input\0, temp??_max\0, temp??_crit\0, | ||
78 | temp??_alarm\0, temp??_alarm_enable\0, temp??_beep\0, temp??_shutdown\0, | ||
79 | temp??_label\0 */ | ||
80 | #define ABIT_UGURU3_TEMP_NAMES_LENGTH (13 + 11 + 12 + 13 + 20 + 12 + 16 + 13) | ||
81 | /* sum of strlen +1 of: fan??_input\0, fan??_min\0, fan??_alarm\0, | ||
82 | fan??_alarm_enable\0, fan??_beep\0, fan??_shutdown\0, fan??_label\0 */ | ||
83 | #define ABIT_UGURU3_FAN_NAMES_LENGTH (12 + 10 + 12 + 19 + 11 + 15 + 12) | ||
84 | /* Worst case scenario 16 in sensors (longest names_length) and the rest | ||
85 | temp sensors (second longest names_length). */ | ||
86 | #define ABIT_UGURU3_SYSFS_NAMES_LENGTH (16 * ABIT_UGURU3_IN_NAMES_LENGTH + \ | ||
87 | (ABIT_UGURU3_MAX_NO_SENSORS - 16) * ABIT_UGURU3_TEMP_NAMES_LENGTH) | ||
88 | |||
89 | /* All the macros below are named identical to the openguru2 program | ||
90 | reverse engineered by Louis Kruger, hence the names might not be 100% | ||
91 | logical. I could come up with better names, but I prefer keeping the names | ||
92 | identical so that this driver can be compared with his work more easily. */ | ||
93 | /* Two i/o-ports are used by uGuru */ | ||
94 | #define ABIT_UGURU3_BASE 0x00E0 | ||
95 | #define ABIT_UGURU3_CMD 0x00 | ||
96 | #define ABIT_UGURU3_DATA 0x04 | ||
97 | #define ABIT_UGURU3_REGION_LENGTH 5 | ||
98 | /* The wait_xxx functions return this on success and the last contents | ||
99 | of the DATA register (0-255) on failure. */ | ||
100 | #define ABIT_UGURU3_SUCCESS -1 | ||
101 | /* uGuru status flags */ | ||
102 | #define ABIT_UGURU3_STATUS_READY_FOR_READ 0x01 | ||
103 | #define ABIT_UGURU3_STATUS_BUSY 0x02 | ||
104 | |||
105 | |||
106 | /* Structures */ | ||
107 | struct abituguru3_sensor_info { | ||
108 | const char* name; | ||
109 | int port; | ||
110 | int type; | ||
111 | int multiplier; | ||
112 | int divisor; | ||
113 | int offset; | ||
114 | }; | ||
115 | |||
116 | struct abituguru3_motherboard_info { | ||
117 | u16 id; | ||
118 | const char *name; | ||
119 | /* + 1 -> end of sensors indicated by a sensor with name == NULL */ | ||
120 | struct abituguru3_sensor_info sensors[ABIT_UGURU3_MAX_NO_SENSORS + 1]; | ||
121 | }; | ||
122 | |||
123 | /* For the Abit uGuru, we need to keep some data in memory. | ||
124 | The structure is dynamically allocated, at the same time when a new | ||
125 | abituguru3 device is allocated. */ | ||
126 | struct abituguru3_data { | ||
127 | struct class_device *class_dev; /* hwmon registered device */ | ||
128 | struct mutex update_lock; /* protect access to data and uGuru */ | ||
129 | unsigned short addr; /* uguru base address */ | ||
130 | char valid; /* !=0 if following fields are valid */ | ||
131 | unsigned long last_updated; /* In jiffies */ | ||
132 | |||
133 | /* For convenience the sysfs attr and their names are generated | ||
134 | automatically. We have max 10 entries per sensor (for in sensors) */ | ||
135 | struct sensor_device_attribute_2 sysfs_attr[ABIT_UGURU3_MAX_NO_SENSORS | ||
136 | * 10]; | ||
137 | |||
138 | /* Buffer to store the dynamically generated sysfs names */ | ||
139 | char sysfs_names[ABIT_UGURU3_SYSFS_NAMES_LENGTH]; | ||
140 | |||
141 | /* Pointer to the sensors info for the detected motherboard */ | ||
142 | const struct abituguru3_sensor_info *sensors; | ||
143 | |||
144 | /* The abituguru3 supports upto 48 sensors, and thus has registers | ||
145 | sets for 48 sensors, for convienence reasons / simplicity of the | ||
146 | code we always read and store all registers for all 48 sensors */ | ||
147 | |||
148 | /* Alarms for all 48 sensors (1 bit per sensor) */ | ||
149 | u8 alarms[48/8]; | ||
150 | |||
151 | /* Value of all 48 sensors */ | ||
152 | u8 value[48]; | ||
153 | |||
154 | /* Settings of all 48 sensors, note in and temp sensors (the first 32 | ||
155 | sensors) have 3 bytes of settings, while fans only have 2 bytes, | ||
156 | for convenience we use 3 bytes for all sensors */ | ||
157 | u8 settings[48][3]; | ||
158 | }; | ||
159 | |||
160 | |||
161 | /* Constants */ | ||
162 | static const struct abituguru3_motherboard_info abituguru3_motherboards[] = { | ||
163 | { 0x000C, "unknown", { | ||
164 | { "CPU Core", 0, 0, 10, 1, 0 }, | ||
165 | { "DDR", 1, 0, 10, 1, 0 }, | ||
166 | { "DDR VTT", 2, 0, 10, 1, 0 }, | ||
167 | { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, | ||
168 | { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 }, | ||
169 | { "MCH 2.5V", 5, 0, 20, 1, 0 }, | ||
170 | { "ICH 1.05V", 6, 0, 10, 1, 0 }, | ||
171 | { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, | ||
172 | { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, | ||
173 | { "ATX +5V", 9, 0, 30, 1, 0 }, | ||
174 | { "+3.3V", 10, 0, 20, 1, 0 }, | ||
175 | { "5VSB", 11, 0, 30, 1, 0 }, | ||
176 | { "CPU", 24, 1, 1, 1, 0 }, | ||
177 | { "System ", 25, 1, 1, 1, 0 }, | ||
178 | { "PWM", 26, 1, 1, 1, 0 }, | ||
179 | { "CPU Fan", 32, 2, 60, 1, 0 }, | ||
180 | { "NB Fan", 33, 2, 60, 1, 0 }, | ||
181 | { "SYS FAN", 34, 2, 60, 1, 0 }, | ||
182 | { "AUX1 Fan", 35, 2, 60, 1, 0 }, | ||
183 | { NULL, 0, 0, 0, 0, 0 } } | ||
184 | }, | ||
185 | { 0x000D, "Abit AW8", { | ||
186 | { "CPU Core", 0, 0, 10, 1, 0 }, | ||
187 | { "DDR", 1, 0, 10, 1, 0 }, | ||
188 | { "DDR VTT", 2, 0, 10, 1, 0 }, | ||
189 | { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, | ||
190 | { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 }, | ||
191 | { "MCH 2.5V", 5, 0, 20, 1, 0 }, | ||
192 | { "ICH 1.05V", 6, 0, 10, 1, 0 }, | ||
193 | { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, | ||
194 | { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, | ||
195 | { "ATX +5V", 9, 0, 30, 1, 0 }, | ||
196 | { "+3.3V", 10, 0, 20, 1, 0 }, | ||
197 | { "5VSB", 11, 0, 30, 1, 0 }, | ||
198 | { "CPU", 24, 1, 1, 1, 0 }, | ||
199 | { "System ", 25, 1, 1, 1, 0 }, | ||
200 | { "PWM1", 26, 1, 1, 1, 0 }, | ||
201 | { "PWM2", 27, 1, 1, 1, 0 }, | ||
202 | { "PWM3", 28, 1, 1, 1, 0 }, | ||
203 | { "PWM4", 29, 1, 1, 1, 0 }, | ||
204 | { "CPU Fan", 32, 2, 60, 1, 0 }, | ||
205 | { "NB Fan", 33, 2, 60, 1, 0 }, | ||
206 | { "SYS Fan", 34, 2, 60, 1, 0 }, | ||
207 | { "AUX1 Fan", 35, 2, 60, 1, 0 }, | ||
208 | { "AUX2 Fan", 36, 2, 60, 1, 0 }, | ||
209 | { "AUX3 Fan", 37, 2, 60, 1, 0 }, | ||
210 | { "AUX4 Fan", 38, 2, 60, 1, 0 }, | ||
211 | { "AUX5 Fan", 39, 2, 60, 1, 0 }, | ||
212 | { NULL, 0, 0, 0, 0, 0 } } | ||
213 | }, | ||
214 | { 0x000E, "AL-8", { | ||
215 | { "CPU Core", 0, 0, 10, 1, 0 }, | ||
216 | { "DDR", 1, 0, 10, 1, 0 }, | ||
217 | { "DDR VTT", 2, 0, 10, 1, 0 }, | ||
218 | { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, | ||
219 | { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 }, | ||
220 | { "MCH 2.5V", 5, 0, 20, 1, 0 }, | ||
221 | { "ICH 1.05V", 6, 0, 10, 1, 0 }, | ||
222 | { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, | ||
223 | { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, | ||
224 | { "ATX +5V", 9, 0, 30, 1, 0 }, | ||
225 | { "+3.3V", 10, 0, 20, 1, 0 }, | ||
226 | { "5VSB", 11, 0, 30, 1, 0 }, | ||
227 | { "CPU", 24, 1, 1, 1, 0 }, | ||
228 | { "System ", 25, 1, 1, 1, 0 }, | ||
229 | { "PWM", 26, 1, 1, 1, 0 }, | ||
230 | { "CPU Fan", 32, 2, 60, 1, 0 }, | ||
231 | { "NB Fan", 33, 2, 60, 1, 0 }, | ||
232 | { "SYS Fan", 34, 2, 60, 1, 0 }, | ||
233 | { NULL, 0, 0, 0, 0, 0 } } | ||
234 | }, | ||
235 | { 0x000F, "unknown", { | ||
236 | { "CPU Core", 0, 0, 10, 1, 0 }, | ||
237 | { "DDR", 1, 0, 10, 1, 0 }, | ||
238 | { "DDR VTT", 2, 0, 10, 1, 0 }, | ||
239 | { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, | ||
240 | { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 }, | ||
241 | { "MCH 2.5V", 5, 0, 20, 1, 0 }, | ||
242 | { "ICH 1.05V", 6, 0, 10, 1, 0 }, | ||
243 | { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, | ||
244 | { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, | ||
245 | { "ATX +5V", 9, 0, 30, 1, 0 }, | ||
246 | { "+3.3V", 10, 0, 20, 1, 0 }, | ||
247 | { "5VSB", 11, 0, 30, 1, 0 }, | ||
248 | { "CPU", 24, 1, 1, 1, 0 }, | ||
249 | { "System ", 25, 1, 1, 1, 0 }, | ||
250 | { "PWM", 26, 1, 1, 1, 0 }, | ||
251 | { "CPU Fan", 32, 2, 60, 1, 0 }, | ||
252 | { "NB Fan", 33, 2, 60, 1, 0 }, | ||
253 | { "SYS Fan", 34, 2, 60, 1, 0 }, | ||
254 | { NULL, 0, 0, 0, 0, 0 } } | ||
255 | }, | ||
256 | { 0x0010, "Abit NI8 SLI GR", { | ||
257 | { "CPU Core", 0, 0, 10, 1, 0 }, | ||
258 | { "DDR", 1, 0, 10, 1, 0 }, | ||
259 | { "DDR VTT", 2, 0, 10, 1, 0 }, | ||
260 | { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, | ||
261 | { "NB 1.4V", 4, 0, 10, 1, 0 }, | ||
262 | { "SB 1.5V", 6, 0, 10, 1, 0 }, | ||
263 | { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, | ||
264 | { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, | ||
265 | { "ATX +5V", 9, 0, 30, 1, 0 }, | ||
266 | { "+3.3V", 10, 0, 20, 1, 0 }, | ||
267 | { "5VSB", 11, 0, 30, 1, 0 }, | ||
268 | { "CPU", 24, 1, 1, 1, 0 }, | ||
269 | { "SYS", 25, 1, 1, 1, 0 }, | ||
270 | { "PWM", 26, 1, 1, 1, 0 }, | ||
271 | { "CPU Fan", 32, 2, 60, 1, 0 }, | ||
272 | { "NB Fan", 33, 2, 60, 1, 0 }, | ||
273 | { "SYS Fan", 34, 2, 60, 1, 0 }, | ||
274 | { "AUX1 Fan", 35, 2, 60, 1, 0 }, | ||
275 | { "OTES1 Fan", 36, 2, 60, 1, 0 }, | ||
276 | { NULL, 0, 0, 0, 0, 0 } } | ||
277 | }, | ||
278 | { 0x0011, "Abit AT8 32X", { | ||
279 | { "CPU Core", 0, 0, 10, 1, 0 }, | ||
280 | { "DDR", 1, 0, 20, 1, 0 }, | ||
281 | { "DDR VTT", 2, 0, 10, 1, 0 }, | ||
282 | { "CPU VDDA 2.5V", 6, 0, 20, 1, 0 }, | ||
283 | { "NB 1.8V", 4, 0, 10, 1, 0 }, | ||
284 | { "NB 1.8V Dual", 5, 0, 10, 1, 0 }, | ||
285 | { "HTV 1.2", 3, 0, 10, 1, 0 }, | ||
286 | { "PCIE 1.2V", 12, 0, 10, 1, 0 }, | ||
287 | { "NB 1.2V", 13, 0, 10, 1, 0 }, | ||
288 | { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, | ||
289 | { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, | ||
290 | { "ATX +5V", 9, 0, 30, 1, 0 }, | ||
291 | { "+3.3V", 10, 0, 20, 1, 0 }, | ||
292 | { "5VSB", 11, 0, 30, 1, 0 }, | ||
293 | { "CPU", 24, 1, 1, 1, 0 }, | ||
294 | { "NB", 25, 1, 1, 1, 0 }, | ||
295 | { "System", 26, 1, 1, 1, 0 }, | ||
296 | { "PWM", 27, 1, 1, 1, 0 }, | ||
297 | { "CPU Fan", 32, 2, 60, 1, 0 }, | ||
298 | { "NB Fan", 33, 2, 60, 1, 0 }, | ||
299 | { "SYS Fan", 34, 2, 60, 1, 0 }, | ||
300 | { "AUX1 Fan", 35, 2, 60, 1, 0 }, | ||
301 | { "AUX2 Fan", 36, 2, 60, 1, 0 }, | ||
302 | { NULL, 0, 0, 0, 0, 0 } } | ||
303 | }, | ||
304 | { 0x0012, "Abit AN8 32X", { | ||
305 | { "CPU Core", 0, 0, 10, 1, 0 }, | ||
306 | { "DDR", 1, 0, 20, 1, 0 }, | ||
307 | { "DDR VTT", 2, 0, 10, 1, 0 }, | ||
308 | { "HyperTransport", 3, 0, 10, 1, 0 }, | ||
309 | { "CPU VDDA 2.5V", 5, 0, 20, 1, 0 }, | ||
310 | { "NB", 4, 0, 10, 1, 0 }, | ||
311 | { "SB", 6, 0, 10, 1, 0 }, | ||
312 | { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, | ||
313 | { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, | ||
314 | { "ATX +5V", 9, 0, 30, 1, 0 }, | ||
315 | { "+3.3V", 10, 0, 20, 1, 0 }, | ||
316 | { "5VSB", 11, 0, 30, 1, 0 }, | ||
317 | { "CPU", 24, 1, 1, 1, 0 }, | ||
318 | { "SYS", 25, 1, 1, 1, 0 }, | ||
319 | { "PWM", 26, 1, 1, 1, 0 }, | ||
320 | { "CPU Fan", 32, 2, 60, 1, 0 }, | ||
321 | { "NB Fan", 33, 2, 60, 1, 0 }, | ||
322 | { "SYS Fan", 34, 2, 60, 1, 0 }, | ||
323 | { "AUX1 Fan", 36, 2, 60, 1, 0 }, | ||
324 | { NULL, 0, 0, 0, 0, 0 } } | ||
325 | }, | ||
326 | { 0x0013, "unknown", { | ||
327 | { "CPU Core", 0, 0, 10, 1, 0 }, | ||
328 | { "DDR", 1, 0, 10, 1, 0 }, | ||
329 | { "DDR VTT", 2, 0, 10, 1, 0 }, | ||
330 | { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, | ||
331 | { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 }, | ||
332 | { "MCH 2.5V", 5, 0, 20, 1, 0 }, | ||
333 | { "ICH 1.05V", 6, 0, 10, 1, 0 }, | ||
334 | { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, | ||
335 | { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, | ||
336 | { "ATX +5V", 9, 0, 30, 1, 0 }, | ||
337 | { "+3.3V", 10, 0, 20, 1, 0 }, | ||
338 | { "5VSB", 11, 0, 30, 1, 0 }, | ||
339 | { "CPU", 24, 1, 1, 1, 0 }, | ||
340 | { "System ", 25, 1, 1, 1, 0 }, | ||
341 | { "PWM1", 26, 1, 1, 1, 0 }, | ||
342 | { "PWM2", 27, 1, 1, 1, 0 }, | ||
343 | { "PWM3", 28, 1, 1, 1, 0 }, | ||
344 | { "PWM4", 29, 1, 1, 1, 0 }, | ||
345 | { "CPU Fan", 32, 2, 60, 1, 0 }, | ||
346 | { "NB Fan", 33, 2, 60, 1, 0 }, | ||
347 | { "SYS Fan", 34, 2, 60, 1, 0 }, | ||
348 | { "AUX1 Fan", 35, 2, 60, 1, 0 }, | ||
349 | { "AUX2 Fan", 36, 2, 60, 1, 0 }, | ||
350 | { "AUX3 Fan", 37, 2, 60, 1, 0 }, | ||
351 | { "AUX4 Fan", 38, 2, 60, 1, 0 }, | ||
352 | { NULL, 0, 0, 0, 0, 0 } } | ||
353 | }, | ||
354 | { 0x0014, "Abit AB9 Pro", { | ||
355 | { "CPU Core", 0, 0, 10, 1, 0 }, | ||
356 | { "DDR", 1, 0, 10, 1, 0 }, | ||
357 | { "DDR VTT", 2, 0, 10, 1, 0 }, | ||
358 | { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, | ||
359 | { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 }, | ||
360 | { "MCH 2.5V", 5, 0, 20, 1, 0 }, | ||
361 | { "ICH 1.05V", 6, 0, 10, 1, 0 }, | ||
362 | { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, | ||
363 | { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, | ||
364 | { "ATX +5V", 9, 0, 30, 1, 0 }, | ||
365 | { "+3.3V", 10, 0, 20, 1, 0 }, | ||
366 | { "5VSB", 11, 0, 30, 1, 0 }, | ||
367 | { "CPU", 24, 1, 1, 1, 0 }, | ||
368 | { "System ", 25, 1, 1, 1, 0 }, | ||
369 | { "PWM", 26, 1, 1, 1, 0 }, | ||
370 | { "CPU Fan", 32, 2, 60, 1, 0 }, | ||
371 | { "NB Fan", 33, 2, 60, 1, 0 }, | ||
372 | { "SYS Fan", 34, 2, 60, 1, 0 }, | ||
373 | { NULL, 0, 0, 0, 0, 0 } } | ||
374 | }, | ||
375 | { 0x0015, "unknown", { | ||
376 | { "CPU Core", 0, 0, 10, 1, 0 }, | ||
377 | { "DDR", 1, 0, 20, 1, 0 }, | ||
378 | { "DDR VTT", 2, 0, 10, 1, 0 }, | ||
379 | { "HyperTransport", 3, 0, 10, 1, 0 }, | ||
380 | { "CPU VDDA 2.5V", 5, 0, 20, 1, 0 }, | ||
381 | { "NB", 4, 0, 10, 1, 0 }, | ||
382 | { "SB", 6, 0, 10, 1, 0 }, | ||
383 | { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, | ||
384 | { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, | ||
385 | { "ATX +5V", 9, 0, 30, 1, 0 }, | ||
386 | { "+3.3V", 10, 0, 20, 1, 0 }, | ||
387 | { "5VSB", 11, 0, 30, 1, 0 }, | ||
388 | { "CPU", 24, 1, 1, 1, 0 }, | ||
389 | { "SYS", 25, 1, 1, 1, 0 }, | ||
390 | { "PWM", 26, 1, 1, 1, 0 }, | ||
391 | { "CPU Fan", 32, 2, 60, 1, 0 }, | ||
392 | { "NB Fan", 33, 2, 60, 1, 0 }, | ||
393 | { "SYS Fan", 34, 2, 60, 1, 0 }, | ||
394 | { "AUX1 Fan", 33, 2, 60, 1, 0 }, | ||
395 | { "AUX2 Fan", 35, 2, 60, 1, 0 }, | ||
396 | { "AUX3 Fan", 36, 2, 60, 1, 0 }, | ||
397 | { NULL, 0, 0, 0, 0, 0 } } | ||
398 | }, | ||
399 | { 0x0016, "AW9D-MAX", { | ||
400 | { "CPU Core", 0, 0, 10, 1, 0 }, | ||
401 | { "DDR2", 1, 0, 20, 1, 0 }, | ||
402 | { "DDR2 VTT", 2, 0, 10, 1, 0 }, | ||
403 | { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, | ||
404 | { "MCH & PCIE 1.5V", 4, 0, 10, 1, 0 }, | ||
405 | { "MCH 2.5V", 5, 0, 20, 1, 0 }, | ||
406 | { "ICH 1.05V", 6, 0, 10, 1, 0 }, | ||
407 | { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, | ||
408 | { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, | ||
409 | { "ATX +5V", 9, 0, 30, 1, 0 }, | ||
410 | { "+3.3V", 10, 0, 20, 1, 0 }, | ||
411 | { "5VSB", 11, 0, 30, 1, 0 }, | ||
412 | { "CPU", 24, 1, 1, 1, 0 }, | ||
413 | { "System ", 25, 1, 1, 1, 0 }, | ||
414 | { "PWM1", 26, 1, 1, 1, 0 }, | ||
415 | { "PWM2", 27, 1, 1, 1, 0 }, | ||
416 | { "PWM3", 28, 1, 1, 1, 0 }, | ||
417 | { "PWM4", 29, 1, 1, 1, 0 }, | ||
418 | { "CPU Fan", 32, 2, 60, 1, 0 }, | ||
419 | { "NB Fan", 33, 2, 60, 1, 0 }, | ||
420 | { "SYS Fan", 34, 2, 60, 1, 0 }, | ||
421 | { "AUX1 Fan", 35, 2, 60, 1, 0 }, | ||
422 | { "AUX2 Fan", 36, 2, 60, 1, 0 }, | ||
423 | { "AUX3 Fan", 37, 2, 60, 1, 0 }, | ||
424 | { "OTES1 Fan", 38, 2, 60, 1, 0 }, | ||
425 | { NULL, 0, 0, 0, 0, 0 } } | ||
426 | }, | ||
427 | { 0x0017, "unknown", { | ||
428 | { "CPU Core", 0, 0, 10, 1, 0 }, | ||
429 | { "DDR2", 1, 0, 20, 1, 0 }, | ||
430 | { "DDR2 VTT", 2, 0, 10, 1, 0 }, | ||
431 | { "HyperTransport", 3, 0, 10, 1, 0 }, | ||
432 | { "CPU VDDA 2.5V", 6, 0, 20, 1, 0 }, | ||
433 | { "NB 1.8V", 4, 0, 10, 1, 0 }, | ||
434 | { "NB 1.2V ", 13, 0, 10, 1, 0 }, | ||
435 | { "SB 1.2V", 5, 0, 10, 1, 0 }, | ||
436 | { "PCIE 1.2V", 12, 0, 10, 1, 0 }, | ||
437 | { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, | ||
438 | { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, | ||
439 | { "ATX +5V", 9, 0, 30, 1, 0 }, | ||
440 | { "ATX +3.3V", 10, 0, 20, 1, 0 }, | ||
441 | { "ATX 5VSB", 11, 0, 30, 1, 0 }, | ||
442 | { "CPU", 24, 1, 1, 1, 0 }, | ||
443 | { "System ", 26, 1, 1, 1, 0 }, | ||
444 | { "PWM", 27, 1, 1, 1, 0 }, | ||
445 | { "CPU FAN", 32, 2, 60, 1, 0 }, | ||
446 | { "SYS FAN", 34, 2, 60, 1, 0 }, | ||
447 | { "AUX1 FAN", 35, 2, 60, 1, 0 }, | ||
448 | { "AUX2 FAN", 36, 2, 60, 1, 0 }, | ||
449 | { "AUX3 FAN", 37, 2, 60, 1, 0 }, | ||
450 | { NULL, 0, 0, 0, 0, 0 } } | ||
451 | }, | ||
452 | { 0x0018, "unknown", { | ||
453 | { "CPU Core", 0, 0, 10, 1, 0 }, | ||
454 | { "DDR2", 1, 0, 20, 1, 0 }, | ||
455 | { "DDR2 VTT", 2, 0, 10, 1, 0 }, | ||
456 | { "CPU VTT", 3, 0, 10, 1, 0 }, | ||
457 | { "MCH 1.25V", 4, 0, 10, 1, 0 }, | ||
458 | { "ICHIO 1.5V", 5, 0, 10, 1, 0 }, | ||
459 | { "ICH 1.05V", 6, 0, 10, 1, 0 }, | ||
460 | { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, | ||
461 | { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, | ||
462 | { "ATX +5V", 9, 0, 30, 1, 0 }, | ||
463 | { "+3.3V", 10, 0, 20, 1, 0 }, | ||
464 | { "5VSB", 11, 0, 30, 1, 0 }, | ||
465 | { "CPU", 24, 1, 1, 1, 0 }, | ||
466 | { "System ", 25, 1, 1, 1, 0 }, | ||
467 | { "PWM Phase1", 26, 1, 1, 1, 0 }, | ||
468 | { "PWM Phase2", 27, 1, 1, 1, 0 }, | ||
469 | { "PWM Phase3", 28, 1, 1, 1, 0 }, | ||
470 | { "PWM Phase4", 29, 1, 1, 1, 0 }, | ||
471 | { "PWM Phase5", 30, 1, 1, 1, 0 }, | ||
472 | { "CPU Fan", 32, 2, 60, 1, 0 }, | ||
473 | { "SYS Fan", 34, 2, 60, 1, 0 }, | ||
474 | { "AUX1 Fan", 33, 2, 60, 1, 0 }, | ||
475 | { "AUX2 Fan", 35, 2, 60, 1, 0 }, | ||
476 | { "AUX3 Fan", 36, 2, 60, 1, 0 }, | ||
477 | { NULL, 0, 0, 0, 0, 0 } } | ||
478 | }, | ||
479 | { 0x0019, "unknown", { | ||
480 | { "CPU Core", 7, 0, 10, 1, 0 }, | ||
481 | { "DDR2", 13, 0, 20, 1, 0 }, | ||
482 | { "DDR2 VTT", 14, 0, 10, 1, 0 }, | ||
483 | { "CPU VTT", 3, 0, 20, 1, 0 }, | ||
484 | { "NB 1.2V ", 4, 0, 10, 1, 0 }, | ||
485 | { "SB 1.5V", 6, 0, 10, 1, 0 }, | ||
486 | { "HyperTransport", 5, 0, 10, 1, 0 }, | ||
487 | { "ATX +12V (24-Pin)", 12, 0, 60, 1, 0 }, | ||
488 | { "ATX +12V (4-pin)", 8, 0, 60, 1, 0 }, | ||
489 | { "ATX +5V", 9, 0, 30, 1, 0 }, | ||
490 | { "ATX +3.3V", 10, 0, 20, 1, 0 }, | ||
491 | { "ATX 5VSB", 11, 0, 30, 1, 0 }, | ||
492 | { "CPU", 24, 1, 1, 1, 0 }, | ||
493 | { "System ", 25, 1, 1, 1, 0 }, | ||
494 | { "PWM Phase1", 26, 1, 1, 1, 0 }, | ||
495 | { "PWM Phase2", 27, 1, 1, 1, 0 }, | ||
496 | { "PWM Phase3", 28, 1, 1, 1, 0 }, | ||
497 | { "PWM Phase4", 29, 1, 1, 1, 0 }, | ||
498 | { "PWM Phase5", 30, 1, 1, 1, 0 }, | ||
499 | { "CPU FAN", 32, 2, 60, 1, 0 }, | ||
500 | { "SYS FAN", 34, 2, 60, 1, 0 }, | ||
501 | { "AUX1 FAN", 33, 2, 60, 1, 0 }, | ||
502 | { "AUX2 FAN", 35, 2, 60, 1, 0 }, | ||
503 | { "AUX3 FAN", 36, 2, 60, 1, 0 }, | ||
504 | { NULL, 0, 0, 0, 0, 0 } } | ||
505 | }, | ||
506 | { 0x001A, "unknown", { | ||
507 | { "CPU Core", 0, 0, 10, 1, 0 }, | ||
508 | { "DDR2", 1, 0, 20, 1, 0 }, | ||
509 | { "DDR2 VTT", 2, 0, 10, 1, 0 }, | ||
510 | { "CPU VTT 1.2V", 3, 0, 10, 1, 0 }, | ||
511 | { "MCH 1.25V", 4, 0, 10, 1, 0 }, | ||
512 | { "ICHIO 1.5V", 5, 0, 10, 1, 0 }, | ||
513 | { "ICH 1.05V", 6, 0, 10, 1, 0 }, | ||
514 | { "ATX +12V (24-Pin)", 7, 0, 60, 1, 0 }, | ||
515 | { "ATX +12V (8-pin)", 8, 0, 60, 1, 0 }, | ||
516 | { "ATX +5V", 9, 0, 30, 1, 0 }, | ||
517 | { "+3.3V", 10, 0, 20, 1, 0 }, | ||
518 | { "5VSB", 11, 0, 30, 1, 0 }, | ||
519 | { "CPU", 24, 1, 1, 1, 0 }, | ||
520 | { "System ", 25, 1, 1, 1, 0 }, | ||
521 | { "PWM ", 26, 1, 1, 1, 0 }, | ||
522 | { "PWM Phase2", 27, 1, 1, 1, 0 }, | ||
523 | { "PWM Phase3", 28, 1, 1, 1, 0 }, | ||
524 | { "PWM Phase4", 29, 1, 1, 1, 0 }, | ||
525 | { "PWM Phase5", 30, 1, 1, 1, 0 }, | ||
526 | { "CPU Fan", 32, 2, 60, 1, 0 }, | ||
527 | { "SYS Fan", 34, 2, 60, 1, 0 }, | ||
528 | { "AUX1 Fan", 33, 2, 60, 1, 0 }, | ||
529 | { "AUX2 Fan", 35, 2, 60, 1, 0 }, | ||
530 | { "AUX3 Fan", 36, 2, 60, 1, 0 }, | ||
531 | { NULL, 0, 0, 0, 0, 0 } } | ||
532 | }, | ||
533 | { 0x0000, NULL, { { NULL, 0, 0, 0, 0, 0 } } } | ||
534 | }; | ||
535 | |||
536 | |||
537 | /* Insmod parameters */ | ||
538 | static int force; | ||
539 | module_param(force, bool, 0); | ||
540 | MODULE_PARM_DESC(force, "Set to one to force detection."); | ||
541 | /* Default verbose is 1, since this driver is still in the testing phase */ | ||
542 | static int verbose = 1; | ||
543 | module_param(verbose, bool, 0644); | ||
544 | MODULE_PARM_DESC(verbose, "Enable/disable verbose error reporting"); | ||
545 | |||
546 | |||
547 | /* wait while the uguru is busy (usually after a write) */ | ||
548 | static int abituguru3_wait_while_busy(struct abituguru3_data *data) | ||
549 | { | ||
550 | u8 x; | ||
551 | int timeout = ABIT_UGURU3_WAIT_TIMEOUT; | ||
552 | |||
553 | while ((x = inb_p(data->addr + ABIT_UGURU3_DATA)) & | ||
554 | ABIT_UGURU3_STATUS_BUSY) { | ||
555 | timeout--; | ||
556 | if (timeout == 0) | ||
557 | return x; | ||
558 | /* sleep a bit before our last try, to give the uGuru3 one | ||
559 | last chance to respond. */ | ||
560 | if (timeout == 1) | ||
561 | msleep(1); | ||
562 | } | ||
563 | return ABIT_UGURU3_SUCCESS; | ||
564 | } | ||
565 | |||
566 | /* wait till uguru is ready to be read */ | ||
567 | static int abituguru3_wait_for_read(struct abituguru3_data *data) | ||
568 | { | ||
569 | u8 x; | ||
570 | int timeout = ABIT_UGURU3_WAIT_TIMEOUT; | ||
571 | |||
572 | while (!((x = inb_p(data->addr + ABIT_UGURU3_DATA)) & | ||
573 | ABIT_UGURU3_STATUS_READY_FOR_READ)) { | ||
574 | timeout--; | ||
575 | if (timeout == 0) | ||
576 | return x; | ||
577 | /* sleep a bit before our last try, to give the uGuru3 one | ||
578 | last chance to respond. */ | ||
579 | if (timeout == 1) | ||
580 | msleep(1); | ||
581 | } | ||
582 | return ABIT_UGURU3_SUCCESS; | ||
583 | } | ||
584 | |||
585 | /* This synchronizes us with the uGuru3's protocol state machine, this | ||
586 | must be done before each command. */ | ||
587 | static int abituguru3_synchronize(struct abituguru3_data *data) | ||
588 | { | ||
589 | int x, timeout = ABIT_UGURU3_SYNCHRONIZE_TIMEOUT; | ||
590 | |||
591 | if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { | ||
592 | ABIT_UGURU3_DEBUG("synchronize timeout during initial busy " | ||
593 | "wait, status: 0x%02x\n", x); | ||
594 | return -EIO; | ||
595 | } | ||
596 | |||
597 | outb(0x20, data->addr + ABIT_UGURU3_DATA); | ||
598 | if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { | ||
599 | ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x20, " | ||
600 | "status: 0x%02x\n", x); | ||
601 | return -EIO; | ||
602 | } | ||
603 | |||
604 | outb(0x10, data->addr + ABIT_UGURU3_CMD); | ||
605 | if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { | ||
606 | ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x10, " | ||
607 | "status: 0x%02x\n", x); | ||
608 | return -EIO; | ||
609 | } | ||
610 | |||
611 | outb(0x00, data->addr + ABIT_UGURU3_CMD); | ||
612 | if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { | ||
613 | ABIT_UGURU3_DEBUG("synchronize timeout after sending 0x00, " | ||
614 | "status: 0x%02x\n", x); | ||
615 | return -EIO; | ||
616 | } | ||
617 | |||
618 | if ((x = abituguru3_wait_for_read(data)) != ABIT_UGURU3_SUCCESS) { | ||
619 | ABIT_UGURU3_DEBUG("synchronize timeout waiting for read, " | ||
620 | "status: 0x%02x\n", x); | ||
621 | return -EIO; | ||
622 | } | ||
623 | |||
624 | while ((x = inb(data->addr + ABIT_UGURU3_CMD)) != 0xAC) { | ||
625 | timeout--; | ||
626 | if (timeout == 0) { | ||
627 | ABIT_UGURU3_DEBUG("synchronize timeout cmd does not " | ||
628 | "hold 0xAC after synchronize, cmd: 0x%02x\n", | ||
629 | x); | ||
630 | return -EIO; | ||
631 | } | ||
632 | msleep(1); | ||
633 | } | ||
634 | return 0; | ||
635 | } | ||
636 | |||
637 | /* Read count bytes from sensor sensor_addr in bank bank_addr and store the | ||
638 | result in buf */ | ||
639 | static int abituguru3_read(struct abituguru3_data *data, u8 bank, u8 offset, | ||
640 | u8 count, u8 *buf) | ||
641 | { | ||
642 | int i, x; | ||
643 | |||
644 | if ((x = abituguru3_synchronize(data))) | ||
645 | return x; | ||
646 | |||
647 | outb(0x1A, data->addr + ABIT_UGURU3_DATA); | ||
648 | if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { | ||
649 | ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after " | ||
650 | "sending 0x1A, status: 0x%02x\n", (unsigned int)bank, | ||
651 | (unsigned int)offset, x); | ||
652 | return -EIO; | ||
653 | } | ||
654 | |||
655 | outb(bank, data->addr + ABIT_UGURU3_CMD); | ||
656 | if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { | ||
657 | ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after " | ||
658 | "sending the bank, status: 0x%02x\n", | ||
659 | (unsigned int)bank, (unsigned int)offset, x); | ||
660 | return -EIO; | ||
661 | } | ||
662 | |||
663 | outb(offset, data->addr + ABIT_UGURU3_CMD); | ||
664 | if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { | ||
665 | ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after " | ||
666 | "sending the offset, status: 0x%02x\n", | ||
667 | (unsigned int)bank, (unsigned int)offset, x); | ||
668 | return -EIO; | ||
669 | } | ||
670 | |||
671 | outb(count, data->addr + ABIT_UGURU3_CMD); | ||
672 | if ((x = abituguru3_wait_while_busy(data)) != ABIT_UGURU3_SUCCESS) { | ||
673 | ABIT_UGURU3_DEBUG("read from 0x%02x:0x%02x timed out after " | ||
674 | "sending the count, status: 0x%02x\n", | ||
675 | (unsigned int)bank, (unsigned int)offset, x); | ||
676 | return -EIO; | ||
677 | } | ||
678 | |||
679 | for (i = 0; i < count; i++) { | ||
680 | if ((x = abituguru3_wait_for_read(data)) != | ||
681 | ABIT_UGURU3_SUCCESS) { | ||
682 | ABIT_UGURU3_DEBUG("timeout reading byte %d from " | ||
683 | "0x%02x:0x%02x, status: 0x%02x\n", i, | ||
684 | (unsigned int)bank, (unsigned int)offset, x); | ||
685 | break; | ||
686 | } | ||
687 | buf[i] = inb(data->addr + ABIT_UGURU3_CMD); | ||
688 | } | ||
689 | return i; | ||
690 | } | ||
691 | |||
692 | /* Sensor settings are stored 1 byte per offset with the bytes | ||
693 | placed add consecutive offsets. */ | ||
694 | int abituguru3_read_increment_offset(struct abituguru3_data *data, u8 bank, | ||
695 | u8 offset, u8 count, u8 *buf, int offset_count) | ||
696 | { | ||
697 | int i, x; | ||
698 | |||
699 | for (i = 0; i < offset_count; i++) | ||
700 | if ((x = abituguru3_read(data, bank, offset + i, count, | ||
701 | buf + i * count)) != count) | ||
702 | return i * count + (i && (x < 0)) ? 0 : x; | ||
703 | |||
704 | return i * count; | ||
705 | } | ||
706 | |||
707 | /* Following are the sysfs callback functions. These functions expect: | ||
708 | sensor_device_attribute_2->index: index into the data->sensors array | ||
709 | sensor_device_attribute_2->nr: register offset, bitmask or NA. */ | ||
710 | static struct abituguru3_data *abituguru3_update_device(struct device *dev); | ||
711 | |||
712 | static ssize_t show_value(struct device *dev, | ||
713 | struct device_attribute *devattr, char *buf) | ||
714 | { | ||
715 | int value; | ||
716 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); | ||
717 | struct abituguru3_data *data = abituguru3_update_device(dev); | ||
718 | const struct abituguru3_sensor_info *sensor; | ||
719 | |||
720 | if (!data) | ||
721 | return -EIO; | ||
722 | |||
723 | sensor = &data->sensors[attr->index]; | ||
724 | |||
725 | /* are we reading a setting, or is this a normal read? */ | ||
726 | if (attr->nr) | ||
727 | value = data->settings[sensor->port][attr->nr]; | ||
728 | else | ||
729 | value = data->value[sensor->port]; | ||
730 | |||
731 | /* convert the value */ | ||
732 | value = (value * sensor->multiplier) / sensor->divisor + | ||
733 | sensor->offset; | ||
734 | |||
735 | /* alternatively we could update the sensors settings struct for this, | ||
736 | but then its contents would differ from the windows sw ini files */ | ||
737 | if (sensor->type == ABIT_UGURU3_TEMP_SENSOR) | ||
738 | value *= 1000; | ||
739 | |||
740 | return sprintf(buf, "%d\n", value); | ||
741 | } | ||
742 | |||
743 | static ssize_t show_alarm(struct device *dev, | ||
744 | struct device_attribute *devattr, char *buf) | ||
745 | { | ||
746 | int port; | ||
747 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); | ||
748 | struct abituguru3_data *data = abituguru3_update_device(dev); | ||
749 | |||
750 | if (!data) | ||
751 | return -EIO; | ||
752 | |||
753 | port = data->sensors[attr->index].port; | ||
754 | |||
755 | /* See if the alarm bit for this sensor is set and if a bitmask is | ||
756 | given in attr->nr also check if the alarm matches the type of alarm | ||
757 | we're looking for (for volt it can be either low or high). The type | ||
758 | is stored in a few readonly bits in the settings of the sensor. */ | ||
759 | if ((data->alarms[port / 8] & (0x01 << (port % 8))) && | ||
760 | (!attr->nr || (data->settings[port][0] & attr->nr))) | ||
761 | return sprintf(buf, "1\n"); | ||
762 | else | ||
763 | return sprintf(buf, "0\n"); | ||
764 | } | ||
765 | |||
766 | static ssize_t show_mask(struct device *dev, | ||
767 | struct device_attribute *devattr, char *buf) | ||
768 | { | ||
769 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); | ||
770 | struct abituguru3_data *data = dev_get_drvdata(dev); | ||
771 | |||
772 | if (data->settings[data->sensors[attr->index].port][0] & attr->nr) | ||
773 | return sprintf(buf, "1\n"); | ||
774 | else | ||
775 | return sprintf(buf, "0\n"); | ||
776 | } | ||
777 | |||
778 | static ssize_t show_label(struct device *dev, | ||
779 | struct device_attribute *devattr, char *buf) | ||
780 | { | ||
781 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); | ||
782 | struct abituguru3_data *data = dev_get_drvdata(dev); | ||
783 | |||
784 | return sprintf(buf, "%s\n", data->sensors[attr->index].name); | ||
785 | } | ||
786 | |||
787 | static ssize_t show_name(struct device *dev, | ||
788 | struct device_attribute *devattr, char *buf) | ||
789 | { | ||
790 | return sprintf(buf, "%s\n", ABIT_UGURU3_NAME); | ||
791 | } | ||
792 | |||
793 | /* Sysfs attr templates, the real entries are generated automatically. */ | ||
794 | static const | ||
795 | struct sensor_device_attribute_2 abituguru3_sysfs_templ[3][10] = { { | ||
796 | SENSOR_ATTR_2(in%d_input, 0444, show_value, NULL, 0, 0), | ||
797 | SENSOR_ATTR_2(in%d_min, 0444, show_value, NULL, 1, 0), | ||
798 | SENSOR_ATTR_2(in%d_max, 0444, show_value, NULL, 2, 0), | ||
799 | SENSOR_ATTR_2(in%d_min_alarm, 0444, show_alarm, NULL, | ||
800 | ABIT_UGURU3_VOLT_LOW_ALARM_FLAG, 0), | ||
801 | SENSOR_ATTR_2(in%d_max_alarm, 0444, show_alarm, NULL, | ||
802 | ABIT_UGURU3_VOLT_HIGH_ALARM_FLAG, 0), | ||
803 | SENSOR_ATTR_2(in%d_beep, 0444, show_mask, NULL, | ||
804 | ABIT_UGURU3_BEEP_ENABLE, 0), | ||
805 | SENSOR_ATTR_2(in%d_shutdown, 0444, show_mask, NULL, | ||
806 | ABIT_UGURU3_SHUTDOWN_ENABLE, 0), | ||
807 | SENSOR_ATTR_2(in%d_min_alarm_enable, 0444, show_mask, NULL, | ||
808 | ABIT_UGURU3_VOLT_LOW_ALARM_ENABLE, 0), | ||
809 | SENSOR_ATTR_2(in%d_max_alarm_enable, 0444, show_mask, NULL, | ||
810 | ABIT_UGURU3_VOLT_HIGH_ALARM_ENABLE, 0), | ||
811 | SENSOR_ATTR_2(in%d_label, 0444, show_label, NULL, 0, 0) | ||
812 | }, { | ||
813 | SENSOR_ATTR_2(temp%d_input, 0444, show_value, NULL, 0, 0), | ||
814 | SENSOR_ATTR_2(temp%d_max, 0444, show_value, NULL, 1, 0), | ||
815 | SENSOR_ATTR_2(temp%d_crit, 0444, show_value, NULL, 2, 0), | ||
816 | SENSOR_ATTR_2(temp%d_alarm, 0444, show_alarm, NULL, 0, 0), | ||
817 | SENSOR_ATTR_2(temp%d_beep, 0444, show_mask, NULL, | ||
818 | ABIT_UGURU3_BEEP_ENABLE, 0), | ||
819 | SENSOR_ATTR_2(temp%d_shutdown, 0444, show_mask, NULL, | ||
820 | ABIT_UGURU3_SHUTDOWN_ENABLE, 0), | ||
821 | SENSOR_ATTR_2(temp%d_alarm_enable, 0444, show_mask, NULL, | ||
822 | ABIT_UGURU3_TEMP_HIGH_ALARM_ENABLE, 0), | ||
823 | SENSOR_ATTR_2(temp%d_label, 0444, show_label, NULL, 0, 0) | ||
824 | }, { | ||
825 | SENSOR_ATTR_2(fan%d_input, 0444, show_value, NULL, 0, 0), | ||
826 | SENSOR_ATTR_2(fan%d_min, 0444, show_value, NULL, 1, 0), | ||
827 | SENSOR_ATTR_2(fan%d_alarm, 0444, show_alarm, NULL, 0, 0), | ||
828 | SENSOR_ATTR_2(fan%d_beep, 0444, show_mask, NULL, | ||
829 | ABIT_UGURU3_BEEP_ENABLE, 0), | ||
830 | SENSOR_ATTR_2(fan%d_shutdown, 0444, show_mask, NULL, | ||
831 | ABIT_UGURU3_SHUTDOWN_ENABLE, 0), | ||
832 | SENSOR_ATTR_2(fan%d_alarm_enable, 0444, show_mask, NULL, | ||
833 | ABIT_UGURU3_FAN_LOW_ALARM_ENABLE, 0), | ||
834 | SENSOR_ATTR_2(fan%d_label, 0444, show_label, NULL, 0, 0) | ||
835 | } }; | ||
836 | |||
837 | static struct sensor_device_attribute_2 abituguru3_sysfs_attr[] = { | ||
838 | SENSOR_ATTR_2(name, 0444, show_name, NULL, 0, 0), | ||
839 | }; | ||
840 | |||
841 | static int __devinit abituguru3_probe(struct platform_device *pdev) | ||
842 | { | ||
843 | const int no_sysfs_attr[3] = { 10, 8, 7 }; | ||
844 | int sensor_index[3] = { 0, 1, 1 }; | ||
845 | struct abituguru3_data *data; | ||
846 | int i, j, type, used, sysfs_names_free, sysfs_attr_i, res = -ENODEV; | ||
847 | char *sysfs_filename; | ||
848 | u8 buf[2]; | ||
849 | u16 id; | ||
850 | |||
851 | if (!(data = kzalloc(sizeof(struct abituguru3_data), GFP_KERNEL))) | ||
852 | return -ENOMEM; | ||
853 | |||
854 | data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start; | ||
855 | mutex_init(&data->update_lock); | ||
856 | platform_set_drvdata(pdev, data); | ||
857 | |||
858 | /* Read the motherboard ID */ | ||
859 | if ((i = abituguru3_read(data, ABIT_UGURU3_MISC_BANK, | ||
860 | ABIT_UGURU3_BOARD_ID, 2, buf)) != 2) { | ||
861 | goto abituguru3_probe_error; | ||
862 | } | ||
863 | |||
864 | /* Completely read the uGuru to see if one really is there */ | ||
865 | if (!abituguru3_update_device(&pdev->dev)) | ||
866 | goto abituguru3_probe_error; | ||
867 | |||
868 | /* lookup the ID in our motherboard table */ | ||
869 | id = ((u16)buf[0] << 8) | (u16)buf[1]; | ||
870 | for (i = 0; abituguru3_motherboards[i].id; i++) | ||
871 | if (abituguru3_motherboards[i].id == id) | ||
872 | break; | ||
873 | if (!abituguru3_motherboards[i].id) { | ||
874 | printk(KERN_ERR ABIT_UGURU3_NAME ": error unknown motherboard " | ||
875 | "ID: %04X. Please report this to the abituguru3 " | ||
876 | "maintainer (see MAINTAINERS)\n", (unsigned int)id); | ||
877 | goto abituguru3_probe_error; | ||
878 | } | ||
879 | data->sensors = abituguru3_motherboards[i].sensors; | ||
880 | printk(KERN_INFO ABIT_UGURU3_NAME ": found Abit uGuru3, motherboard " | ||
881 | "ID: %04X (%s)\n", (unsigned int)id, | ||
882 | abituguru3_motherboards[i].name); | ||
883 | |||
884 | /* Fill the sysfs attr array */ | ||
885 | sysfs_attr_i = 0; | ||
886 | sysfs_filename = data->sysfs_names; | ||
887 | sysfs_names_free = ABIT_UGURU3_SYSFS_NAMES_LENGTH; | ||
888 | for (i = 0; data->sensors[i].name; i++) { | ||
889 | /* Fail safe check, this should never happen! */ | ||
890 | if (i >= ABIT_UGURU3_MAX_NO_SENSORS) { | ||
891 | printk(KERN_ERR ABIT_UGURU3_NAME | ||
892 | ": Fatal error motherboard has more sensors " | ||
893 | "then ABIT_UGURU3_MAX_NO_SENSORS. This should " | ||
894 | "never happen please report to the abituguru3 " | ||
895 | "maintainer (see MAINTAINERS)\n"); | ||
896 | res = -ENAMETOOLONG; | ||
897 | goto abituguru3_probe_error; | ||
898 | } | ||
899 | type = data->sensors[i].type; | ||
900 | for (j = 0; j < no_sysfs_attr[type]; j++) { | ||
901 | used = snprintf(sysfs_filename, sysfs_names_free, | ||
902 | abituguru3_sysfs_templ[type][j].dev_attr.attr. | ||
903 | name, sensor_index[type]) + 1; | ||
904 | data->sysfs_attr[sysfs_attr_i] = | ||
905 | abituguru3_sysfs_templ[type][j]; | ||
906 | data->sysfs_attr[sysfs_attr_i].dev_attr.attr.name = | ||
907 | sysfs_filename; | ||
908 | data->sysfs_attr[sysfs_attr_i].index = i; | ||
909 | sysfs_filename += used; | ||
910 | sysfs_names_free -= used; | ||
911 | sysfs_attr_i++; | ||
912 | } | ||
913 | sensor_index[type]++; | ||
914 | } | ||
915 | /* Fail safe check, this should never happen! */ | ||
916 | if (sysfs_names_free < 0) { | ||
917 | printk(KERN_ERR ABIT_UGURU3_NAME | ||
918 | ": Fatal error ran out of space for sysfs attr names. " | ||
919 | "This should never happen please report to the " | ||
920 | "abituguru3 maintainer (see MAINTAINERS)\n"); | ||
921 | res = -ENAMETOOLONG; | ||
922 | goto abituguru3_probe_error; | ||
923 | } | ||
924 | |||
925 | /* Register sysfs hooks */ | ||
926 | for (i = 0; i < sysfs_attr_i; i++) | ||
927 | if (device_create_file(&pdev->dev, | ||
928 | &data->sysfs_attr[i].dev_attr)) | ||
929 | goto abituguru3_probe_error; | ||
930 | for (i = 0; i < ARRAY_SIZE(abituguru3_sysfs_attr); i++) | ||
931 | if (device_create_file(&pdev->dev, | ||
932 | &abituguru3_sysfs_attr[i].dev_attr)) | ||
933 | goto abituguru3_probe_error; | ||
934 | |||
935 | data->class_dev = hwmon_device_register(&pdev->dev); | ||
936 | if (IS_ERR(data->class_dev)) { | ||
937 | res = PTR_ERR(data->class_dev); | ||
938 | goto abituguru3_probe_error; | ||
939 | } | ||
940 | |||
941 | return 0; /* success */ | ||
942 | |||
943 | abituguru3_probe_error: | ||
944 | for (i = 0; data->sysfs_attr[i].dev_attr.attr.name; i++) | ||
945 | device_remove_file(&pdev->dev, &data->sysfs_attr[i].dev_attr); | ||
946 | for (i = 0; i < ARRAY_SIZE(abituguru3_sysfs_attr); i++) | ||
947 | device_remove_file(&pdev->dev, | ||
948 | &abituguru3_sysfs_attr[i].dev_attr); | ||
949 | kfree(data); | ||
950 | return res; | ||
951 | } | ||
952 | |||
953 | static int __devexit abituguru3_remove(struct platform_device *pdev) | ||
954 | { | ||
955 | int i; | ||
956 | struct abituguru3_data *data = platform_get_drvdata(pdev); | ||
957 | |||
958 | platform_set_drvdata(pdev, NULL); | ||
959 | hwmon_device_unregister(data->class_dev); | ||
960 | for (i = 0; data->sysfs_attr[i].dev_attr.attr.name; i++) | ||
961 | device_remove_file(&pdev->dev, &data->sysfs_attr[i].dev_attr); | ||
962 | for (i = 0; i < ARRAY_SIZE(abituguru3_sysfs_attr); i++) | ||
963 | device_remove_file(&pdev->dev, | ||
964 | &abituguru3_sysfs_attr[i].dev_attr); | ||
965 | kfree(data); | ||
966 | |||
967 | return 0; | ||
968 | } | ||
969 | |||
970 | static struct abituguru3_data *abituguru3_update_device(struct device *dev) | ||
971 | { | ||
972 | int i; | ||
973 | struct abituguru3_data *data = dev_get_drvdata(dev); | ||
974 | |||
975 | mutex_lock(&data->update_lock); | ||
976 | if (!data->valid || time_after(jiffies, data->last_updated + HZ)) { | ||
977 | /* Clear data->valid while updating */ | ||
978 | data->valid = 0; | ||
979 | /* Read alarms */ | ||
980 | if (abituguru3_read_increment_offset(data, | ||
981 | ABIT_UGURU3_SETTINGS_BANK, | ||
982 | ABIT_UGURU3_ALARMS_START, | ||
983 | 1, data->alarms, 48/8) != (48/8)) | ||
984 | goto LEAVE_UPDATE; | ||
985 | /* Read in and temp sensors (3 byte settings / sensor) */ | ||
986 | for (i = 0; i < 32; i++) { | ||
987 | if (abituguru3_read(data, ABIT_UGURU3_SENSORS_BANK, | ||
988 | ABIT_UGURU3_VALUES_START + i, | ||
989 | 1, &data->value[i]) != 1) | ||
990 | goto LEAVE_UPDATE; | ||
991 | if (abituguru3_read_increment_offset(data, | ||
992 | ABIT_UGURU3_SETTINGS_BANK, | ||
993 | ABIT_UGURU3_SETTINGS_START + i * 3, | ||
994 | 1, | ||
995 | data->settings[i], 3) != 3) | ||
996 | goto LEAVE_UPDATE; | ||
997 | } | ||
998 | /* Read temp sensors (2 byte settings / sensor) */ | ||
999 | for (i = 0; i < 16; i++) { | ||
1000 | if (abituguru3_read(data, ABIT_UGURU3_SENSORS_BANK, | ||
1001 | ABIT_UGURU3_VALUES_START + 32 + i, | ||
1002 | 1, &data->value[32 + i]) != 1) | ||
1003 | goto LEAVE_UPDATE; | ||
1004 | if (abituguru3_read_increment_offset(data, | ||
1005 | ABIT_UGURU3_SETTINGS_BANK, | ||
1006 | ABIT_UGURU3_SETTINGS_START + 32 * 3 + | ||
1007 | i * 2, 1, | ||
1008 | data->settings[32 + i], 2) != 2) | ||
1009 | goto LEAVE_UPDATE; | ||
1010 | } | ||
1011 | data->last_updated = jiffies; | ||
1012 | data->valid = 1; | ||
1013 | } | ||
1014 | LEAVE_UPDATE: | ||
1015 | mutex_unlock(&data->update_lock); | ||
1016 | if (data->valid) | ||
1017 | return data; | ||
1018 | else | ||
1019 | return NULL; | ||
1020 | } | ||
1021 | |||
1022 | #ifdef CONFIG_PM | ||
1023 | static int abituguru3_suspend(struct platform_device *pdev, pm_message_t state) | ||
1024 | { | ||
1025 | struct abituguru3_data *data = platform_get_drvdata(pdev); | ||
1026 | /* make sure all communications with the uguru3 are done and no new | ||
1027 | ones are started */ | ||
1028 | mutex_lock(&data->update_lock); | ||
1029 | return 0; | ||
1030 | } | ||
1031 | |||
1032 | static int abituguru3_resume(struct platform_device *pdev) | ||
1033 | { | ||
1034 | struct abituguru3_data *data = platform_get_drvdata(pdev); | ||
1035 | mutex_unlock(&data->update_lock); | ||
1036 | return 0; | ||
1037 | } | ||
1038 | #else | ||
1039 | #define abituguru3_suspend NULL | ||
1040 | #define abituguru3_resume NULL | ||
1041 | #endif /* CONFIG_PM */ | ||
1042 | |||
1043 | static struct platform_driver abituguru3_driver = { | ||
1044 | .driver = { | ||
1045 | .owner = THIS_MODULE, | ||
1046 | .name = ABIT_UGURU3_NAME, | ||
1047 | }, | ||
1048 | .probe = abituguru3_probe, | ||
1049 | .remove = __devexit_p(abituguru3_remove), | ||
1050 | .suspend = abituguru3_suspend, | ||
1051 | .resume = abituguru3_resume | ||
1052 | }; | ||
1053 | |||
1054 | static int __init abituguru3_detect(void) | ||
1055 | { | ||
1056 | /* See if there is an uguru3 there. An idle uGuru3 will hold 0x00 or | ||
1057 | 0x08 at DATA and 0xAC at CMD. Sometimes the uGuru3 will hold 0x05 | ||
1058 | at CMD instead, why is unknown. So we test for 0x05 too. */ | ||
1059 | u8 data_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_DATA); | ||
1060 | u8 cmd_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_CMD); | ||
1061 | if (((data_val == 0x00) || (data_val == 0x08)) && | ||
1062 | ((cmd_val == 0xAC) || (cmd_val == 0x05))) | ||
1063 | return ABIT_UGURU3_BASE; | ||
1064 | |||
1065 | ABIT_UGURU3_DEBUG("no Abit uGuru3 found, data = 0x%02X, cmd = " | ||
1066 | "0x%02X\n", (unsigned int)data_val, (unsigned int)cmd_val); | ||
1067 | |||
1068 | if (force) { | ||
1069 | printk(KERN_INFO ABIT_UGURU3_NAME ": Assuming Abit uGuru3 is " | ||
1070 | "present because of \"force\" parameter\n"); | ||
1071 | return ABIT_UGURU3_BASE; | ||
1072 | } | ||
1073 | |||
1074 | /* No uGuru3 found */ | ||
1075 | return -ENODEV; | ||
1076 | } | ||
1077 | |||
1078 | static struct platform_device *abituguru3_pdev; | ||
1079 | |||
1080 | static int __init abituguru3_init(void) | ||
1081 | { | ||
1082 | int address, err; | ||
1083 | struct resource res = { .flags = IORESOURCE_IO }; | ||
1084 | |||
1085 | address = abituguru3_detect(); | ||
1086 | if (address < 0) | ||
1087 | return address; | ||
1088 | |||
1089 | err = platform_driver_register(&abituguru3_driver); | ||
1090 | if (err) | ||
1091 | goto exit; | ||
1092 | |||
1093 | abituguru3_pdev = platform_device_alloc(ABIT_UGURU3_NAME, address); | ||
1094 | if (!abituguru3_pdev) { | ||
1095 | printk(KERN_ERR ABIT_UGURU3_NAME | ||
1096 | ": Device allocation failed\n"); | ||
1097 | err = -ENOMEM; | ||
1098 | goto exit_driver_unregister; | ||
1099 | } | ||
1100 | |||
1101 | res.start = address; | ||
1102 | res.end = address + ABIT_UGURU3_REGION_LENGTH - 1; | ||
1103 | res.name = ABIT_UGURU3_NAME; | ||
1104 | |||
1105 | err = platform_device_add_resources(abituguru3_pdev, &res, 1); | ||
1106 | if (err) { | ||
1107 | printk(KERN_ERR ABIT_UGURU3_NAME | ||
1108 | ": Device resource addition failed (%d)\n", err); | ||
1109 | goto exit_device_put; | ||
1110 | } | ||
1111 | |||
1112 | err = platform_device_add(abituguru3_pdev); | ||
1113 | if (err) { | ||
1114 | printk(KERN_ERR ABIT_UGURU3_NAME | ||
1115 | ": Device addition failed (%d)\n", err); | ||
1116 | goto exit_device_put; | ||
1117 | } | ||
1118 | |||
1119 | return 0; | ||
1120 | |||
1121 | exit_device_put: | ||
1122 | platform_device_put(abituguru3_pdev); | ||
1123 | exit_driver_unregister: | ||
1124 | platform_driver_unregister(&abituguru3_driver); | ||
1125 | exit: | ||
1126 | return err; | ||
1127 | } | ||
1128 | |||
1129 | static void __exit abituguru3_exit(void) | ||
1130 | { | ||
1131 | platform_device_unregister(abituguru3_pdev); | ||
1132 | platform_driver_unregister(&abituguru3_driver); | ||
1133 | } | ||
1134 | |||
1135 | MODULE_AUTHOR("Hans de Goede <j.w.r.degoede@hhs.nl>"); | ||
1136 | MODULE_DESCRIPTION("Abit uGuru3 Sensor device"); | ||
1137 | MODULE_LICENSE("GPL"); | ||
1138 | |||
1139 | module_init(abituguru3_init); | ||
1140 | module_exit(abituguru3_exit); | ||
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index 6d54c8caed79..7c1795225b06 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c | |||
@@ -318,7 +318,7 @@ exit: | |||
318 | } | 318 | } |
319 | 319 | ||
320 | #ifdef CONFIG_HOTPLUG_CPU | 320 | #ifdef CONFIG_HOTPLUG_CPU |
321 | void coretemp_device_remove(unsigned int cpu) | 321 | static void coretemp_device_remove(unsigned int cpu) |
322 | { | 322 | { |
323 | struct pdev_entry *p, *n; | 323 | struct pdev_entry *p, *n; |
324 | mutex_lock(&pdev_list_mutex); | 324 | mutex_lock(&pdev_list_mutex); |
diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c new file mode 100644 index 000000000000..be3aaa5d0b91 --- /dev/null +++ b/drivers/hwmon/dme1737.c | |||
@@ -0,0 +1,2080 @@ | |||
1 | /* | ||
2 | * dme1737.c - driver for the SMSC DME1737 and Asus A8000 Super-I/O chips | ||
3 | * integrated hardware monitoring features. | ||
4 | * Copyright (c) 2007 Juerg Haefliger <juergh@gmail.com> | ||
5 | * | ||
6 | * This driver is based on the LM85 driver. The hardware monitoring | ||
7 | * capabilities of the DME1737 are very similar to the LM85 with some | ||
8 | * additional features. Even though the DME1737 is a Super-I/O chip, the | ||
9 | * hardware monitoring registers are only accessible via SMBus. | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License as published by | ||
13 | * the Free Software Foundation; either version 2 of the License, or | ||
14 | * (at your option) any later version. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 | * GNU General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU General Public License | ||
22 | * along with this program; if not, write to the Free Software | ||
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
24 | */ | ||
25 | |||
26 | #include <linux/module.h> | ||
27 | #include <linux/init.h> | ||
28 | #include <linux/slab.h> | ||
29 | #include <linux/jiffies.h> | ||
30 | #include <linux/i2c.h> | ||
31 | #include <linux/hwmon.h> | ||
32 | #include <linux/hwmon-sysfs.h> | ||
33 | #include <linux/hwmon-vid.h> | ||
34 | #include <linux/err.h> | ||
35 | #include <linux/mutex.h> | ||
36 | #include <asm/io.h> | ||
37 | |||
38 | /* Module load parameters */ | ||
39 | static int force_start; | ||
40 | module_param(force_start, bool, 0); | ||
41 | MODULE_PARM_DESC(force_start, "Force the chip to start monitoring inputs"); | ||
42 | |||
43 | /* Addresses to scan */ | ||
44 | static unsigned short normal_i2c[] = {0x2c, 0x2d, 0x2e, I2C_CLIENT_END}; | ||
45 | |||
46 | /* Insmod parameters */ | ||
47 | I2C_CLIENT_INSMOD_1(dme1737); | ||
48 | |||
49 | /* --------------------------------------------------------------------- | ||
50 | * Registers | ||
51 | * | ||
52 | * The sensors are defined as follows: | ||
53 | * | ||
54 | * Voltages Temperatures | ||
55 | * -------- ------------ | ||
56 | * in0 +5VTR (+5V stdby) temp1 Remote diode 1 | ||
57 | * in1 Vccp (proc core) temp2 Internal temp | ||
58 | * in2 VCC (internal +3.3V) temp3 Remote diode 2 | ||
59 | * in3 +5V | ||
60 | * in4 +12V | ||
61 | * in5 VTR (+3.3V stby) | ||
62 | * in6 Vbat | ||
63 | * | ||
64 | * --------------------------------------------------------------------- */ | ||
65 | |||
66 | /* Voltages (in) numbered 0-6 (ix) */ | ||
67 | #define DME1737_REG_IN(ix) ((ix) < 5 ? 0x20 + (ix) \ | ||
68 | : 0x94 + (ix)) | ||
69 | #define DME1737_REG_IN_MIN(ix) ((ix) < 5 ? 0x44 + (ix) * 2 \ | ||
70 | : 0x91 + (ix) * 2) | ||
71 | #define DME1737_REG_IN_MAX(ix) ((ix) < 5 ? 0x45 + (ix) * 2 \ | ||
72 | : 0x92 + (ix) * 2) | ||
73 | |||
74 | /* Temperatures (temp) numbered 0-2 (ix) */ | ||
75 | #define DME1737_REG_TEMP(ix) (0x25 + (ix)) | ||
76 | #define DME1737_REG_TEMP_MIN(ix) (0x4e + (ix) * 2) | ||
77 | #define DME1737_REG_TEMP_MAX(ix) (0x4f + (ix) * 2) | ||
78 | #define DME1737_REG_TEMP_OFFSET(ix) ((ix) == 0 ? 0x1f \ | ||
79 | : 0x1c + (ix)) | ||
80 | |||
81 | /* Voltage and temperature LSBs | ||
82 | * The LSBs (4 bits each) are stored in 5 registers with the following layouts: | ||
83 | * IN_TEMP_LSB(0) = [in5, in6] | ||
84 | * IN_TEMP_LSB(1) = [temp3, temp1] | ||
85 | * IN_TEMP_LSB(2) = [in4, temp2] | ||
86 | * IN_TEMP_LSB(3) = [in3, in0] | ||
87 | * IN_TEMP_LSB(4) = [in2, in1] */ | ||
88 | #define DME1737_REG_IN_TEMP_LSB(ix) (0x84 + (ix)) | ||
89 | static const u8 DME1737_REG_IN_LSB[] = {3, 4, 4, 3, 2, 0, 0}; | ||
90 | static const u8 DME1737_REG_IN_LSB_SHL[] = {4, 4, 0, 0, 0, 0, 4}; | ||
91 | static const u8 DME1737_REG_TEMP_LSB[] = {1, 2, 1}; | ||
92 | static const u8 DME1737_REG_TEMP_LSB_SHL[] = {4, 4, 0}; | ||
93 | |||
94 | /* Fans numbered 0-5 (ix) */ | ||
95 | #define DME1737_REG_FAN(ix) ((ix) < 4 ? 0x28 + (ix) * 2 \ | ||
96 | : 0xa1 + (ix) * 2) | ||
97 | #define DME1737_REG_FAN_MIN(ix) ((ix) < 4 ? 0x54 + (ix) * 2 \ | ||
98 | : 0xa5 + (ix) * 2) | ||
99 | #define DME1737_REG_FAN_OPT(ix) ((ix) < 4 ? 0x90 + (ix) \ | ||
100 | : 0xb2 + (ix)) | ||
101 | #define DME1737_REG_FAN_MAX(ix) (0xb4 + (ix)) /* only for fan[4-5] */ | ||
102 | |||
103 | /* PWMs numbered 0-2, 4-5 (ix) */ | ||
104 | #define DME1737_REG_PWM(ix) ((ix) < 3 ? 0x30 + (ix) \ | ||
105 | : 0xa1 + (ix)) | ||
106 | #define DME1737_REG_PWM_CONFIG(ix) (0x5c + (ix)) /* only for pwm[0-2] */ | ||
107 | #define DME1737_REG_PWM_MIN(ix) (0x64 + (ix)) /* only for pwm[0-2] */ | ||
108 | #define DME1737_REG_PWM_FREQ(ix) ((ix) < 3 ? 0x5f + (ix) \ | ||
109 | : 0xa3 + (ix)) | ||
110 | /* The layout of the ramp rate registers is different from the other pwm | ||
111 | * registers. The bits for the 3 PWMs are stored in 2 registers: | ||
112 | * PWM_RR(0) = [OFF3, OFF2, OFF1, RES, RR1E, RR1-2, RR1-1, RR1-0] | ||
113 | * PWM_RR(1) = [RR2E, RR2-2, RR2-1, RR2-0, RR3E, RR3-2, RR3-1, RR3-0] */ | ||
114 | #define DME1737_REG_PWM_RR(ix) (0x62 + (ix)) /* only for pwm[0-2] */ | ||
115 | |||
116 | /* Thermal zones 0-2 */ | ||
117 | #define DME1737_REG_ZONE_LOW(ix) (0x67 + (ix)) | ||
118 | #define DME1737_REG_ZONE_ABS(ix) (0x6a + (ix)) | ||
119 | /* The layout of the hysteresis registers is different from the other zone | ||
120 | * registers. The bits for the 3 zones are stored in 2 registers: | ||
121 | * ZONE_HYST(0) = [H1-3, H1-2, H1-1, H1-0, H2-3, H2-2, H2-1, H2-0] | ||
122 | * ZONE_HYST(1) = [H3-3, H3-2, H3-1, H3-0, RES, RES, RES, RES] */ | ||
123 | #define DME1737_REG_ZONE_HYST(ix) (0x6d + (ix)) | ||
124 | |||
125 | /* Alarm registers and bit mapping | ||
126 | * The 3 8-bit alarm registers will be concatenated to a single 32-bit | ||
127 | * alarm value [0, ALARM3, ALARM2, ALARM1]. */ | ||
128 | #define DME1737_REG_ALARM1 0x41 | ||
129 | #define DME1737_REG_ALARM2 0x42 | ||
130 | #define DME1737_REG_ALARM3 0x83 | ||
131 | static const u8 DME1737_BIT_ALARM_IN[] = {0, 1, 2, 3, 8, 16, 17}; | ||
132 | static const u8 DME1737_BIT_ALARM_TEMP[] = {4, 5, 6}; | ||
133 | static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23}; | ||
134 | |||
135 | /* Miscellaneous registers */ | ||
136 | #define DME1737_REG_COMPANY 0x3e | ||
137 | #define DME1737_REG_VERSTEP 0x3f | ||
138 | #define DME1737_REG_CONFIG 0x40 | ||
139 | #define DME1737_REG_CONFIG2 0x7f | ||
140 | #define DME1737_REG_VID 0x43 | ||
141 | #define DME1737_REG_TACH_PWM 0x81 | ||
142 | |||
143 | /* --------------------------------------------------------------------- | ||
144 | * Misc defines | ||
145 | * --------------------------------------------------------------------- */ | ||
146 | |||
147 | /* Chip identification */ | ||
148 | #define DME1737_COMPANY_SMSC 0x5c | ||
149 | #define DME1737_VERSTEP 0x88 | ||
150 | #define DME1737_VERSTEP_MASK 0xf8 | ||
151 | |||
152 | /* --------------------------------------------------------------------- | ||
153 | * Data structures and manipulation thereof | ||
154 | * --------------------------------------------------------------------- */ | ||
155 | |||
156 | struct dme1737_data { | ||
157 | struct i2c_client client; | ||
158 | struct class_device *class_dev; | ||
159 | |||
160 | struct mutex update_lock; | ||
161 | int valid; /* !=0 if following fields are valid */ | ||
162 | unsigned long last_update; /* in jiffies */ | ||
163 | unsigned long last_vbat; /* in jiffies */ | ||
164 | |||
165 | u8 vid; | ||
166 | u8 pwm_rr_en; | ||
167 | u8 has_pwm; | ||
168 | u8 has_fan; | ||
169 | |||
170 | /* Register values */ | ||
171 | u16 in[7]; | ||
172 | u8 in_min[7]; | ||
173 | u8 in_max[7]; | ||
174 | s16 temp[3]; | ||
175 | s8 temp_min[3]; | ||
176 | s8 temp_max[3]; | ||
177 | s8 temp_offset[3]; | ||
178 | u8 config; | ||
179 | u8 config2; | ||
180 | u8 vrm; | ||
181 | u16 fan[6]; | ||
182 | u16 fan_min[6]; | ||
183 | u8 fan_max[2]; | ||
184 | u8 fan_opt[6]; | ||
185 | u8 pwm[6]; | ||
186 | u8 pwm_min[3]; | ||
187 | u8 pwm_config[3]; | ||
188 | u8 pwm_acz[3]; | ||
189 | u8 pwm_freq[6]; | ||
190 | u8 pwm_rr[2]; | ||
191 | u8 zone_low[3]; | ||
192 | u8 zone_abs[3]; | ||
193 | u8 zone_hyst[2]; | ||
194 | u32 alarms; | ||
195 | }; | ||
196 | |||
197 | /* Nominal voltage values */ | ||
198 | static const int IN_NOMINAL[] = {5000, 2250, 3300, 5000, 12000, 3300, 3300}; | ||
199 | |||
200 | /* Voltage input | ||
201 | * Voltage inputs have 16 bits resolution, limit values have 8 bits | ||
202 | * resolution. */ | ||
203 | static inline int IN_FROM_REG(int reg, int ix, int res) | ||
204 | { | ||
205 | return (reg * IN_NOMINAL[ix] + (3 << (res - 3))) / (3 << (res - 2)); | ||
206 | } | ||
207 | |||
208 | static inline int IN_TO_REG(int val, int ix) | ||
209 | { | ||
210 | return SENSORS_LIMIT((val * 192 + IN_NOMINAL[ix] / 2) / | ||
211 | IN_NOMINAL[ix], 0, 255); | ||
212 | } | ||
213 | |||
214 | /* Temperature input | ||
215 | * The register values represent temperatures in 2's complement notation from | ||
216 | * -127 degrees C to +127 degrees C. Temp inputs have 16 bits resolution, limit | ||
217 | * values have 8 bits resolution. */ | ||
218 | static inline int TEMP_FROM_REG(int reg, int res) | ||
219 | { | ||
220 | return (reg * 1000) >> (res - 8); | ||
221 | } | ||
222 | |||
223 | static inline int TEMP_TO_REG(int val) | ||
224 | { | ||
225 | return SENSORS_LIMIT((val < 0 ? val - 500 : val + 500) / 1000, | ||
226 | -128, 127); | ||
227 | } | ||
228 | |||
229 | /* Temperature range */ | ||
230 | static const int TEMP_RANGE[] = {2000, 2500, 3333, 4000, 5000, 6666, 8000, | ||
231 | 10000, 13333, 16000, 20000, 26666, 32000, | ||
232 | 40000, 53333, 80000}; | ||
233 | |||
234 | static inline int TEMP_RANGE_FROM_REG(int reg) | ||
235 | { | ||
236 | return TEMP_RANGE[(reg >> 4) & 0x0f]; | ||
237 | } | ||
238 | |||
239 | static int TEMP_RANGE_TO_REG(int val, int reg) | ||
240 | { | ||
241 | int i; | ||
242 | |||
243 | for (i = 15; i > 0; i--) { | ||
244 | if (val > (TEMP_RANGE[i] + TEMP_RANGE[i - 1] + 1) / 2) { | ||
245 | break; | ||
246 | } | ||
247 | } | ||
248 | |||
249 | return (reg & 0x0f) | (i << 4); | ||
250 | } | ||
251 | |||
252 | /* Temperature hysteresis | ||
253 | * Register layout: | ||
254 | * reg[0] = [H1-3, H1-2, H1-1, H1-0, H2-3, H2-2, H2-1, H2-0] | ||
255 | * reg[1] = [H3-3, H3-2, H3-1, H3-0, xxxx, xxxx, xxxx, xxxx] */ | ||
256 | static inline int TEMP_HYST_FROM_REG(int reg, int ix) | ||
257 | { | ||
258 | return (((ix == 1) ? reg : reg >> 4) & 0x0f) * 1000; | ||
259 | } | ||
260 | |||
261 | static inline int TEMP_HYST_TO_REG(int val, int ix, int reg) | ||
262 | { | ||
263 | int hyst = SENSORS_LIMIT((val + 500) / 1000, 0, 15); | ||
264 | |||
265 | return (ix == 1) ? (reg & 0xf0) | hyst : (reg & 0x0f) | (hyst << 4); | ||
266 | } | ||
267 | |||
268 | /* Fan input RPM */ | ||
269 | static inline int FAN_FROM_REG(int reg, int tpc) | ||
270 | { | ||
271 | return (reg == 0 || reg == 0xffff) ? 0 : | ||
272 | (tpc == 0) ? 90000 * 60 / reg : tpc * reg; | ||
273 | } | ||
274 | |||
275 | static inline int FAN_TO_REG(int val, int tpc) | ||
276 | { | ||
277 | return SENSORS_LIMIT((tpc == 0) ? 90000 * 60 / val : val / tpc, | ||
278 | 0, 0xffff); | ||
279 | } | ||
280 | |||
281 | /* Fan TPC (tach pulse count) | ||
282 | * Converts a register value to a TPC multiplier or returns 0 if the tachometer | ||
283 | * is configured in legacy (non-tpc) mode */ | ||
284 | static inline int FAN_TPC_FROM_REG(int reg) | ||
285 | { | ||
286 | return (reg & 0x20) ? 0 : 60 >> (reg & 0x03); | ||
287 | } | ||
288 | |||
289 | /* Fan type | ||
290 | * The type of a fan is expressed in number of pulses-per-revolution that it | ||
291 | * emits */ | ||
292 | static inline int FAN_TYPE_FROM_REG(int reg) | ||
293 | { | ||
294 | int edge = (reg >> 1) & 0x03; | ||
295 | |||
296 | return (edge > 0) ? 1 << (edge - 1) : 0; | ||
297 | } | ||
298 | |||
299 | static inline int FAN_TYPE_TO_REG(int val, int reg) | ||
300 | { | ||
301 | int edge = (val == 4) ? 3 : val; | ||
302 | |||
303 | return (reg & 0xf9) | (edge << 1); | ||
304 | } | ||
305 | |||
306 | /* Fan max RPM */ | ||
307 | static const int FAN_MAX[] = {0x54, 0x38, 0x2a, 0x21, 0x1c, 0x18, 0x15, 0x12, | ||
308 | 0x11, 0x0f, 0x0e}; | ||
309 | |||
310 | static int FAN_MAX_FROM_REG(int reg) | ||
311 | { | ||
312 | int i; | ||
313 | |||
314 | for (i = 10; i > 0; i--) { | ||
315 | if (reg == FAN_MAX[i]) { | ||
316 | break; | ||
317 | } | ||
318 | } | ||
319 | |||
320 | return 1000 + i * 500; | ||
321 | } | ||
322 | |||
323 | static int FAN_MAX_TO_REG(int val) | ||
324 | { | ||
325 | int i; | ||
326 | |||
327 | for (i = 10; i > 0; i--) { | ||
328 | if (val > (1000 + (i - 1) * 500)) { | ||
329 | break; | ||
330 | } | ||
331 | } | ||
332 | |||
333 | return FAN_MAX[i]; | ||
334 | } | ||
335 | |||
336 | /* PWM enable | ||
337 | * Register to enable mapping: | ||
338 | * 000: 2 fan on zone 1 auto | ||
339 | * 001: 2 fan on zone 2 auto | ||
340 | * 010: 2 fan on zone 3 auto | ||
341 | * 011: 0 fan full on | ||
342 | * 100: -1 fan disabled | ||
343 | * 101: 2 fan on hottest of zones 2,3 auto | ||
344 | * 110: 2 fan on hottest of zones 1,2,3 auto | ||
345 | * 111: 1 fan in manual mode */ | ||
346 | static inline int PWM_EN_FROM_REG(int reg) | ||
347 | { | ||
348 | static const int en[] = {2, 2, 2, 0, -1, 2, 2, 1}; | ||
349 | |||
350 | return en[(reg >> 5) & 0x07]; | ||
351 | } | ||
352 | |||
353 | static inline int PWM_EN_TO_REG(int val, int reg) | ||
354 | { | ||
355 | int en = (val == 1) ? 7 : 3; | ||
356 | |||
357 | return (reg & 0x1f) | ((en & 0x07) << 5); | ||
358 | } | ||
359 | |||
360 | /* PWM auto channels zone | ||
361 | * Register to auto channels zone mapping (ACZ is a bitfield with bit x | ||
362 | * corresponding to zone x+1): | ||
363 | * 000: 001 fan on zone 1 auto | ||
364 | * 001: 010 fan on zone 2 auto | ||
365 | * 010: 100 fan on zone 3 auto | ||
366 | * 011: 000 fan full on | ||
367 | * 100: 000 fan disabled | ||
368 | * 101: 110 fan on hottest of zones 2,3 auto | ||
369 | * 110: 111 fan on hottest of zones 1,2,3 auto | ||
370 | * 111: 000 fan in manual mode */ | ||
371 | static inline int PWM_ACZ_FROM_REG(int reg) | ||
372 | { | ||
373 | static const int acz[] = {1, 2, 4, 0, 0, 6, 7, 0}; | ||
374 | |||
375 | return acz[(reg >> 5) & 0x07]; | ||
376 | } | ||
377 | |||
378 | static inline int PWM_ACZ_TO_REG(int val, int reg) | ||
379 | { | ||
380 | int acz = (val == 4) ? 2 : val - 1; | ||
381 | |||
382 | return (reg & 0x1f) | ((acz & 0x07) << 5); | ||
383 | } | ||
384 | |||
385 | /* PWM frequency */ | ||
386 | static const int PWM_FREQ[] = {11, 15, 22, 29, 35, 44, 59, 88, | ||
387 | 15000, 20000, 30000, 25000, 0, 0, 0, 0}; | ||
388 | |||
389 | static inline int PWM_FREQ_FROM_REG(int reg) | ||
390 | { | ||
391 | return PWM_FREQ[reg & 0x0f]; | ||
392 | } | ||
393 | |||
394 | static int PWM_FREQ_TO_REG(int val, int reg) | ||
395 | { | ||
396 | int i; | ||
397 | |||
398 | /* the first two cases are special - stupid chip design! */ | ||
399 | if (val > 27500) { | ||
400 | i = 10; | ||
401 | } else if (val > 22500) { | ||
402 | i = 11; | ||
403 | } else { | ||
404 | for (i = 9; i > 0; i--) { | ||
405 | if (val > (PWM_FREQ[i] + PWM_FREQ[i - 1] + 1) / 2) { | ||
406 | break; | ||
407 | } | ||
408 | } | ||
409 | } | ||
410 | |||
411 | return (reg & 0xf0) | i; | ||
412 | } | ||
413 | |||
414 | /* PWM ramp rate | ||
415 | * Register layout: | ||
416 | * reg[0] = [OFF3, OFF2, OFF1, RES, RR1-E, RR1-2, RR1-1, RR1-0] | ||
417 | * reg[1] = [RR2-E, RR2-2, RR2-1, RR2-0, RR3-E, RR3-2, RR3-1, RR3-0] */ | ||
418 | static const u8 PWM_RR[] = {206, 104, 69, 41, 26, 18, 10, 5}; | ||
419 | |||
420 | static inline int PWM_RR_FROM_REG(int reg, int ix) | ||
421 | { | ||
422 | int rr = (ix == 1) ? reg >> 4 : reg; | ||
423 | |||
424 | return (rr & 0x08) ? PWM_RR[rr & 0x07] : 0; | ||
425 | } | ||
426 | |||
427 | static int PWM_RR_TO_REG(int val, int ix, int reg) | ||
428 | { | ||
429 | int i; | ||
430 | |||
431 | for (i = 0; i < 7; i++) { | ||
432 | if (val > (PWM_RR[i] + PWM_RR[i + 1] + 1) / 2) { | ||
433 | break; | ||
434 | } | ||
435 | } | ||
436 | |||
437 | return (ix == 1) ? (reg & 0x8f) | (i << 4) : (reg & 0xf8) | i; | ||
438 | } | ||
439 | |||
440 | /* PWM ramp rate enable */ | ||
441 | static inline int PWM_RR_EN_FROM_REG(int reg, int ix) | ||
442 | { | ||
443 | return PWM_RR_FROM_REG(reg, ix) ? 1 : 0; | ||
444 | } | ||
445 | |||
446 | static inline int PWM_RR_EN_TO_REG(int val, int ix, int reg) | ||
447 | { | ||
448 | int en = (ix == 1) ? 0x80 : 0x08; | ||
449 | |||
450 | return val ? reg | en : reg & ~en; | ||
451 | } | ||
452 | |||
453 | /* PWM min/off | ||
454 | * The PWM min/off bits are part of the PMW ramp rate register 0 (see above for | ||
455 | * the register layout). */ | ||
456 | static inline int PWM_OFF_FROM_REG(int reg, int ix) | ||
457 | { | ||
458 | return (reg >> (ix + 5)) & 0x01; | ||
459 | } | ||
460 | |||
461 | static inline int PWM_OFF_TO_REG(int val, int ix, int reg) | ||
462 | { | ||
463 | return (reg & ~(1 << (ix + 5))) | ((val & 0x01) << (ix + 5)); | ||
464 | } | ||
465 | |||
466 | /* --------------------------------------------------------------------- | ||
467 | * Device I/O access | ||
468 | * --------------------------------------------------------------------- */ | ||
469 | |||
470 | static u8 dme1737_read(struct i2c_client *client, u8 reg) | ||
471 | { | ||
472 | s32 val = i2c_smbus_read_byte_data(client, reg); | ||
473 | |||
474 | if (val < 0) { | ||
475 | dev_warn(&client->dev, "Read from register 0x%02x failed! " | ||
476 | "Please report to the driver maintainer.\n", reg); | ||
477 | } | ||
478 | |||
479 | return val; | ||
480 | } | ||
481 | |||
482 | static s32 dme1737_write(struct i2c_client *client, u8 reg, u8 value) | ||
483 | { | ||
484 | s32 res = i2c_smbus_write_byte_data(client, reg, value); | ||
485 | |||
486 | if (res < 0) { | ||
487 | dev_warn(&client->dev, "Write to register 0x%02x failed! " | ||
488 | "Please report to the driver maintainer.\n", reg); | ||
489 | } | ||
490 | |||
491 | return res; | ||
492 | } | ||
493 | |||
494 | static struct dme1737_data *dme1737_update_device(struct device *dev) | ||
495 | { | ||
496 | struct i2c_client *client = to_i2c_client(dev); | ||
497 | struct dme1737_data *data = i2c_get_clientdata(client); | ||
498 | int ix; | ||
499 | u8 lsb[5]; | ||
500 | |||
501 | mutex_lock(&data->update_lock); | ||
502 | |||
503 | /* Enable a Vbat monitoring cycle every 10 mins */ | ||
504 | if (time_after(jiffies, data->last_vbat + 600 * HZ) || !data->valid) { | ||
505 | dme1737_write(client, DME1737_REG_CONFIG, dme1737_read(client, | ||
506 | DME1737_REG_CONFIG) | 0x10); | ||
507 | data->last_vbat = jiffies; | ||
508 | } | ||
509 | |||
510 | /* Sample register contents every 1 sec */ | ||
511 | if (time_after(jiffies, data->last_update + HZ) || !data->valid) { | ||
512 | data->vid = dme1737_read(client, DME1737_REG_VID) & 0x3f; | ||
513 | |||
514 | /* In (voltage) registers */ | ||
515 | for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) { | ||
516 | /* Voltage inputs are stored as 16 bit values even | ||
517 | * though they have only 12 bits resolution. This is | ||
518 | * to make it consistent with the temp inputs. */ | ||
519 | data->in[ix] = dme1737_read(client, | ||
520 | DME1737_REG_IN(ix)) << 8; | ||
521 | data->in_min[ix] = dme1737_read(client, | ||
522 | DME1737_REG_IN_MIN(ix)); | ||
523 | data->in_max[ix] = dme1737_read(client, | ||
524 | DME1737_REG_IN_MAX(ix)); | ||
525 | } | ||
526 | |||
527 | /* Temp registers */ | ||
528 | for (ix = 0; ix < ARRAY_SIZE(data->temp); ix++) { | ||
529 | /* Temp inputs are stored as 16 bit values even | ||
530 | * though they have only 12 bits resolution. This is | ||
531 | * to take advantage of implicit conversions between | ||
532 | * register values (2's complement) and temp values | ||
533 | * (signed decimal). */ | ||
534 | data->temp[ix] = dme1737_read(client, | ||
535 | DME1737_REG_TEMP(ix)) << 8; | ||
536 | data->temp_min[ix] = dme1737_read(client, | ||
537 | DME1737_REG_TEMP_MIN(ix)); | ||
538 | data->temp_max[ix] = dme1737_read(client, | ||
539 | DME1737_REG_TEMP_MAX(ix)); | ||
540 | data->temp_offset[ix] = dme1737_read(client, | ||
541 | DME1737_REG_TEMP_OFFSET(ix)); | ||
542 | } | ||
543 | |||
544 | /* In and temp LSB registers | ||
545 | * The LSBs are latched when the MSBs are read, so the order in | ||
546 | * which the registers are read (MSB first, then LSB) is | ||
547 | * important! */ | ||
548 | for (ix = 0; ix < ARRAY_SIZE(lsb); ix++) { | ||
549 | lsb[ix] = dme1737_read(client, | ||
550 | DME1737_REG_IN_TEMP_LSB(ix)); | ||
551 | } | ||
552 | for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) { | ||
553 | data->in[ix] |= (lsb[DME1737_REG_IN_LSB[ix]] << | ||
554 | DME1737_REG_IN_LSB_SHL[ix]) & 0xf0; | ||
555 | } | ||
556 | for (ix = 0; ix < ARRAY_SIZE(data->temp); ix++) { | ||
557 | data->temp[ix] |= (lsb[DME1737_REG_TEMP_LSB[ix]] << | ||
558 | DME1737_REG_TEMP_LSB_SHL[ix]) & 0xf0; | ||
559 | } | ||
560 | |||
561 | /* Fan registers */ | ||
562 | for (ix = 0; ix < ARRAY_SIZE(data->fan); ix++) { | ||
563 | /* Skip reading registers if optional fans are not | ||
564 | * present */ | ||
565 | if (!(data->has_fan & (1 << ix))) { | ||
566 | continue; | ||
567 | } | ||
568 | data->fan[ix] = dme1737_read(client, | ||
569 | DME1737_REG_FAN(ix)); | ||
570 | data->fan[ix] |= dme1737_read(client, | ||
571 | DME1737_REG_FAN(ix) + 1) << 8; | ||
572 | data->fan_min[ix] = dme1737_read(client, | ||
573 | DME1737_REG_FAN_MIN(ix)); | ||
574 | data->fan_min[ix] |= dme1737_read(client, | ||
575 | DME1737_REG_FAN_MIN(ix) + 1) << 8; | ||
576 | data->fan_opt[ix] = dme1737_read(client, | ||
577 | DME1737_REG_FAN_OPT(ix)); | ||
578 | /* fan_max exists only for fan[5-6] */ | ||
579 | if (ix > 3) { | ||
580 | data->fan_max[ix - 4] = dme1737_read(client, | ||
581 | DME1737_REG_FAN_MAX(ix)); | ||
582 | } | ||
583 | } | ||
584 | |||
585 | /* PWM registers */ | ||
586 | for (ix = 0; ix < ARRAY_SIZE(data->pwm); ix++) { | ||
587 | /* Skip reading registers if optional PWMs are not | ||
588 | * present */ | ||
589 | if (!(data->has_pwm & (1 << ix))) { | ||
590 | continue; | ||
591 | } | ||
592 | data->pwm[ix] = dme1737_read(client, | ||
593 | DME1737_REG_PWM(ix)); | ||
594 | data->pwm_freq[ix] = dme1737_read(client, | ||
595 | DME1737_REG_PWM_FREQ(ix)); | ||
596 | /* pwm_config and pwm_min exist only for pwm[1-3] */ | ||
597 | if (ix < 3) { | ||
598 | data->pwm_config[ix] = dme1737_read(client, | ||
599 | DME1737_REG_PWM_CONFIG(ix)); | ||
600 | data->pwm_min[ix] = dme1737_read(client, | ||
601 | DME1737_REG_PWM_MIN(ix)); | ||
602 | } | ||
603 | } | ||
604 | for (ix = 0; ix < ARRAY_SIZE(data->pwm_rr); ix++) { | ||
605 | data->pwm_rr[ix] = dme1737_read(client, | ||
606 | DME1737_REG_PWM_RR(ix)); | ||
607 | } | ||
608 | |||
609 | /* Thermal zone registers */ | ||
610 | for (ix = 0; ix < ARRAY_SIZE(data->zone_low); ix++) { | ||
611 | data->zone_low[ix] = dme1737_read(client, | ||
612 | DME1737_REG_ZONE_LOW(ix)); | ||
613 | data->zone_abs[ix] = dme1737_read(client, | ||
614 | DME1737_REG_ZONE_ABS(ix)); | ||
615 | } | ||
616 | for (ix = 0; ix < ARRAY_SIZE(data->zone_hyst); ix++) { | ||
617 | data->zone_hyst[ix] = dme1737_read(client, | ||
618 | DME1737_REG_ZONE_HYST(ix)); | ||
619 | } | ||
620 | |||
621 | /* Alarm registers */ | ||
622 | data->alarms = dme1737_read(client, | ||
623 | DME1737_REG_ALARM1); | ||
624 | /* Bit 7 tells us if the other alarm registers are non-zero and | ||
625 | * therefore also need to be read */ | ||
626 | if (data->alarms & 0x80) { | ||
627 | data->alarms |= dme1737_read(client, | ||
628 | DME1737_REG_ALARM2) << 8; | ||
629 | data->alarms |= dme1737_read(client, | ||
630 | DME1737_REG_ALARM3) << 16; | ||
631 | } | ||
632 | |||
633 | data->last_update = jiffies; | ||
634 | data->valid = 1; | ||
635 | } | ||
636 | |||
637 | mutex_unlock(&data->update_lock); | ||
638 | |||
639 | return data; | ||
640 | } | ||
641 | |||
642 | /* --------------------------------------------------------------------- | ||
643 | * Voltage sysfs attributes | ||
644 | * ix = [0-5] | ||
645 | * --------------------------------------------------------------------- */ | ||
646 | |||
647 | #define SYS_IN_INPUT 0 | ||
648 | #define SYS_IN_MIN 1 | ||
649 | #define SYS_IN_MAX 2 | ||
650 | #define SYS_IN_ALARM 3 | ||
651 | |||
652 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, | ||
653 | char *buf) | ||
654 | { | ||
655 | struct dme1737_data *data = dme1737_update_device(dev); | ||
656 | struct sensor_device_attribute_2 | ||
657 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | ||
658 | int ix = sensor_attr_2->index; | ||
659 | int fn = sensor_attr_2->nr; | ||
660 | int res; | ||
661 | |||
662 | switch (fn) { | ||
663 | case SYS_IN_INPUT: | ||
664 | res = IN_FROM_REG(data->in[ix], ix, 16); | ||
665 | break; | ||
666 | case SYS_IN_MIN: | ||
667 | res = IN_FROM_REG(data->in_min[ix], ix, 8); | ||
668 | break; | ||
669 | case SYS_IN_MAX: | ||
670 | res = IN_FROM_REG(data->in_max[ix], ix, 8); | ||
671 | break; | ||
672 | case SYS_IN_ALARM: | ||
673 | res = (data->alarms >> DME1737_BIT_ALARM_IN[ix]) & 0x01; | ||
674 | break; | ||
675 | default: | ||
676 | res = 0; | ||
677 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | ||
678 | } | ||
679 | |||
680 | return sprintf(buf, "%d\n", res); | ||
681 | } | ||
682 | |||
683 | static ssize_t set_in(struct device *dev, struct device_attribute *attr, | ||
684 | const char *buf, size_t count) | ||
685 | { | ||
686 | struct i2c_client *client = to_i2c_client(dev); | ||
687 | struct dme1737_data *data = i2c_get_clientdata(client); | ||
688 | struct sensor_device_attribute_2 | ||
689 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | ||
690 | int ix = sensor_attr_2->index; | ||
691 | int fn = sensor_attr_2->nr; | ||
692 | long val = simple_strtol(buf, NULL, 10); | ||
693 | |||
694 | mutex_lock(&data->update_lock); | ||
695 | switch (fn) { | ||
696 | case SYS_IN_MIN: | ||
697 | data->in_min[ix] = IN_TO_REG(val, ix); | ||
698 | dme1737_write(client, DME1737_REG_IN_MIN(ix), | ||
699 | data->in_min[ix]); | ||
700 | break; | ||
701 | case SYS_IN_MAX: | ||
702 | data->in_max[ix] = IN_TO_REG(val, ix); | ||
703 | dme1737_write(client, DME1737_REG_IN_MAX(ix), | ||
704 | data->in_max[ix]); | ||
705 | break; | ||
706 | default: | ||
707 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | ||
708 | } | ||
709 | mutex_unlock(&data->update_lock); | ||
710 | |||
711 | return count; | ||
712 | } | ||
713 | |||
714 | /* --------------------------------------------------------------------- | ||
715 | * Temperature sysfs attributes | ||
716 | * ix = [0-2] | ||
717 | * --------------------------------------------------------------------- */ | ||
718 | |||
719 | #define SYS_TEMP_INPUT 0 | ||
720 | #define SYS_TEMP_MIN 1 | ||
721 | #define SYS_TEMP_MAX 2 | ||
722 | #define SYS_TEMP_OFFSET 3 | ||
723 | #define SYS_TEMP_ALARM 4 | ||
724 | #define SYS_TEMP_FAULT 5 | ||
725 | |||
726 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, | ||
727 | char *buf) | ||
728 | { | ||
729 | struct dme1737_data *data = dme1737_update_device(dev); | ||
730 | struct sensor_device_attribute_2 | ||
731 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | ||
732 | int ix = sensor_attr_2->index; | ||
733 | int fn = sensor_attr_2->nr; | ||
734 | int res; | ||
735 | |||
736 | switch (fn) { | ||
737 | case SYS_TEMP_INPUT: | ||
738 | res = TEMP_FROM_REG(data->temp[ix], 16); | ||
739 | break; | ||
740 | case SYS_TEMP_MIN: | ||
741 | res = TEMP_FROM_REG(data->temp_min[ix], 8); | ||
742 | break; | ||
743 | case SYS_TEMP_MAX: | ||
744 | res = TEMP_FROM_REG(data->temp_max[ix], 8); | ||
745 | break; | ||
746 | case SYS_TEMP_OFFSET: | ||
747 | res = TEMP_FROM_REG(data->temp_offset[ix], 8); | ||
748 | break; | ||
749 | case SYS_TEMP_ALARM: | ||
750 | res = (data->alarms >> DME1737_BIT_ALARM_TEMP[ix]) & 0x01; | ||
751 | break; | ||
752 | case SYS_TEMP_FAULT: | ||
753 | res = (data->temp[ix] == 0x0800); | ||
754 | break; | ||
755 | default: | ||
756 | res = 0; | ||
757 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | ||
758 | } | ||
759 | |||
760 | return sprintf(buf, "%d\n", res); | ||
761 | } | ||
762 | |||
763 | static ssize_t set_temp(struct device *dev, struct device_attribute *attr, | ||
764 | const char *buf, size_t count) | ||
765 | { | ||
766 | struct i2c_client *client = to_i2c_client(dev); | ||
767 | struct dme1737_data *data = i2c_get_clientdata(client); | ||
768 | struct sensor_device_attribute_2 | ||
769 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | ||
770 | int ix = sensor_attr_2->index; | ||
771 | int fn = sensor_attr_2->nr; | ||
772 | long val = simple_strtol(buf, NULL, 10); | ||
773 | |||
774 | mutex_lock(&data->update_lock); | ||
775 | switch (fn) { | ||
776 | case SYS_TEMP_MIN: | ||
777 | data->temp_min[ix] = TEMP_TO_REG(val); | ||
778 | dme1737_write(client, DME1737_REG_TEMP_MIN(ix), | ||
779 | data->temp_min[ix]); | ||
780 | break; | ||
781 | case SYS_TEMP_MAX: | ||
782 | data->temp_max[ix] = TEMP_TO_REG(val); | ||
783 | dme1737_write(client, DME1737_REG_TEMP_MAX(ix), | ||
784 | data->temp_max[ix]); | ||
785 | break; | ||
786 | case SYS_TEMP_OFFSET: | ||
787 | data->temp_offset[ix] = TEMP_TO_REG(val); | ||
788 | dme1737_write(client, DME1737_REG_TEMP_OFFSET(ix), | ||
789 | data->temp_offset[ix]); | ||
790 | break; | ||
791 | default: | ||
792 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | ||
793 | } | ||
794 | mutex_unlock(&data->update_lock); | ||
795 | |||
796 | return count; | ||
797 | } | ||
798 | |||
799 | /* --------------------------------------------------------------------- | ||
800 | * Zone sysfs attributes | ||
801 | * ix = [0-2] | ||
802 | * --------------------------------------------------------------------- */ | ||
803 | |||
804 | #define SYS_ZONE_AUTO_CHANNELS_TEMP 0 | ||
805 | #define SYS_ZONE_AUTO_POINT1_TEMP_HYST 1 | ||
806 | #define SYS_ZONE_AUTO_POINT1_TEMP 2 | ||
807 | #define SYS_ZONE_AUTO_POINT2_TEMP 3 | ||
808 | #define SYS_ZONE_AUTO_POINT3_TEMP 4 | ||
809 | |||
810 | static ssize_t show_zone(struct device *dev, struct device_attribute *attr, | ||
811 | char *buf) | ||
812 | { | ||
813 | struct dme1737_data *data = dme1737_update_device(dev); | ||
814 | struct sensor_device_attribute_2 | ||
815 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | ||
816 | int ix = sensor_attr_2->index; | ||
817 | int fn = sensor_attr_2->nr; | ||
818 | int res; | ||
819 | |||
820 | switch (fn) { | ||
821 | case SYS_ZONE_AUTO_CHANNELS_TEMP: | ||
822 | /* check config2 for non-standard temp-to-zone mapping */ | ||
823 | if ((ix == 1) && (data->config2 & 0x02)) { | ||
824 | res = 4; | ||
825 | } else { | ||
826 | res = 1 << ix; | ||
827 | } | ||
828 | break; | ||
829 | case SYS_ZONE_AUTO_POINT1_TEMP_HYST: | ||
830 | res = TEMP_FROM_REG(data->zone_low[ix], 8) - | ||
831 | TEMP_HYST_FROM_REG(data->zone_hyst[ix == 2], ix); | ||
832 | break; | ||
833 | case SYS_ZONE_AUTO_POINT1_TEMP: | ||
834 | res = TEMP_FROM_REG(data->zone_low[ix], 8); | ||
835 | break; | ||
836 | case SYS_ZONE_AUTO_POINT2_TEMP: | ||
837 | /* pwm_freq holds the temp range bits in the upper nibble */ | ||
838 | res = TEMP_FROM_REG(data->zone_low[ix], 8) + | ||
839 | TEMP_RANGE_FROM_REG(data->pwm_freq[ix]); | ||
840 | break; | ||
841 | case SYS_ZONE_AUTO_POINT3_TEMP: | ||
842 | res = TEMP_FROM_REG(data->zone_abs[ix], 8); | ||
843 | break; | ||
844 | default: | ||
845 | res = 0; | ||
846 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | ||
847 | } | ||
848 | |||
849 | return sprintf(buf, "%d\n", res); | ||
850 | } | ||
851 | |||
852 | static ssize_t set_zone(struct device *dev, struct device_attribute *attr, | ||
853 | const char *buf, size_t count) | ||
854 | { | ||
855 | struct i2c_client *client = to_i2c_client(dev); | ||
856 | struct dme1737_data *data = i2c_get_clientdata(client); | ||
857 | struct sensor_device_attribute_2 | ||
858 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | ||
859 | int ix = sensor_attr_2->index; | ||
860 | int fn = sensor_attr_2->nr; | ||
861 | long val = simple_strtol(buf, NULL, 10); | ||
862 | |||
863 | mutex_lock(&data->update_lock); | ||
864 | switch (fn) { | ||
865 | case SYS_ZONE_AUTO_POINT1_TEMP_HYST: | ||
866 | /* Refresh the cache */ | ||
867 | data->zone_low[ix] = dme1737_read(client, | ||
868 | DME1737_REG_ZONE_LOW(ix)); | ||
869 | /* Modify the temp hyst value */ | ||
870 | data->zone_hyst[ix == 2] = TEMP_HYST_TO_REG( | ||
871 | TEMP_FROM_REG(data->zone_low[ix], 8) - | ||
872 | val, ix, dme1737_read(client, | ||
873 | DME1737_REG_ZONE_HYST(ix == 2))); | ||
874 | dme1737_write(client, DME1737_REG_ZONE_HYST(ix == 2), | ||
875 | data->zone_hyst[ix == 2]); | ||
876 | break; | ||
877 | case SYS_ZONE_AUTO_POINT1_TEMP: | ||
878 | data->zone_low[ix] = TEMP_TO_REG(val); | ||
879 | dme1737_write(client, DME1737_REG_ZONE_LOW(ix), | ||
880 | data->zone_low[ix]); | ||
881 | break; | ||
882 | case SYS_ZONE_AUTO_POINT2_TEMP: | ||
883 | /* Refresh the cache */ | ||
884 | data->zone_low[ix] = dme1737_read(client, | ||
885 | DME1737_REG_ZONE_LOW(ix)); | ||
886 | /* Modify the temp range value (which is stored in the upper | ||
887 | * nibble of the pwm_freq register) */ | ||
888 | data->pwm_freq[ix] = TEMP_RANGE_TO_REG(val - | ||
889 | TEMP_FROM_REG(data->zone_low[ix], 8), | ||
890 | dme1737_read(client, | ||
891 | DME1737_REG_PWM_FREQ(ix))); | ||
892 | dme1737_write(client, DME1737_REG_PWM_FREQ(ix), | ||
893 | data->pwm_freq[ix]); | ||
894 | break; | ||
895 | case SYS_ZONE_AUTO_POINT3_TEMP: | ||
896 | data->zone_abs[ix] = TEMP_TO_REG(val); | ||
897 | dme1737_write(client, DME1737_REG_ZONE_ABS(ix), | ||
898 | data->zone_abs[ix]); | ||
899 | break; | ||
900 | default: | ||
901 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | ||
902 | } | ||
903 | mutex_unlock(&data->update_lock); | ||
904 | |||
905 | return count; | ||
906 | } | ||
907 | |||
908 | /* --------------------------------------------------------------------- | ||
909 | * Fan sysfs attributes | ||
910 | * ix = [0-5] | ||
911 | * --------------------------------------------------------------------- */ | ||
912 | |||
913 | #define SYS_FAN_INPUT 0 | ||
914 | #define SYS_FAN_MIN 1 | ||
915 | #define SYS_FAN_MAX 2 | ||
916 | #define SYS_FAN_ALARM 3 | ||
917 | #define SYS_FAN_TYPE 4 | ||
918 | |||
919 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, | ||
920 | char *buf) | ||
921 | { | ||
922 | struct dme1737_data *data = dme1737_update_device(dev); | ||
923 | struct sensor_device_attribute_2 | ||
924 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | ||
925 | int ix = sensor_attr_2->index; | ||
926 | int fn = sensor_attr_2->nr; | ||
927 | int res; | ||
928 | |||
929 | switch (fn) { | ||
930 | case SYS_FAN_INPUT: | ||
931 | res = FAN_FROM_REG(data->fan[ix], | ||
932 | ix < 4 ? 0 : | ||
933 | FAN_TPC_FROM_REG(data->fan_opt[ix])); | ||
934 | break; | ||
935 | case SYS_FAN_MIN: | ||
936 | res = FAN_FROM_REG(data->fan_min[ix], | ||
937 | ix < 4 ? 0 : | ||
938 | FAN_TPC_FROM_REG(data->fan_opt[ix])); | ||
939 | break; | ||
940 | case SYS_FAN_MAX: | ||
941 | /* only valid for fan[5-6] */ | ||
942 | res = FAN_MAX_FROM_REG(data->fan_max[ix - 4]); | ||
943 | break; | ||
944 | case SYS_FAN_ALARM: | ||
945 | res = (data->alarms >> DME1737_BIT_ALARM_FAN[ix]) & 0x01; | ||
946 | break; | ||
947 | case SYS_FAN_TYPE: | ||
948 | /* only valid for fan[1-4] */ | ||
949 | res = FAN_TYPE_FROM_REG(data->fan_opt[ix]); | ||
950 | break; | ||
951 | default: | ||
952 | res = 0; | ||
953 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | ||
954 | } | ||
955 | |||
956 | return sprintf(buf, "%d\n", res); | ||
957 | } | ||
958 | |||
959 | static ssize_t set_fan(struct device *dev, struct device_attribute *attr, | ||
960 | const char *buf, size_t count) | ||
961 | { | ||
962 | struct i2c_client *client = to_i2c_client(dev); | ||
963 | struct dme1737_data *data = i2c_get_clientdata(client); | ||
964 | struct sensor_device_attribute_2 | ||
965 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | ||
966 | int ix = sensor_attr_2->index; | ||
967 | int fn = sensor_attr_2->nr; | ||
968 | long val = simple_strtol(buf, NULL, 10); | ||
969 | |||
970 | mutex_lock(&data->update_lock); | ||
971 | switch (fn) { | ||
972 | case SYS_FAN_MIN: | ||
973 | if (ix < 4) { | ||
974 | data->fan_min[ix] = FAN_TO_REG(val, 0); | ||
975 | } else { | ||
976 | /* Refresh the cache */ | ||
977 | data->fan_opt[ix] = dme1737_read(client, | ||
978 | DME1737_REG_FAN_OPT(ix)); | ||
979 | /* Modify the fan min value */ | ||
980 | data->fan_min[ix] = FAN_TO_REG(val, | ||
981 | FAN_TPC_FROM_REG(data->fan_opt[ix])); | ||
982 | } | ||
983 | dme1737_write(client, DME1737_REG_FAN_MIN(ix), | ||
984 | data->fan_min[ix] & 0xff); | ||
985 | dme1737_write(client, DME1737_REG_FAN_MIN(ix) + 1, | ||
986 | data->fan_min[ix] >> 8); | ||
987 | break; | ||
988 | case SYS_FAN_MAX: | ||
989 | /* Only valid for fan[5-6] */ | ||
990 | data->fan_max[ix - 4] = FAN_MAX_TO_REG(val); | ||
991 | dme1737_write(client, DME1737_REG_FAN_MAX(ix), | ||
992 | data->fan_max[ix - 4]); | ||
993 | break; | ||
994 | case SYS_FAN_TYPE: | ||
995 | /* Only valid for fan[1-4] */ | ||
996 | if (!(val == 1 || val == 2 || val == 4)) { | ||
997 | count = -EINVAL; | ||
998 | dev_warn(&client->dev, "Fan type value %ld not " | ||
999 | "supported. Choose one of 1, 2, or 4.\n", | ||
1000 | val); | ||
1001 | goto exit; | ||
1002 | } | ||
1003 | data->fan_opt[ix] = FAN_TYPE_TO_REG(val, dme1737_read(client, | ||
1004 | DME1737_REG_FAN_OPT(ix))); | ||
1005 | dme1737_write(client, DME1737_REG_FAN_OPT(ix), | ||
1006 | data->fan_opt[ix]); | ||
1007 | break; | ||
1008 | default: | ||
1009 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | ||
1010 | } | ||
1011 | exit: | ||
1012 | mutex_unlock(&data->update_lock); | ||
1013 | |||
1014 | return count; | ||
1015 | } | ||
1016 | |||
1017 | /* --------------------------------------------------------------------- | ||
1018 | * PWM sysfs attributes | ||
1019 | * ix = [0-4] | ||
1020 | * --------------------------------------------------------------------- */ | ||
1021 | |||
1022 | #define SYS_PWM 0 | ||
1023 | #define SYS_PWM_FREQ 1 | ||
1024 | #define SYS_PWM_ENABLE 2 | ||
1025 | #define SYS_PWM_RAMP_RATE 3 | ||
1026 | #define SYS_PWM_AUTO_CHANNELS_ZONE 4 | ||
1027 | #define SYS_PWM_AUTO_PWM_MIN 5 | ||
1028 | #define SYS_PWM_AUTO_POINT1_PWM 6 | ||
1029 | #define SYS_PWM_AUTO_POINT2_PWM 7 | ||
1030 | |||
1031 | static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, | ||
1032 | char *buf) | ||
1033 | { | ||
1034 | struct dme1737_data *data = dme1737_update_device(dev); | ||
1035 | struct sensor_device_attribute_2 | ||
1036 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | ||
1037 | int ix = sensor_attr_2->index; | ||
1038 | int fn = sensor_attr_2->nr; | ||
1039 | int res; | ||
1040 | |||
1041 | switch (fn) { | ||
1042 | case SYS_PWM: | ||
1043 | if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 0) { | ||
1044 | res = 255; | ||
1045 | } else { | ||
1046 | res = data->pwm[ix]; | ||
1047 | } | ||
1048 | break; | ||
1049 | case SYS_PWM_FREQ: | ||
1050 | res = PWM_FREQ_FROM_REG(data->pwm_freq[ix]); | ||
1051 | break; | ||
1052 | case SYS_PWM_ENABLE: | ||
1053 | if (ix > 3) { | ||
1054 | res = 1; /* pwm[5-6] hard-wired to manual mode */ | ||
1055 | } else { | ||
1056 | res = PWM_EN_FROM_REG(data->pwm_config[ix]); | ||
1057 | } | ||
1058 | break; | ||
1059 | case SYS_PWM_RAMP_RATE: | ||
1060 | /* Only valid for pwm[1-3] */ | ||
1061 | res = PWM_RR_FROM_REG(data->pwm_rr[ix > 0], ix); | ||
1062 | break; | ||
1063 | case SYS_PWM_AUTO_CHANNELS_ZONE: | ||
1064 | /* Only valid for pwm[1-3] */ | ||
1065 | if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { | ||
1066 | res = PWM_ACZ_FROM_REG(data->pwm_config[ix]); | ||
1067 | } else { | ||
1068 | res = data->pwm_acz[ix]; | ||
1069 | } | ||
1070 | break; | ||
1071 | case SYS_PWM_AUTO_PWM_MIN: | ||
1072 | /* Only valid for pwm[1-3] */ | ||
1073 | if (PWM_OFF_FROM_REG(data->pwm_rr[0], ix)) { | ||
1074 | res = data->pwm_min[ix]; | ||
1075 | } else { | ||
1076 | res = 0; | ||
1077 | } | ||
1078 | break; | ||
1079 | case SYS_PWM_AUTO_POINT1_PWM: | ||
1080 | /* Only valid for pwm[1-3] */ | ||
1081 | res = data->pwm_min[ix]; | ||
1082 | break; | ||
1083 | case SYS_PWM_AUTO_POINT2_PWM: | ||
1084 | /* Only valid for pwm[1-3] */ | ||
1085 | res = 255; /* hard-wired */ | ||
1086 | break; | ||
1087 | default: | ||
1088 | res = 0; | ||
1089 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | ||
1090 | } | ||
1091 | |||
1092 | return sprintf(buf, "%d\n", res); | ||
1093 | } | ||
1094 | |||
1095 | static struct attribute *dme1737_attr_pwm[]; | ||
1096 | static void dme1737_chmod_file(struct i2c_client*, struct attribute*, mode_t); | ||
1097 | |||
1098 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | ||
1099 | const char *buf, size_t count) | ||
1100 | { | ||
1101 | struct i2c_client *client = to_i2c_client(dev); | ||
1102 | struct dme1737_data *data = i2c_get_clientdata(client); | ||
1103 | struct sensor_device_attribute_2 | ||
1104 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | ||
1105 | int ix = sensor_attr_2->index; | ||
1106 | int fn = sensor_attr_2->nr; | ||
1107 | long val = simple_strtol(buf, NULL, 10); | ||
1108 | |||
1109 | mutex_lock(&data->update_lock); | ||
1110 | switch (fn) { | ||
1111 | case SYS_PWM: | ||
1112 | data->pwm[ix] = SENSORS_LIMIT(val, 0, 255); | ||
1113 | dme1737_write(client, DME1737_REG_PWM(ix), data->pwm[ix]); | ||
1114 | break; | ||
1115 | case SYS_PWM_FREQ: | ||
1116 | data->pwm_freq[ix] = PWM_FREQ_TO_REG(val, dme1737_read(client, | ||
1117 | DME1737_REG_PWM_FREQ(ix))); | ||
1118 | dme1737_write(client, DME1737_REG_PWM_FREQ(ix), | ||
1119 | data->pwm_freq[ix]); | ||
1120 | break; | ||
1121 | case SYS_PWM_ENABLE: | ||
1122 | /* Only valid for pwm[1-3] */ | ||
1123 | if (val < 0 || val > 2) { | ||
1124 | count = -EINVAL; | ||
1125 | dev_warn(&client->dev, "PWM enable %ld not " | ||
1126 | "supported. Choose one of 0, 1, or 2.\n", | ||
1127 | val); | ||
1128 | goto exit; | ||
1129 | } | ||
1130 | /* Refresh the cache */ | ||
1131 | data->pwm_config[ix] = dme1737_read(client, | ||
1132 | DME1737_REG_PWM_CONFIG(ix)); | ||
1133 | if (val == PWM_EN_FROM_REG(data->pwm_config[ix])) { | ||
1134 | /* Bail out if no change */ | ||
1135 | goto exit; | ||
1136 | } | ||
1137 | /* Do some housekeeping if we are currently in auto mode */ | ||
1138 | if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { | ||
1139 | /* Save the current zone channel assignment */ | ||
1140 | data->pwm_acz[ix] = PWM_ACZ_FROM_REG( | ||
1141 | data->pwm_config[ix]); | ||
1142 | /* Save the current ramp rate state and disable it */ | ||
1143 | data->pwm_rr[ix > 0] = dme1737_read(client, | ||
1144 | DME1737_REG_PWM_RR(ix > 0)); | ||
1145 | data->pwm_rr_en &= ~(1 << ix); | ||
1146 | if (PWM_RR_EN_FROM_REG(data->pwm_rr[ix > 0], ix)) { | ||
1147 | data->pwm_rr_en |= (1 << ix); | ||
1148 | data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(0, ix, | ||
1149 | data->pwm_rr[ix > 0]); | ||
1150 | dme1737_write(client, | ||
1151 | DME1737_REG_PWM_RR(ix > 0), | ||
1152 | data->pwm_rr[ix > 0]); | ||
1153 | } | ||
1154 | } | ||
1155 | /* Set the new PWM mode */ | ||
1156 | switch (val) { | ||
1157 | case 0: | ||
1158 | /* Change permissions of pwm[ix] to read-only */ | ||
1159 | dme1737_chmod_file(client, dme1737_attr_pwm[ix], | ||
1160 | S_IRUGO); | ||
1161 | /* Turn fan fully on */ | ||
1162 | data->pwm_config[ix] = PWM_EN_TO_REG(0, | ||
1163 | data->pwm_config[ix]); | ||
1164 | dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), | ||
1165 | data->pwm_config[ix]); | ||
1166 | break; | ||
1167 | case 1: | ||
1168 | /* Turn on manual mode */ | ||
1169 | data->pwm_config[ix] = PWM_EN_TO_REG(1, | ||
1170 | data->pwm_config[ix]); | ||
1171 | dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), | ||
1172 | data->pwm_config[ix]); | ||
1173 | /* Change permissions of pwm[ix] to read-writeable */ | ||
1174 | dme1737_chmod_file(client, dme1737_attr_pwm[ix], | ||
1175 | S_IRUGO | S_IWUSR); | ||
1176 | break; | ||
1177 | case 2: | ||
1178 | /* Change permissions of pwm[ix] to read-only */ | ||
1179 | dme1737_chmod_file(client, dme1737_attr_pwm[ix], | ||
1180 | S_IRUGO); | ||
1181 | /* Turn on auto mode using the saved zone channel | ||
1182 | * assignment */ | ||
1183 | data->pwm_config[ix] = PWM_ACZ_TO_REG( | ||
1184 | data->pwm_acz[ix], | ||
1185 | data->pwm_config[ix]); | ||
1186 | dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), | ||
1187 | data->pwm_config[ix]); | ||
1188 | /* Enable PWM ramp rate if previously enabled */ | ||
1189 | if (data->pwm_rr_en & (1 << ix)) { | ||
1190 | data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(1, ix, | ||
1191 | dme1737_read(client, | ||
1192 | DME1737_REG_PWM_RR(ix > 0))); | ||
1193 | dme1737_write(client, | ||
1194 | DME1737_REG_PWM_RR(ix > 0), | ||
1195 | data->pwm_rr[ix > 0]); | ||
1196 | } | ||
1197 | break; | ||
1198 | } | ||
1199 | break; | ||
1200 | case SYS_PWM_RAMP_RATE: | ||
1201 | /* Only valid for pwm[1-3] */ | ||
1202 | /* Refresh the cache */ | ||
1203 | data->pwm_config[ix] = dme1737_read(client, | ||
1204 | DME1737_REG_PWM_CONFIG(ix)); | ||
1205 | data->pwm_rr[ix > 0] = dme1737_read(client, | ||
1206 | DME1737_REG_PWM_RR(ix > 0)); | ||
1207 | /* Set the ramp rate value */ | ||
1208 | if (val > 0) { | ||
1209 | data->pwm_rr[ix > 0] = PWM_RR_TO_REG(val, ix, | ||
1210 | data->pwm_rr[ix > 0]); | ||
1211 | } | ||
1212 | /* Enable/disable the feature only if the associated PWM | ||
1213 | * output is in automatic mode. */ | ||
1214 | if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { | ||
1215 | data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(val > 0, ix, | ||
1216 | data->pwm_rr[ix > 0]); | ||
1217 | } | ||
1218 | dme1737_write(client, DME1737_REG_PWM_RR(ix > 0), | ||
1219 | data->pwm_rr[ix > 0]); | ||
1220 | break; | ||
1221 | case SYS_PWM_AUTO_CHANNELS_ZONE: | ||
1222 | /* Only valid for pwm[1-3] */ | ||
1223 | if (!(val == 1 || val == 2 || val == 4 || | ||
1224 | val == 6 || val == 7)) { | ||
1225 | count = -EINVAL; | ||
1226 | dev_warn(&client->dev, "PWM auto channels zone %ld " | ||
1227 | "not supported. Choose one of 1, 2, 4, 6, " | ||
1228 | "or 7.\n", val); | ||
1229 | goto exit; | ||
1230 | } | ||
1231 | /* Refresh the cache */ | ||
1232 | data->pwm_config[ix] = dme1737_read(client, | ||
1233 | DME1737_REG_PWM_CONFIG(ix)); | ||
1234 | if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { | ||
1235 | /* PWM is already in auto mode so update the temp | ||
1236 | * channel assignment */ | ||
1237 | data->pwm_config[ix] = PWM_ACZ_TO_REG(val, | ||
1238 | data->pwm_config[ix]); | ||
1239 | dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), | ||
1240 | data->pwm_config[ix]); | ||
1241 | } else { | ||
1242 | /* PWM is not in auto mode so we save the temp | ||
1243 | * channel assignment for later use */ | ||
1244 | data->pwm_acz[ix] = val; | ||
1245 | } | ||
1246 | break; | ||
1247 | case SYS_PWM_AUTO_PWM_MIN: | ||
1248 | /* Only valid for pwm[1-3] */ | ||
1249 | /* Refresh the cache */ | ||
1250 | data->pwm_min[ix] = dme1737_read(client, | ||
1251 | DME1737_REG_PWM_MIN(ix)); | ||
1252 | /* There are only 2 values supported for the auto_pwm_min | ||
1253 | * value: 0 or auto_point1_pwm. So if the temperature drops | ||
1254 | * below the auto_point1_temp_hyst value, the fan either turns | ||
1255 | * off or runs at auto_point1_pwm duty-cycle. */ | ||
1256 | if (val > ((data->pwm_min[ix] + 1) / 2)) { | ||
1257 | data->pwm_rr[0] = PWM_OFF_TO_REG(1, ix, | ||
1258 | dme1737_read(client, | ||
1259 | DME1737_REG_PWM_RR(0))); | ||
1260 | |||
1261 | } else { | ||
1262 | data->pwm_rr[0] = PWM_OFF_TO_REG(0, ix, | ||
1263 | dme1737_read(client, | ||
1264 | DME1737_REG_PWM_RR(0))); | ||
1265 | |||
1266 | } | ||
1267 | dme1737_write(client, DME1737_REG_PWM_RR(0), | ||
1268 | data->pwm_rr[0]); | ||
1269 | break; | ||
1270 | case SYS_PWM_AUTO_POINT1_PWM: | ||
1271 | /* Only valid for pwm[1-3] */ | ||
1272 | data->pwm_min[ix] = SENSORS_LIMIT(val, 0, 255); | ||
1273 | dme1737_write(client, DME1737_REG_PWM_MIN(ix), | ||
1274 | data->pwm_min[ix]); | ||
1275 | break; | ||
1276 | default: | ||
1277 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | ||
1278 | } | ||
1279 | exit: | ||
1280 | mutex_unlock(&data->update_lock); | ||
1281 | |||
1282 | return count; | ||
1283 | } | ||
1284 | |||
1285 | /* --------------------------------------------------------------------- | ||
1286 | * Miscellaneous sysfs attributes | ||
1287 | * --------------------------------------------------------------------- */ | ||
1288 | |||
1289 | static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, | ||
1290 | char *buf) | ||
1291 | { | ||
1292 | struct i2c_client *client = to_i2c_client(dev); | ||
1293 | struct dme1737_data *data = i2c_get_clientdata(client); | ||
1294 | |||
1295 | return sprintf(buf, "%d\n", data->vrm); | ||
1296 | } | ||
1297 | |||
1298 | static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, | ||
1299 | const char *buf, size_t count) | ||
1300 | { | ||
1301 | struct i2c_client *client = to_i2c_client(dev); | ||
1302 | struct dme1737_data *data = i2c_get_clientdata(client); | ||
1303 | long val = simple_strtol(buf, NULL, 10); | ||
1304 | |||
1305 | data->vrm = val; | ||
1306 | return count; | ||
1307 | } | ||
1308 | |||
1309 | static ssize_t show_vid(struct device *dev, struct device_attribute *attr, | ||
1310 | char *buf) | ||
1311 | { | ||
1312 | struct dme1737_data *data = dme1737_update_device(dev); | ||
1313 | |||
1314 | return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); | ||
1315 | } | ||
1316 | |||
1317 | /* --------------------------------------------------------------------- | ||
1318 | * Sysfs device attribute defines and structs | ||
1319 | * --------------------------------------------------------------------- */ | ||
1320 | |||
1321 | /* Voltages 0-6 */ | ||
1322 | |||
1323 | #define SENSOR_DEVICE_ATTR_IN(ix) \ | ||
1324 | static SENSOR_DEVICE_ATTR_2(in##ix##_input, S_IRUGO, \ | ||
1325 | show_in, NULL, SYS_IN_INPUT, ix); \ | ||
1326 | static SENSOR_DEVICE_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \ | ||
1327 | show_in, set_in, SYS_IN_MIN, ix); \ | ||
1328 | static SENSOR_DEVICE_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \ | ||
1329 | show_in, set_in, SYS_IN_MAX, ix); \ | ||
1330 | static SENSOR_DEVICE_ATTR_2(in##ix##_alarm, S_IRUGO, \ | ||
1331 | show_in, NULL, SYS_IN_ALARM, ix) | ||
1332 | |||
1333 | SENSOR_DEVICE_ATTR_IN(0); | ||
1334 | SENSOR_DEVICE_ATTR_IN(1); | ||
1335 | SENSOR_DEVICE_ATTR_IN(2); | ||
1336 | SENSOR_DEVICE_ATTR_IN(3); | ||
1337 | SENSOR_DEVICE_ATTR_IN(4); | ||
1338 | SENSOR_DEVICE_ATTR_IN(5); | ||
1339 | SENSOR_DEVICE_ATTR_IN(6); | ||
1340 | |||
1341 | /* Temperatures 1-3 */ | ||
1342 | |||
1343 | #define SENSOR_DEVICE_ATTR_TEMP(ix) \ | ||
1344 | static SENSOR_DEVICE_ATTR_2(temp##ix##_input, S_IRUGO, \ | ||
1345 | show_temp, NULL, SYS_TEMP_INPUT, ix-1); \ | ||
1346 | static SENSOR_DEVICE_ATTR_2(temp##ix##_min, S_IRUGO | S_IWUSR, \ | ||
1347 | show_temp, set_temp, SYS_TEMP_MIN, ix-1); \ | ||
1348 | static SENSOR_DEVICE_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \ | ||
1349 | show_temp, set_temp, SYS_TEMP_MAX, ix-1); \ | ||
1350 | static SENSOR_DEVICE_ATTR_2(temp##ix##_offset, S_IRUGO, \ | ||
1351 | show_temp, set_temp, SYS_TEMP_OFFSET, ix-1); \ | ||
1352 | static SENSOR_DEVICE_ATTR_2(temp##ix##_alarm, S_IRUGO, \ | ||
1353 | show_temp, NULL, SYS_TEMP_ALARM, ix-1); \ | ||
1354 | static SENSOR_DEVICE_ATTR_2(temp##ix##_fault, S_IRUGO, \ | ||
1355 | show_temp, NULL, SYS_TEMP_FAULT, ix-1) | ||
1356 | |||
1357 | SENSOR_DEVICE_ATTR_TEMP(1); | ||
1358 | SENSOR_DEVICE_ATTR_TEMP(2); | ||
1359 | SENSOR_DEVICE_ATTR_TEMP(3); | ||
1360 | |||
1361 | /* Zones 1-3 */ | ||
1362 | |||
1363 | #define SENSOR_DEVICE_ATTR_ZONE(ix) \ | ||
1364 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_channels_temp, S_IRUGO, \ | ||
1365 | show_zone, NULL, SYS_ZONE_AUTO_CHANNELS_TEMP, ix-1); \ | ||
1366 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp_hyst, S_IRUGO, \ | ||
1367 | show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP_HYST, ix-1); \ | ||
1368 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp, S_IRUGO, \ | ||
1369 | show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP, ix-1); \ | ||
1370 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point2_temp, S_IRUGO, \ | ||
1371 | show_zone, set_zone, SYS_ZONE_AUTO_POINT2_TEMP, ix-1); \ | ||
1372 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point3_temp, S_IRUGO, \ | ||
1373 | show_zone, set_zone, SYS_ZONE_AUTO_POINT3_TEMP, ix-1) | ||
1374 | |||
1375 | SENSOR_DEVICE_ATTR_ZONE(1); | ||
1376 | SENSOR_DEVICE_ATTR_ZONE(2); | ||
1377 | SENSOR_DEVICE_ATTR_ZONE(3); | ||
1378 | |||
1379 | /* Fans 1-4 */ | ||
1380 | |||
1381 | #define SENSOR_DEVICE_ATTR_FAN_1TO4(ix) \ | ||
1382 | static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \ | ||
1383 | show_fan, NULL, SYS_FAN_INPUT, ix-1); \ | ||
1384 | static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \ | ||
1385 | show_fan, set_fan, SYS_FAN_MIN, ix-1); \ | ||
1386 | static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \ | ||
1387 | show_fan, NULL, SYS_FAN_ALARM, ix-1); \ | ||
1388 | static SENSOR_DEVICE_ATTR_2(fan##ix##_type, S_IRUGO | S_IWUSR, \ | ||
1389 | show_fan, set_fan, SYS_FAN_TYPE, ix-1) | ||
1390 | |||
1391 | SENSOR_DEVICE_ATTR_FAN_1TO4(1); | ||
1392 | SENSOR_DEVICE_ATTR_FAN_1TO4(2); | ||
1393 | SENSOR_DEVICE_ATTR_FAN_1TO4(3); | ||
1394 | SENSOR_DEVICE_ATTR_FAN_1TO4(4); | ||
1395 | |||
1396 | /* Fans 5-6 */ | ||
1397 | |||
1398 | #define SENSOR_DEVICE_ATTR_FAN_5TO6(ix) \ | ||
1399 | static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \ | ||
1400 | show_fan, NULL, SYS_FAN_INPUT, ix-1); \ | ||
1401 | static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \ | ||
1402 | show_fan, set_fan, SYS_FAN_MIN, ix-1); \ | ||
1403 | static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \ | ||
1404 | show_fan, NULL, SYS_FAN_ALARM, ix-1); \ | ||
1405 | static SENSOR_DEVICE_ATTR_2(fan##ix##_max, S_IRUGO | S_IWUSR, \ | ||
1406 | show_fan, set_fan, SYS_FAN_MAX, ix-1) | ||
1407 | |||
1408 | SENSOR_DEVICE_ATTR_FAN_5TO6(5); | ||
1409 | SENSOR_DEVICE_ATTR_FAN_5TO6(6); | ||
1410 | |||
1411 | /* PWMs 1-3 */ | ||
1412 | |||
1413 | #define SENSOR_DEVICE_ATTR_PWM_1TO3(ix) \ | ||
1414 | static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO, \ | ||
1415 | show_pwm, set_pwm, SYS_PWM, ix-1); \ | ||
1416 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO, \ | ||
1417 | show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \ | ||
1418 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \ | ||
1419 | show_pwm, set_pwm, SYS_PWM_ENABLE, ix-1); \ | ||
1420 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_ramp_rate, S_IRUGO, \ | ||
1421 | show_pwm, set_pwm, SYS_PWM_RAMP_RATE, ix-1); \ | ||
1422 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_channels_zone, S_IRUGO, \ | ||
1423 | show_pwm, set_pwm, SYS_PWM_AUTO_CHANNELS_ZONE, ix-1); \ | ||
1424 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_pwm_min, S_IRUGO, \ | ||
1425 | show_pwm, set_pwm, SYS_PWM_AUTO_PWM_MIN, ix-1); \ | ||
1426 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point1_pwm, S_IRUGO, \ | ||
1427 | show_pwm, set_pwm, SYS_PWM_AUTO_POINT1_PWM, ix-1); \ | ||
1428 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point2_pwm, S_IRUGO, \ | ||
1429 | show_pwm, NULL, SYS_PWM_AUTO_POINT2_PWM, ix-1) | ||
1430 | |||
1431 | SENSOR_DEVICE_ATTR_PWM_1TO3(1); | ||
1432 | SENSOR_DEVICE_ATTR_PWM_1TO3(2); | ||
1433 | SENSOR_DEVICE_ATTR_PWM_1TO3(3); | ||
1434 | |||
1435 | /* PWMs 5-6 */ | ||
1436 | |||
1437 | #define SENSOR_DEVICE_ATTR_PWM_5TO6(ix) \ | ||
1438 | static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO | S_IWUSR, \ | ||
1439 | show_pwm, set_pwm, SYS_PWM, ix-1); \ | ||
1440 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO | S_IWUSR, \ | ||
1441 | show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \ | ||
1442 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \ | ||
1443 | show_pwm, NULL, SYS_PWM_ENABLE, ix-1) | ||
1444 | |||
1445 | SENSOR_DEVICE_ATTR_PWM_5TO6(5); | ||
1446 | SENSOR_DEVICE_ATTR_PWM_5TO6(6); | ||
1447 | |||
1448 | /* Misc */ | ||
1449 | |||
1450 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); | ||
1451 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); | ||
1452 | |||
1453 | #define SENSOR_DEV_ATTR_IN(ix) \ | ||
1454 | &sensor_dev_attr_in##ix##_input.dev_attr.attr, \ | ||
1455 | &sensor_dev_attr_in##ix##_min.dev_attr.attr, \ | ||
1456 | &sensor_dev_attr_in##ix##_max.dev_attr.attr, \ | ||
1457 | &sensor_dev_attr_in##ix##_alarm.dev_attr.attr | ||
1458 | |||
1459 | /* These attributes are read-writeable only if the chip is *not* locked */ | ||
1460 | #define SENSOR_DEV_ATTR_TEMP_LOCK(ix) \ | ||
1461 | &sensor_dev_attr_temp##ix##_offset.dev_attr.attr | ||
1462 | |||
1463 | #define SENSOR_DEV_ATTR_TEMP(ix) \ | ||
1464 | SENSOR_DEV_ATTR_TEMP_LOCK(ix), \ | ||
1465 | &sensor_dev_attr_temp##ix##_input.dev_attr.attr, \ | ||
1466 | &sensor_dev_attr_temp##ix##_min.dev_attr.attr, \ | ||
1467 | &sensor_dev_attr_temp##ix##_max.dev_attr.attr, \ | ||
1468 | &sensor_dev_attr_temp##ix##_alarm.dev_attr.attr, \ | ||
1469 | &sensor_dev_attr_temp##ix##_fault.dev_attr.attr | ||
1470 | |||
1471 | /* These attributes are read-writeable only if the chip is *not* locked */ | ||
1472 | #define SENSOR_DEV_ATTR_ZONE_LOCK(ix) \ | ||
1473 | &sensor_dev_attr_zone##ix##_auto_point1_temp_hyst.dev_attr.attr, \ | ||
1474 | &sensor_dev_attr_zone##ix##_auto_point1_temp.dev_attr.attr, \ | ||
1475 | &sensor_dev_attr_zone##ix##_auto_point2_temp.dev_attr.attr, \ | ||
1476 | &sensor_dev_attr_zone##ix##_auto_point3_temp.dev_attr.attr | ||
1477 | |||
1478 | #define SENSOR_DEV_ATTR_ZONE(ix) \ | ||
1479 | SENSOR_DEV_ATTR_ZONE_LOCK(ix), \ | ||
1480 | &sensor_dev_attr_zone##ix##_auto_channels_temp.dev_attr.attr | ||
1481 | |||
1482 | #define SENSOR_DEV_ATTR_FAN_1TO4(ix) \ | ||
1483 | &sensor_dev_attr_fan##ix##_input.dev_attr.attr, \ | ||
1484 | &sensor_dev_attr_fan##ix##_min.dev_attr.attr, \ | ||
1485 | &sensor_dev_attr_fan##ix##_alarm.dev_attr.attr, \ | ||
1486 | &sensor_dev_attr_fan##ix##_type.dev_attr.attr | ||
1487 | |||
1488 | #define SENSOR_DEV_ATTR_FAN_5TO6(ix) \ | ||
1489 | &sensor_dev_attr_fan##ix##_input.dev_attr.attr, \ | ||
1490 | &sensor_dev_attr_fan##ix##_min.dev_attr.attr, \ | ||
1491 | &sensor_dev_attr_fan##ix##_alarm.dev_attr.attr, \ | ||
1492 | &sensor_dev_attr_fan##ix##_max.dev_attr.attr | ||
1493 | |||
1494 | /* These attributes are read-writeable only if the chip is *not* locked */ | ||
1495 | #define SENSOR_DEV_ATTR_PWM_1TO3_LOCK(ix) \ | ||
1496 | &sensor_dev_attr_pwm##ix##_freq.dev_attr.attr, \ | ||
1497 | &sensor_dev_attr_pwm##ix##_enable.dev_attr.attr, \ | ||
1498 | &sensor_dev_attr_pwm##ix##_ramp_rate.dev_attr.attr, \ | ||
1499 | &sensor_dev_attr_pwm##ix##_auto_channels_zone.dev_attr.attr, \ | ||
1500 | &sensor_dev_attr_pwm##ix##_auto_pwm_min.dev_attr.attr, \ | ||
1501 | &sensor_dev_attr_pwm##ix##_auto_point1_pwm.dev_attr.attr | ||
1502 | |||
1503 | #define SENSOR_DEV_ATTR_PWM_1TO3(ix) \ | ||
1504 | SENSOR_DEV_ATTR_PWM_1TO3_LOCK(ix), \ | ||
1505 | &sensor_dev_attr_pwm##ix.dev_attr.attr, \ | ||
1506 | &sensor_dev_attr_pwm##ix##_auto_point2_pwm.dev_attr.attr | ||
1507 | |||
1508 | /* These attributes are read-writeable only if the chip is *not* locked */ | ||
1509 | #define SENSOR_DEV_ATTR_PWM_5TO6_LOCK(ix) \ | ||
1510 | &sensor_dev_attr_pwm##ix.dev_attr.attr, \ | ||
1511 | &sensor_dev_attr_pwm##ix##_freq.dev_attr.attr | ||
1512 | |||
1513 | #define SENSOR_DEV_ATTR_PWM_5TO6(ix) \ | ||
1514 | SENSOR_DEV_ATTR_PWM_5TO6_LOCK(ix), \ | ||
1515 | &sensor_dev_attr_pwm##ix##_enable.dev_attr.attr | ||
1516 | |||
1517 | /* This struct holds all the attributes that are always present and need to be | ||
1518 | * created unconditionally. The attributes that need modification of their | ||
1519 | * permissions are created read-only and write permissions are added or removed | ||
1520 | * on the fly when required */ | ||
1521 | static struct attribute *dme1737_attr[] ={ | ||
1522 | /* Voltages */ | ||
1523 | SENSOR_DEV_ATTR_IN(0), | ||
1524 | SENSOR_DEV_ATTR_IN(1), | ||
1525 | SENSOR_DEV_ATTR_IN(2), | ||
1526 | SENSOR_DEV_ATTR_IN(3), | ||
1527 | SENSOR_DEV_ATTR_IN(4), | ||
1528 | SENSOR_DEV_ATTR_IN(5), | ||
1529 | SENSOR_DEV_ATTR_IN(6), | ||
1530 | /* Temperatures */ | ||
1531 | SENSOR_DEV_ATTR_TEMP(1), | ||
1532 | SENSOR_DEV_ATTR_TEMP(2), | ||
1533 | SENSOR_DEV_ATTR_TEMP(3), | ||
1534 | /* Zones */ | ||
1535 | SENSOR_DEV_ATTR_ZONE(1), | ||
1536 | SENSOR_DEV_ATTR_ZONE(2), | ||
1537 | SENSOR_DEV_ATTR_ZONE(3), | ||
1538 | /* Misc */ | ||
1539 | &dev_attr_vrm.attr, | ||
1540 | &dev_attr_cpu0_vid.attr, | ||
1541 | NULL | ||
1542 | }; | ||
1543 | |||
1544 | static const struct attribute_group dme1737_group = { | ||
1545 | .attrs = dme1737_attr, | ||
1546 | }; | ||
1547 | |||
1548 | /* The following structs hold the PWM attributes, some of which are optional. | ||
1549 | * Their creation depends on the chip configuration which is determined during | ||
1550 | * module load. */ | ||
1551 | static struct attribute *dme1737_attr_pwm1[] = { | ||
1552 | SENSOR_DEV_ATTR_PWM_1TO3(1), | ||
1553 | NULL | ||
1554 | }; | ||
1555 | static struct attribute *dme1737_attr_pwm2[] = { | ||
1556 | SENSOR_DEV_ATTR_PWM_1TO3(2), | ||
1557 | NULL | ||
1558 | }; | ||
1559 | static struct attribute *dme1737_attr_pwm3[] = { | ||
1560 | SENSOR_DEV_ATTR_PWM_1TO3(3), | ||
1561 | NULL | ||
1562 | }; | ||
1563 | static struct attribute *dme1737_attr_pwm5[] = { | ||
1564 | SENSOR_DEV_ATTR_PWM_5TO6(5), | ||
1565 | NULL | ||
1566 | }; | ||
1567 | static struct attribute *dme1737_attr_pwm6[] = { | ||
1568 | SENSOR_DEV_ATTR_PWM_5TO6(6), | ||
1569 | NULL | ||
1570 | }; | ||
1571 | |||
1572 | static const struct attribute_group dme1737_pwm_group[] = { | ||
1573 | { .attrs = dme1737_attr_pwm1 }, | ||
1574 | { .attrs = dme1737_attr_pwm2 }, | ||
1575 | { .attrs = dme1737_attr_pwm3 }, | ||
1576 | { .attrs = NULL }, | ||
1577 | { .attrs = dme1737_attr_pwm5 }, | ||
1578 | { .attrs = dme1737_attr_pwm6 }, | ||
1579 | }; | ||
1580 | |||
1581 | /* The following structs hold the fan attributes, some of which are optional. | ||
1582 | * Their creation depends on the chip configuration which is determined during | ||
1583 | * module load. */ | ||
1584 | static struct attribute *dme1737_attr_fan1[] = { | ||
1585 | SENSOR_DEV_ATTR_FAN_1TO4(1), | ||
1586 | NULL | ||
1587 | }; | ||
1588 | static struct attribute *dme1737_attr_fan2[] = { | ||
1589 | SENSOR_DEV_ATTR_FAN_1TO4(2), | ||
1590 | NULL | ||
1591 | }; | ||
1592 | static struct attribute *dme1737_attr_fan3[] = { | ||
1593 | SENSOR_DEV_ATTR_FAN_1TO4(3), | ||
1594 | NULL | ||
1595 | }; | ||
1596 | static struct attribute *dme1737_attr_fan4[] = { | ||
1597 | SENSOR_DEV_ATTR_FAN_1TO4(4), | ||
1598 | NULL | ||
1599 | }; | ||
1600 | static struct attribute *dme1737_attr_fan5[] = { | ||
1601 | SENSOR_DEV_ATTR_FAN_5TO6(5), | ||
1602 | NULL | ||
1603 | }; | ||
1604 | static struct attribute *dme1737_attr_fan6[] = { | ||
1605 | SENSOR_DEV_ATTR_FAN_5TO6(6), | ||
1606 | NULL | ||
1607 | }; | ||
1608 | |||
1609 | static const struct attribute_group dme1737_fan_group[] = { | ||
1610 | { .attrs = dme1737_attr_fan1 }, | ||
1611 | { .attrs = dme1737_attr_fan2 }, | ||
1612 | { .attrs = dme1737_attr_fan3 }, | ||
1613 | { .attrs = dme1737_attr_fan4 }, | ||
1614 | { .attrs = dme1737_attr_fan5 }, | ||
1615 | { .attrs = dme1737_attr_fan6 }, | ||
1616 | }; | ||
1617 | |||
1618 | /* The permissions of all of the following attributes are changed to read- | ||
1619 | * writeable if the chip is *not* locked. Otherwise they stay read-only. */ | ||
1620 | static struct attribute *dme1737_attr_lock[] = { | ||
1621 | /* Temperatures */ | ||
1622 | SENSOR_DEV_ATTR_TEMP_LOCK(1), | ||
1623 | SENSOR_DEV_ATTR_TEMP_LOCK(2), | ||
1624 | SENSOR_DEV_ATTR_TEMP_LOCK(3), | ||
1625 | /* Zones */ | ||
1626 | SENSOR_DEV_ATTR_ZONE_LOCK(1), | ||
1627 | SENSOR_DEV_ATTR_ZONE_LOCK(2), | ||
1628 | SENSOR_DEV_ATTR_ZONE_LOCK(3), | ||
1629 | NULL | ||
1630 | }; | ||
1631 | |||
1632 | static const struct attribute_group dme1737_lock_group = { | ||
1633 | .attrs = dme1737_attr_lock, | ||
1634 | }; | ||
1635 | |||
1636 | /* The permissions of the following PWM attributes are changed to read- | ||
1637 | * writeable if the chip is *not* locked and the respective PWM is available. | ||
1638 | * Otherwise they stay read-only. */ | ||
1639 | static struct attribute *dme1737_attr_pwm1_lock[] = { | ||
1640 | SENSOR_DEV_ATTR_PWM_1TO3_LOCK(1), | ||
1641 | NULL | ||
1642 | }; | ||
1643 | static struct attribute *dme1737_attr_pwm2_lock[] = { | ||
1644 | SENSOR_DEV_ATTR_PWM_1TO3_LOCK(2), | ||
1645 | NULL | ||
1646 | }; | ||
1647 | static struct attribute *dme1737_attr_pwm3_lock[] = { | ||
1648 | SENSOR_DEV_ATTR_PWM_1TO3_LOCK(3), | ||
1649 | NULL | ||
1650 | }; | ||
1651 | static struct attribute *dme1737_attr_pwm5_lock[] = { | ||
1652 | SENSOR_DEV_ATTR_PWM_5TO6_LOCK(5), | ||
1653 | NULL | ||
1654 | }; | ||
1655 | static struct attribute *dme1737_attr_pwm6_lock[] = { | ||
1656 | SENSOR_DEV_ATTR_PWM_5TO6_LOCK(6), | ||
1657 | NULL | ||
1658 | }; | ||
1659 | |||
1660 | static const struct attribute_group dme1737_pwm_lock_group[] = { | ||
1661 | { .attrs = dme1737_attr_pwm1_lock }, | ||
1662 | { .attrs = dme1737_attr_pwm2_lock }, | ||
1663 | { .attrs = dme1737_attr_pwm3_lock }, | ||
1664 | { .attrs = NULL }, | ||
1665 | { .attrs = dme1737_attr_pwm5_lock }, | ||
1666 | { .attrs = dme1737_attr_pwm6_lock }, | ||
1667 | }; | ||
1668 | |||
1669 | /* Pwm[1-3] are read-writeable if the associated pwm is in manual mode and the | ||
1670 | * chip is not locked. Otherwise they are read-only. */ | ||
1671 | static struct attribute *dme1737_attr_pwm[] = { | ||
1672 | &sensor_dev_attr_pwm1.dev_attr.attr, | ||
1673 | &sensor_dev_attr_pwm2.dev_attr.attr, | ||
1674 | &sensor_dev_attr_pwm3.dev_attr.attr, | ||
1675 | }; | ||
1676 | |||
1677 | /* --------------------------------------------------------------------- | ||
1678 | * Super-IO functions | ||
1679 | * --------------------------------------------------------------------- */ | ||
1680 | |||
1681 | static inline int dme1737_sio_inb(int sio_cip, int reg) | ||
1682 | { | ||
1683 | outb(reg, sio_cip); | ||
1684 | return inb(sio_cip + 1); | ||
1685 | } | ||
1686 | |||
1687 | static inline void dme1737_sio_outb(int sio_cip, int reg, int val) | ||
1688 | { | ||
1689 | outb(reg, sio_cip); | ||
1690 | outb(val, sio_cip + 1); | ||
1691 | } | ||
1692 | |||
1693 | static int dme1737_sio_get_features(int sio_cip, struct i2c_client *client) | ||
1694 | { | ||
1695 | struct dme1737_data *data = i2c_get_clientdata(client); | ||
1696 | int err = 0, reg; | ||
1697 | u16 addr; | ||
1698 | |||
1699 | /* Enter configuration mode */ | ||
1700 | outb(0x55, sio_cip); | ||
1701 | |||
1702 | /* Check device ID | ||
1703 | * The DME1737 can return either 0x78 or 0x77 as its device ID. */ | ||
1704 | reg = dme1737_sio_inb(sio_cip, 0x20); | ||
1705 | if (!(reg == 0x77 || reg == 0x78)) { | ||
1706 | err = -ENODEV; | ||
1707 | goto exit; | ||
1708 | } | ||
1709 | |||
1710 | /* Select logical device A (runtime registers) */ | ||
1711 | dme1737_sio_outb(sio_cip, 0x07, 0x0a); | ||
1712 | |||
1713 | /* Get the base address of the runtime registers */ | ||
1714 | if (!(addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) | | ||
1715 | dme1737_sio_inb(sio_cip, 0x61))) { | ||
1716 | err = -ENODEV; | ||
1717 | goto exit; | ||
1718 | } | ||
1719 | |||
1720 | /* Read the runtime registers to determine which optional features | ||
1721 | * are enabled and available. Bits [3:2] of registers 0x43-0x46 are set | ||
1722 | * to '10' if the respective feature is enabled. */ | ||
1723 | if ((inb(addr + 0x43) & 0x0c) == 0x08) { /* fan6 */ | ||
1724 | data->has_fan |= (1 << 5); | ||
1725 | } | ||
1726 | if ((inb(addr + 0x44) & 0x0c) == 0x08) { /* pwm6 */ | ||
1727 | data->has_pwm |= (1 << 5); | ||
1728 | } | ||
1729 | if ((inb(addr + 0x45) & 0x0c) == 0x08) { /* fan5 */ | ||
1730 | data->has_fan |= (1 << 4); | ||
1731 | } | ||
1732 | if ((inb(addr + 0x46) & 0x0c) == 0x08) { /* pwm5 */ | ||
1733 | data->has_pwm |= (1 << 4); | ||
1734 | } | ||
1735 | |||
1736 | exit: | ||
1737 | /* Exit configuration mode */ | ||
1738 | outb(0xaa, sio_cip); | ||
1739 | |||
1740 | return err; | ||
1741 | } | ||
1742 | |||
1743 | /* --------------------------------------------------------------------- | ||
1744 | * Device detection, registration and initialization | ||
1745 | * --------------------------------------------------------------------- */ | ||
1746 | |||
1747 | static struct i2c_driver dme1737_driver; | ||
1748 | |||
1749 | static void dme1737_chmod_file(struct i2c_client *client, | ||
1750 | struct attribute *attr, mode_t mode) | ||
1751 | { | ||
1752 | if (sysfs_chmod_file(&client->dev.kobj, attr, mode)) { | ||
1753 | dev_warn(&client->dev, "Failed to change permissions of %s.\n", | ||
1754 | attr->name); | ||
1755 | } | ||
1756 | } | ||
1757 | |||
1758 | static void dme1737_chmod_group(struct i2c_client *client, | ||
1759 | const struct attribute_group *group, | ||
1760 | mode_t mode) | ||
1761 | { | ||
1762 | struct attribute **attr; | ||
1763 | |||
1764 | for (attr = group->attrs; *attr; attr++) { | ||
1765 | dme1737_chmod_file(client, *attr, mode); | ||
1766 | } | ||
1767 | } | ||
1768 | |||
1769 | static int dme1737_init_client(struct i2c_client *client) | ||
1770 | { | ||
1771 | struct dme1737_data *data = i2c_get_clientdata(client); | ||
1772 | int ix; | ||
1773 | u8 reg; | ||
1774 | |||
1775 | data->config = dme1737_read(client, DME1737_REG_CONFIG); | ||
1776 | /* Inform if part is not monitoring/started */ | ||
1777 | if (!(data->config & 0x01)) { | ||
1778 | if (!force_start) { | ||
1779 | dev_err(&client->dev, "Device is not monitoring. " | ||
1780 | "Use the force_start load parameter to " | ||
1781 | "override.\n"); | ||
1782 | return -EFAULT; | ||
1783 | } | ||
1784 | |||
1785 | /* Force monitoring */ | ||
1786 | data->config |= 0x01; | ||
1787 | dme1737_write(client, DME1737_REG_CONFIG, data->config); | ||
1788 | } | ||
1789 | /* Inform if part is not ready */ | ||
1790 | if (!(data->config & 0x04)) { | ||
1791 | dev_err(&client->dev, "Device is not ready.\n"); | ||
1792 | return -EFAULT; | ||
1793 | } | ||
1794 | |||
1795 | data->config2 = dme1737_read(client, DME1737_REG_CONFIG2); | ||
1796 | /* Check if optional fan3 input is enabled */ | ||
1797 | if (data->config2 & 0x04) { | ||
1798 | data->has_fan |= (1 << 2); | ||
1799 | } | ||
1800 | |||
1801 | /* Fan4 and pwm3 are only available if the client's I2C address | ||
1802 | * is the default 0x2e. Otherwise the I/Os associated with these | ||
1803 | * functions are used for addr enable/select. */ | ||
1804 | if (client->addr == 0x2e) { | ||
1805 | data->has_fan |= (1 << 3); | ||
1806 | data->has_pwm |= (1 << 2); | ||
1807 | } | ||
1808 | |||
1809 | /* Determine if the optional fan[5-6] and/or pwm[5-6] are enabled. | ||
1810 | * For this, we need to query the runtime registers through the | ||
1811 | * Super-IO LPC interface. Try both config ports 0x2e and 0x4e. */ | ||
1812 | if (dme1737_sio_get_features(0x2e, client) && | ||
1813 | dme1737_sio_get_features(0x4e, client)) { | ||
1814 | dev_warn(&client->dev, "Failed to query Super-IO for optional " | ||
1815 | "features.\n"); | ||
1816 | } | ||
1817 | |||
1818 | /* Fan1, fan2, pwm1, and pwm2 are always present */ | ||
1819 | data->has_fan |= 0x03; | ||
1820 | data->has_pwm |= 0x03; | ||
1821 | |||
1822 | dev_info(&client->dev, "Optional features: pwm3=%s, pwm5=%s, pwm6=%s, " | ||
1823 | "fan3=%s, fan4=%s, fan5=%s, fan6=%s.\n", | ||
1824 | (data->has_pwm & (1 << 2)) ? "yes" : "no", | ||
1825 | (data->has_pwm & (1 << 4)) ? "yes" : "no", | ||
1826 | (data->has_pwm & (1 << 5)) ? "yes" : "no", | ||
1827 | (data->has_fan & (1 << 2)) ? "yes" : "no", | ||
1828 | (data->has_fan & (1 << 3)) ? "yes" : "no", | ||
1829 | (data->has_fan & (1 << 4)) ? "yes" : "no", | ||
1830 | (data->has_fan & (1 << 5)) ? "yes" : "no"); | ||
1831 | |||
1832 | reg = dme1737_read(client, DME1737_REG_TACH_PWM); | ||
1833 | /* Inform if fan-to-pwm mapping differs from the default */ | ||
1834 | if (reg != 0xa4) { | ||
1835 | dev_warn(&client->dev, "Non-standard fan to pwm mapping: " | ||
1836 | "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, " | ||
1837 | "fan4->pwm%d. Please report to the driver " | ||
1838 | "maintainer.\n", | ||
1839 | (reg & 0x03) + 1, ((reg >> 2) & 0x03) + 1, | ||
1840 | ((reg >> 4) & 0x03) + 1, ((reg >> 6) & 0x03) + 1); | ||
1841 | } | ||
1842 | |||
1843 | /* Switch pwm[1-3] to manual mode if they are currently disabled and | ||
1844 | * set the duty-cycles to 0% (which is identical to the PWMs being | ||
1845 | * disabled). */ | ||
1846 | if (!(data->config & 0x02)) { | ||
1847 | for (ix = 0; ix < 3; ix++) { | ||
1848 | data->pwm_config[ix] = dme1737_read(client, | ||
1849 | DME1737_REG_PWM_CONFIG(ix)); | ||
1850 | if ((data->has_pwm & (1 << ix)) && | ||
1851 | (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) { | ||
1852 | dev_info(&client->dev, "Switching pwm%d to " | ||
1853 | "manual mode.\n", ix + 1); | ||
1854 | data->pwm_config[ix] = PWM_EN_TO_REG(1, | ||
1855 | data->pwm_config[ix]); | ||
1856 | dme1737_write(client, DME1737_REG_PWM(ix), 0); | ||
1857 | dme1737_write(client, | ||
1858 | DME1737_REG_PWM_CONFIG(ix), | ||
1859 | data->pwm_config[ix]); | ||
1860 | } | ||
1861 | } | ||
1862 | } | ||
1863 | |||
1864 | /* Initialize the default PWM auto channels zone (acz) assignments */ | ||
1865 | data->pwm_acz[0] = 1; /* pwm1 -> zone1 */ | ||
1866 | data->pwm_acz[1] = 2; /* pwm2 -> zone2 */ | ||
1867 | data->pwm_acz[2] = 4; /* pwm3 -> zone3 */ | ||
1868 | |||
1869 | /* Set VRM */ | ||
1870 | data->vrm = vid_which_vrm(); | ||
1871 | |||
1872 | return 0; | ||
1873 | } | ||
1874 | |||
1875 | static int dme1737_detect(struct i2c_adapter *adapter, int address, | ||
1876 | int kind) | ||
1877 | { | ||
1878 | u8 company, verstep = 0; | ||
1879 | struct i2c_client *client; | ||
1880 | struct dme1737_data *data; | ||
1881 | int ix, err = 0; | ||
1882 | const char *name; | ||
1883 | |||
1884 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | ||
1885 | goto exit; | ||
1886 | } | ||
1887 | |||
1888 | if (!(data = kzalloc(sizeof(struct dme1737_data), GFP_KERNEL))) { | ||
1889 | err = -ENOMEM; | ||
1890 | goto exit; | ||
1891 | } | ||
1892 | |||
1893 | client = &data->client; | ||
1894 | i2c_set_clientdata(client, data); | ||
1895 | client->addr = address; | ||
1896 | client->adapter = adapter; | ||
1897 | client->driver = &dme1737_driver; | ||
1898 | |||
1899 | /* A negative kind means that the driver was loaded with no force | ||
1900 | * parameter (default), so we must identify the chip. */ | ||
1901 | if (kind < 0) { | ||
1902 | company = dme1737_read(client, DME1737_REG_COMPANY); | ||
1903 | verstep = dme1737_read(client, DME1737_REG_VERSTEP); | ||
1904 | |||
1905 | if (!((company == DME1737_COMPANY_SMSC) && | ||
1906 | ((verstep & DME1737_VERSTEP_MASK) == DME1737_VERSTEP))) { | ||
1907 | err = -ENODEV; | ||
1908 | goto exit_kfree; | ||
1909 | } | ||
1910 | } | ||
1911 | |||
1912 | kind = dme1737; | ||
1913 | name = "dme1737"; | ||
1914 | |||
1915 | /* Fill in the remaining client fields and put it into the global | ||
1916 | * list */ | ||
1917 | strlcpy(client->name, name, I2C_NAME_SIZE); | ||
1918 | mutex_init(&data->update_lock); | ||
1919 | |||
1920 | /* Tell the I2C layer a new client has arrived */ | ||
1921 | if ((err = i2c_attach_client(client))) { | ||
1922 | goto exit_kfree; | ||
1923 | } | ||
1924 | |||
1925 | /* Initialize the DME1737 chip */ | ||
1926 | if ((err = dme1737_init_client(client))) { | ||
1927 | goto exit_detach; | ||
1928 | } | ||
1929 | |||
1930 | /* Create standard sysfs attributes */ | ||
1931 | if ((err = sysfs_create_group(&client->dev.kobj, &dme1737_group))) { | ||
1932 | goto exit_detach; | ||
1933 | } | ||
1934 | |||
1935 | /* Create fan sysfs attributes */ | ||
1936 | for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { | ||
1937 | if (data->has_fan & (1 << ix)) { | ||
1938 | if ((err = sysfs_create_group(&client->dev.kobj, | ||
1939 | &dme1737_fan_group[ix]))) { | ||
1940 | goto exit_remove; | ||
1941 | } | ||
1942 | } | ||
1943 | } | ||
1944 | |||
1945 | /* Create PWM sysfs attributes */ | ||
1946 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { | ||
1947 | if (data->has_pwm & (1 << ix)) { | ||
1948 | if ((err = sysfs_create_group(&client->dev.kobj, | ||
1949 | &dme1737_pwm_group[ix]))) { | ||
1950 | goto exit_remove; | ||
1951 | } | ||
1952 | } | ||
1953 | } | ||
1954 | |||
1955 | /* Inform if the device is locked. Otherwise change the permissions of | ||
1956 | * selected attributes from read-only to read-writeable. */ | ||
1957 | if (data->config & 0x02) { | ||
1958 | dev_info(&client->dev, "Device is locked. Some attributes " | ||
1959 | "will be read-only.\n"); | ||
1960 | } else { | ||
1961 | /* Change permissions of standard attributes */ | ||
1962 | dme1737_chmod_group(client, &dme1737_lock_group, | ||
1963 | S_IRUGO | S_IWUSR); | ||
1964 | |||
1965 | /* Change permissions of PWM attributes */ | ||
1966 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_lock_group); ix++) { | ||
1967 | if (data->has_pwm & (1 << ix)) { | ||
1968 | dme1737_chmod_group(client, | ||
1969 | &dme1737_pwm_lock_group[ix], | ||
1970 | S_IRUGO | S_IWUSR); | ||
1971 | } | ||
1972 | } | ||
1973 | |||
1974 | /* Change permissions of pwm[1-3] if in manual mode */ | ||
1975 | for (ix = 0; ix < 3; ix++) { | ||
1976 | if ((data->has_pwm & (1 << ix)) && | ||
1977 | (PWM_EN_FROM_REG(data->pwm_config[ix]) == 1)) { | ||
1978 | dme1737_chmod_file(client, | ||
1979 | dme1737_attr_pwm[ix], | ||
1980 | S_IRUGO | S_IWUSR); | ||
1981 | } | ||
1982 | } | ||
1983 | } | ||
1984 | |||
1985 | /* Register device */ | ||
1986 | data->class_dev = hwmon_device_register(&client->dev); | ||
1987 | if (IS_ERR(data->class_dev)) { | ||
1988 | err = PTR_ERR(data->class_dev); | ||
1989 | goto exit_remove; | ||
1990 | } | ||
1991 | |||
1992 | dev_info(&adapter->dev, "Found a DME1737 chip at 0x%02x " | ||
1993 | "(rev 0x%02x)\n", client->addr, verstep); | ||
1994 | |||
1995 | return 0; | ||
1996 | |||
1997 | exit_remove: | ||
1998 | for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { | ||
1999 | if (data->has_fan & (1 << ix)) { | ||
2000 | sysfs_remove_group(&client->dev.kobj, | ||
2001 | &dme1737_fan_group[ix]); | ||
2002 | } | ||
2003 | } | ||
2004 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { | ||
2005 | if (data->has_pwm & (1 << ix)) { | ||
2006 | sysfs_remove_group(&client->dev.kobj, | ||
2007 | &dme1737_pwm_group[ix]); | ||
2008 | } | ||
2009 | } | ||
2010 | sysfs_remove_group(&client->dev.kobj, &dme1737_group); | ||
2011 | exit_detach: | ||
2012 | i2c_detach_client(client); | ||
2013 | exit_kfree: | ||
2014 | kfree(data); | ||
2015 | exit: | ||
2016 | return err; | ||
2017 | } | ||
2018 | |||
2019 | static int dme1737_attach_adapter(struct i2c_adapter *adapter) | ||
2020 | { | ||
2021 | if (!(adapter->class & I2C_CLASS_HWMON)) { | ||
2022 | return 0; | ||
2023 | } | ||
2024 | |||
2025 | return i2c_probe(adapter, &addr_data, dme1737_detect); | ||
2026 | } | ||
2027 | |||
2028 | static int dme1737_detach_client(struct i2c_client *client) | ||
2029 | { | ||
2030 | struct dme1737_data *data = i2c_get_clientdata(client); | ||
2031 | int ix, err; | ||
2032 | |||
2033 | hwmon_device_unregister(data->class_dev); | ||
2034 | |||
2035 | for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { | ||
2036 | if (data->has_fan & (1 << ix)) { | ||
2037 | sysfs_remove_group(&client->dev.kobj, | ||
2038 | &dme1737_fan_group[ix]); | ||
2039 | } | ||
2040 | } | ||
2041 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { | ||
2042 | if (data->has_pwm & (1 << ix)) { | ||
2043 | sysfs_remove_group(&client->dev.kobj, | ||
2044 | &dme1737_pwm_group[ix]); | ||
2045 | } | ||
2046 | } | ||
2047 | sysfs_remove_group(&client->dev.kobj, &dme1737_group); | ||
2048 | |||
2049 | if ((err = i2c_detach_client(client))) { | ||
2050 | return err; | ||
2051 | } | ||
2052 | |||
2053 | kfree(data); | ||
2054 | return 0; | ||
2055 | } | ||
2056 | |||
2057 | static struct i2c_driver dme1737_driver = { | ||
2058 | .driver = { | ||
2059 | .name = "dme1737", | ||
2060 | }, | ||
2061 | .attach_adapter = dme1737_attach_adapter, | ||
2062 | .detach_client = dme1737_detach_client, | ||
2063 | }; | ||
2064 | |||
2065 | static int __init dme1737_init(void) | ||
2066 | { | ||
2067 | return i2c_add_driver(&dme1737_driver); | ||
2068 | } | ||
2069 | |||
2070 | static void __exit dme1737_exit(void) | ||
2071 | { | ||
2072 | i2c_del_driver(&dme1737_driver); | ||
2073 | } | ||
2074 | |||
2075 | MODULE_AUTHOR("Juerg Haefliger <juergh@gmail.com>"); | ||
2076 | MODULE_DESCRIPTION("DME1737 sensors"); | ||
2077 | MODULE_LICENSE("GPL"); | ||
2078 | |||
2079 | module_init(dme1737_init); | ||
2080 | module_exit(dme1737_exit); | ||
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c index d5ac422d73b2..1212d6b7f316 100644 --- a/drivers/hwmon/ds1621.c +++ b/drivers/hwmon/ds1621.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/jiffies.h> | 27 | #include <linux/jiffies.h> |
28 | #include <linux/i2c.h> | 28 | #include <linux/i2c.h> |
29 | #include <linux/hwmon.h> | 29 | #include <linux/hwmon.h> |
30 | #include <linux/hwmon-sysfs.h> | ||
30 | #include <linux/err.h> | 31 | #include <linux/err.h> |
31 | #include <linux/mutex.h> | 32 | #include <linux/mutex.h> |
32 | #include <linux/sysfs.h> | 33 | #include <linux/sysfs.h> |
@@ -52,9 +53,11 @@ MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low") | |||
52 | #define DS1621_REG_CONFIG_DONE 0x80 | 53 | #define DS1621_REG_CONFIG_DONE 0x80 |
53 | 54 | ||
54 | /* The DS1621 registers */ | 55 | /* The DS1621 registers */ |
55 | #define DS1621_REG_TEMP 0xAA /* word, RO */ | 56 | static const u8 DS1621_REG_TEMP[3] = { |
56 | #define DS1621_REG_TEMP_MIN 0xA2 /* word, RW */ | 57 | 0xAA, /* input, word, RO */ |
57 | #define DS1621_REG_TEMP_MAX 0xA1 /* word, RW */ | 58 | 0xA2, /* min, word, RW */ |
59 | 0xA1, /* max, word, RW */ | ||
60 | }; | ||
58 | #define DS1621_REG_CONF 0xAC /* byte, RW */ | 61 | #define DS1621_REG_CONF 0xAC /* byte, RW */ |
59 | #define DS1621_COM_START 0xEE /* no data */ | 62 | #define DS1621_COM_START 0xEE /* no data */ |
60 | #define DS1621_COM_STOP 0x22 /* no data */ | 63 | #define DS1621_COM_STOP 0x22 /* no data */ |
@@ -63,10 +66,7 @@ MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low") | |||
63 | #define DS1621_ALARM_TEMP_HIGH 0x40 | 66 | #define DS1621_ALARM_TEMP_HIGH 0x40 |
64 | #define DS1621_ALARM_TEMP_LOW 0x20 | 67 | #define DS1621_ALARM_TEMP_LOW 0x20 |
65 | 68 | ||
66 | /* Conversions. Rounding and limit checking is only done on the TO_REG | 69 | /* Conversions */ |
67 | variants. Note that you should be a bit careful with which arguments | ||
68 | these macros are called: arguments may be evaluated more than once. | ||
69 | Fixing this is just not worth it. */ | ||
70 | #define ALARMS_FROM_REG(val) ((val) & \ | 70 | #define ALARMS_FROM_REG(val) ((val) & \ |
71 | (DS1621_ALARM_TEMP_HIGH | DS1621_ALARM_TEMP_LOW)) | 71 | (DS1621_ALARM_TEMP_HIGH | DS1621_ALARM_TEMP_LOW)) |
72 | 72 | ||
@@ -78,7 +78,7 @@ struct ds1621_data { | |||
78 | char valid; /* !=0 if following fields are valid */ | 78 | char valid; /* !=0 if following fields are valid */ |
79 | unsigned long last_updated; /* In jiffies */ | 79 | unsigned long last_updated; /* In jiffies */ |
80 | 80 | ||
81 | u16 temp, temp_min, temp_max; /* Register values, word */ | 81 | u16 temp[3]; /* Register values, word */ |
82 | u8 conf; /* Register encoding, combined */ | 82 | u8 conf; /* Register encoding, combined */ |
83 | }; | 83 | }; |
84 | 84 | ||
@@ -101,7 +101,7 @@ static struct i2c_driver ds1621_driver = { | |||
101 | 101 | ||
102 | /* All registers are word-sized, except for the configuration register. | 102 | /* All registers are word-sized, except for the configuration register. |
103 | DS1621 uses a high-byte first convention, which is exactly opposite to | 103 | DS1621 uses a high-byte first convention, which is exactly opposite to |
104 | the usual practice. */ | 104 | the SMBus standard. */ |
105 | static int ds1621_read_value(struct i2c_client *client, u8 reg) | 105 | static int ds1621_read_value(struct i2c_client *client, u8 reg) |
106 | { | 106 | { |
107 | if (reg == DS1621_REG_CONF) | 107 | if (reg == DS1621_REG_CONF) |
@@ -110,9 +110,6 @@ static int ds1621_read_value(struct i2c_client *client, u8 reg) | |||
110 | return swab16(i2c_smbus_read_word_data(client, reg)); | 110 | return swab16(i2c_smbus_read_word_data(client, reg)); |
111 | } | 111 | } |
112 | 112 | ||
113 | /* All registers are word-sized, except for the configuration register. | ||
114 | DS1621 uses a high-byte first convention, which is exactly opposite to | ||
115 | the usual practice. */ | ||
116 | static int ds1621_write_value(struct i2c_client *client, u8 reg, u16 value) | 113 | static int ds1621_write_value(struct i2c_client *client, u8 reg, u16 value) |
117 | { | 114 | { |
118 | if (reg == DS1621_REG_CONF) | 115 | if (reg == DS1621_REG_CONF) |
@@ -139,50 +136,61 @@ static void ds1621_init_client(struct i2c_client *client) | |||
139 | i2c_smbus_write_byte(client, DS1621_COM_START); | 136 | i2c_smbus_write_byte(client, DS1621_COM_START); |
140 | } | 137 | } |
141 | 138 | ||
142 | #define show(value) \ | 139 | static ssize_t show_temp(struct device *dev, struct device_attribute *da, |
143 | static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \ | 140 | char *buf) |
144 | { \ | 141 | { |
145 | struct ds1621_data *data = ds1621_update_client(dev); \ | 142 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
146 | return sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(data->value)); \ | 143 | struct ds1621_data *data = ds1621_update_client(dev); |
144 | return sprintf(buf, "%d\n", | ||
145 | LM75_TEMP_FROM_REG(data->temp[attr->index])); | ||
147 | } | 146 | } |
148 | 147 | ||
149 | show(temp); | 148 | static ssize_t set_temp(struct device *dev, struct device_attribute *da, |
150 | show(temp_min); | 149 | const char *buf, size_t count) |
151 | show(temp_max); | 150 | { |
152 | 151 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | |
153 | #define set_temp(suffix, value, reg) \ | 152 | struct i2c_client *client = to_i2c_client(dev); |
154 | static ssize_t set_temp_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \ | 153 | struct ds1621_data *data = ds1621_update_client(dev); |
155 | size_t count) \ | 154 | u16 val = LM75_TEMP_TO_REG(simple_strtoul(buf, NULL, 10)); |
156 | { \ | ||
157 | struct i2c_client *client = to_i2c_client(dev); \ | ||
158 | struct ds1621_data *data = ds1621_update_client(dev); \ | ||
159 | u16 val = LM75_TEMP_TO_REG(simple_strtoul(buf, NULL, 10)); \ | ||
160 | \ | ||
161 | mutex_lock(&data->update_lock); \ | ||
162 | data->value = val; \ | ||
163 | ds1621_write_value(client, reg, data->value); \ | ||
164 | mutex_unlock(&data->update_lock); \ | ||
165 | return count; \ | ||
166 | } | ||
167 | 155 | ||
168 | set_temp(min, temp_min, DS1621_REG_TEMP_MIN); | 156 | mutex_lock(&data->update_lock); |
169 | set_temp(max, temp_max, DS1621_REG_TEMP_MAX); | 157 | data->temp[attr->index] = val; |
158 | ds1621_write_value(client, DS1621_REG_TEMP[attr->index], | ||
159 | data->temp[attr->index]); | ||
160 | mutex_unlock(&data->update_lock); | ||
161 | return count; | ||
162 | } | ||
170 | 163 | ||
171 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) | 164 | static ssize_t show_alarms(struct device *dev, struct device_attribute *da, |
165 | char *buf) | ||
172 | { | 166 | { |
173 | struct ds1621_data *data = ds1621_update_client(dev); | 167 | struct ds1621_data *data = ds1621_update_client(dev); |
174 | return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->conf)); | 168 | return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->conf)); |
175 | } | 169 | } |
176 | 170 | ||
171 | static ssize_t show_alarm(struct device *dev, struct device_attribute *da, | ||
172 | char *buf) | ||
173 | { | ||
174 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
175 | struct ds1621_data *data = ds1621_update_client(dev); | ||
176 | return sprintf(buf, "%d\n", !!(data->conf & attr->index)); | ||
177 | } | ||
178 | |||
177 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 179 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
178 | static DEVICE_ATTR(temp1_input, S_IRUGO , show_temp, NULL); | 180 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); |
179 | static DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO , show_temp_min, set_temp_min); | 181 | static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, 1); |
180 | static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max); | 182 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, 2); |
183 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, | ||
184 | DS1621_ALARM_TEMP_LOW); | ||
185 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, | ||
186 | DS1621_ALARM_TEMP_HIGH); | ||
181 | 187 | ||
182 | static struct attribute *ds1621_attributes[] = { | 188 | static struct attribute *ds1621_attributes[] = { |
183 | &dev_attr_temp1_input.attr, | 189 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
184 | &dev_attr_temp1_min.attr, | 190 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
185 | &dev_attr_temp1_max.attr, | 191 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
192 | &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, | ||
193 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, | ||
186 | &dev_attr_alarms.attr, | 194 | &dev_attr_alarms.attr, |
187 | NULL | 195 | NULL |
188 | }; | 196 | }; |
@@ -204,9 +212,9 @@ static int ds1621_detect(struct i2c_adapter *adapter, int address, | |||
204 | int kind) | 212 | int kind) |
205 | { | 213 | { |
206 | int conf, temp; | 214 | int conf, temp; |
207 | struct i2c_client *new_client; | 215 | struct i2c_client *client; |
208 | struct ds1621_data *data; | 216 | struct ds1621_data *data; |
209 | int err = 0; | 217 | int i, err = 0; |
210 | 218 | ||
211 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 219 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
212 | | I2C_FUNC_SMBUS_WORD_DATA | 220 | | I2C_FUNC_SMBUS_WORD_DATA |
@@ -221,55 +229,44 @@ static int ds1621_detect(struct i2c_adapter *adapter, int address, | |||
221 | goto exit; | 229 | goto exit; |
222 | } | 230 | } |
223 | 231 | ||
224 | new_client = &data->client; | 232 | client = &data->client; |
225 | i2c_set_clientdata(new_client, data); | 233 | i2c_set_clientdata(client, data); |
226 | new_client->addr = address; | 234 | client->addr = address; |
227 | new_client->adapter = adapter; | 235 | client->adapter = adapter; |
228 | new_client->driver = &ds1621_driver; | 236 | client->driver = &ds1621_driver; |
229 | new_client->flags = 0; | ||
230 | |||
231 | 237 | ||
232 | /* Now, we do the remaining detection. It is lousy. */ | 238 | /* Now, we do the remaining detection. It is lousy. */ |
233 | if (kind < 0) { | 239 | if (kind < 0) { |
234 | /* The NVB bit should be low if no EEPROM write has been | 240 | /* The NVB bit should be low if no EEPROM write has been |
235 | requested during the latest 10ms, which is highly | 241 | requested during the latest 10ms, which is highly |
236 | improbable in our case. */ | 242 | improbable in our case. */ |
237 | conf = ds1621_read_value(new_client, DS1621_REG_CONF); | 243 | conf = ds1621_read_value(client, DS1621_REG_CONF); |
238 | if (conf & DS1621_REG_CONFIG_NVB) | 244 | if (conf & DS1621_REG_CONFIG_NVB) |
239 | goto exit_free; | 245 | goto exit_free; |
240 | /* The 7 lowest bits of a temperature should always be 0. */ | 246 | /* The 7 lowest bits of a temperature should always be 0. */ |
241 | temp = ds1621_read_value(new_client, DS1621_REG_TEMP); | 247 | for (i = 0; i < ARRAY_SIZE(data->temp); i++) { |
242 | if (temp & 0x007f) | 248 | temp = ds1621_read_value(client, DS1621_REG_TEMP[i]); |
243 | goto exit_free; | 249 | if (temp & 0x007f) |
244 | temp = ds1621_read_value(new_client, DS1621_REG_TEMP_MIN); | 250 | goto exit_free; |
245 | if (temp & 0x007f) | 251 | } |
246 | goto exit_free; | ||
247 | temp = ds1621_read_value(new_client, DS1621_REG_TEMP_MAX); | ||
248 | if (temp & 0x007f) | ||
249 | goto exit_free; | ||
250 | } | 252 | } |
251 | 253 | ||
252 | /* Determine the chip type - only one kind supported! */ | ||
253 | if (kind <= 0) | ||
254 | kind = ds1621; | ||
255 | |||
256 | /* Fill in remaining client fields and put it into the global list */ | 254 | /* Fill in remaining client fields and put it into the global list */ |
257 | strlcpy(new_client->name, "ds1621", I2C_NAME_SIZE); | 255 | strlcpy(client->name, "ds1621", I2C_NAME_SIZE); |
258 | data->valid = 0; | ||
259 | mutex_init(&data->update_lock); | 256 | mutex_init(&data->update_lock); |
260 | 257 | ||
261 | /* Tell the I2C layer a new client has arrived */ | 258 | /* Tell the I2C layer a new client has arrived */ |
262 | if ((err = i2c_attach_client(new_client))) | 259 | if ((err = i2c_attach_client(client))) |
263 | goto exit_free; | 260 | goto exit_free; |
264 | 261 | ||
265 | /* Initialize the DS1621 chip */ | 262 | /* Initialize the DS1621 chip */ |
266 | ds1621_init_client(new_client); | 263 | ds1621_init_client(client); |
267 | 264 | ||
268 | /* Register sysfs hooks */ | 265 | /* Register sysfs hooks */ |
269 | if ((err = sysfs_create_group(&new_client->dev.kobj, &ds1621_group))) | 266 | if ((err = sysfs_create_group(&client->dev.kobj, &ds1621_group))) |
270 | goto exit_detach; | 267 | goto exit_detach; |
271 | 268 | ||
272 | data->class_dev = hwmon_device_register(&new_client->dev); | 269 | data->class_dev = hwmon_device_register(&client->dev); |
273 | if (IS_ERR(data->class_dev)) { | 270 | if (IS_ERR(data->class_dev)) { |
274 | err = PTR_ERR(data->class_dev); | 271 | err = PTR_ERR(data->class_dev); |
275 | goto exit_remove_files; | 272 | goto exit_remove_files; |
@@ -278,9 +275,9 @@ static int ds1621_detect(struct i2c_adapter *adapter, int address, | |||
278 | return 0; | 275 | return 0; |
279 | 276 | ||
280 | exit_remove_files: | 277 | exit_remove_files: |
281 | sysfs_remove_group(&new_client->dev.kobj, &ds1621_group); | 278 | sysfs_remove_group(&client->dev.kobj, &ds1621_group); |
282 | exit_detach: | 279 | exit_detach: |
283 | i2c_detach_client(new_client); | 280 | i2c_detach_client(client); |
284 | exit_free: | 281 | exit_free: |
285 | kfree(data); | 282 | kfree(data); |
286 | exit: | 283 | exit: |
@@ -314,23 +311,21 @@ static struct ds1621_data *ds1621_update_client(struct device *dev) | |||
314 | 311 | ||
315 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | 312 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
316 | || !data->valid) { | 313 | || !data->valid) { |
314 | int i; | ||
317 | 315 | ||
318 | dev_dbg(&client->dev, "Starting ds1621 update\n"); | 316 | dev_dbg(&client->dev, "Starting ds1621 update\n"); |
319 | 317 | ||
320 | data->conf = ds1621_read_value(client, DS1621_REG_CONF); | 318 | data->conf = ds1621_read_value(client, DS1621_REG_CONF); |
321 | 319 | ||
322 | data->temp = ds1621_read_value(client, DS1621_REG_TEMP); | 320 | for (i = 0; i < ARRAY_SIZE(data->temp); i++) |
323 | 321 | data->temp[i] = ds1621_read_value(client, | |
324 | data->temp_min = ds1621_read_value(client, | 322 | DS1621_REG_TEMP[i]); |
325 | DS1621_REG_TEMP_MIN); | ||
326 | data->temp_max = ds1621_read_value(client, | ||
327 | DS1621_REG_TEMP_MAX); | ||
328 | 323 | ||
329 | /* reset alarms if necessary */ | 324 | /* reset alarms if necessary */ |
330 | new_conf = data->conf; | 325 | new_conf = data->conf; |
331 | if (data->temp > data->temp_min) | 326 | if (data->temp[0] > data->temp[1]) /* input > min */ |
332 | new_conf &= ~DS1621_ALARM_TEMP_LOW; | 327 | new_conf &= ~DS1621_ALARM_TEMP_LOW; |
333 | if (data->temp < data->temp_max) | 328 | if (data->temp[0] < data->temp[2]) /* input < max */ |
334 | new_conf &= ~DS1621_ALARM_TEMP_HIGH; | 329 | new_conf &= ~DS1621_ALARM_TEMP_HIGH; |
335 | if (data->conf != new_conf) | 330 | if (data->conf != new_conf) |
336 | ds1621_write_value(client, DS1621_REG_CONF, | 331 | ds1621_write_value(client, DS1621_REG_CONF, |
diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c index cdbe309b8fc4..6f60715f34f8 100644 --- a/drivers/hwmon/f71805f.c +++ b/drivers/hwmon/f71805f.c | |||
@@ -127,6 +127,13 @@ superio_exit(int base) | |||
127 | #define F71805F_REG_TEMP_HIGH(nr) (0x54 + 2 * (nr)) | 127 | #define F71805F_REG_TEMP_HIGH(nr) (0x54 + 2 * (nr)) |
128 | #define F71805F_REG_TEMP_HYST(nr) (0x55 + 2 * (nr)) | 128 | #define F71805F_REG_TEMP_HYST(nr) (0x55 + 2 * (nr)) |
129 | #define F71805F_REG_TEMP_MODE 0x01 | 129 | #define F71805F_REG_TEMP_MODE 0x01 |
130 | /* pwm/fan pwmnr from 0 to 2, auto point apnr from 0 to 2 */ | ||
131 | /* map Fintek numbers to our numbers as follows: 9->0, 5->1, 1->2 */ | ||
132 | #define F71805F_REG_PWM_AUTO_POINT_TEMP(pwmnr, apnr) \ | ||
133 | (0xA0 + 0x10 * (pwmnr) + (2 - (apnr))) | ||
134 | #define F71805F_REG_PWM_AUTO_POINT_FAN(pwmnr, apnr) \ | ||
135 | (0xA4 + 0x10 * (pwmnr) + \ | ||
136 | 2 * (2 - (apnr))) | ||
130 | 137 | ||
131 | #define F71805F_REG_START 0x00 | 138 | #define F71805F_REG_START 0x00 |
132 | /* status nr from 0 to 2 */ | 139 | /* status nr from 0 to 2 */ |
@@ -144,6 +151,11 @@ superio_exit(int base) | |||
144 | * Data structures and manipulation thereof | 151 | * Data structures and manipulation thereof |
145 | */ | 152 | */ |
146 | 153 | ||
154 | struct f71805f_auto_point { | ||
155 | u8 temp[3]; | ||
156 | u16 fan[3]; | ||
157 | }; | ||
158 | |||
147 | struct f71805f_data { | 159 | struct f71805f_data { |
148 | unsigned short addr; | 160 | unsigned short addr; |
149 | const char *name; | 161 | const char *name; |
@@ -170,6 +182,7 @@ struct f71805f_data { | |||
170 | u8 temp_hyst[3]; | 182 | u8 temp_hyst[3]; |
171 | u8 temp_mode; | 183 | u8 temp_mode; |
172 | unsigned long alarms; | 184 | unsigned long alarms; |
185 | struct f71805f_auto_point auto_points[3]; | ||
173 | }; | 186 | }; |
174 | 187 | ||
175 | struct f71805f_sio_data { | 188 | struct f71805f_sio_data { |
@@ -312,7 +325,7 @@ static void f71805f_write16(struct f71805f_data *data, u8 reg, u16 val) | |||
312 | static struct f71805f_data *f71805f_update_device(struct device *dev) | 325 | static struct f71805f_data *f71805f_update_device(struct device *dev) |
313 | { | 326 | { |
314 | struct f71805f_data *data = dev_get_drvdata(dev); | 327 | struct f71805f_data *data = dev_get_drvdata(dev); |
315 | int nr; | 328 | int nr, apnr; |
316 | 329 | ||
317 | mutex_lock(&data->update_lock); | 330 | mutex_lock(&data->update_lock); |
318 | 331 | ||
@@ -342,6 +355,18 @@ static struct f71805f_data *f71805f_update_device(struct device *dev) | |||
342 | F71805F_REG_TEMP_HYST(nr)); | 355 | F71805F_REG_TEMP_HYST(nr)); |
343 | } | 356 | } |
344 | data->temp_mode = f71805f_read8(data, F71805F_REG_TEMP_MODE); | 357 | data->temp_mode = f71805f_read8(data, F71805F_REG_TEMP_MODE); |
358 | for (nr = 0; nr < 3; nr++) { | ||
359 | for (apnr = 0; apnr < 3; apnr++) { | ||
360 | data->auto_points[nr].temp[apnr] = | ||
361 | f71805f_read8(data, | ||
362 | F71805F_REG_PWM_AUTO_POINT_TEMP(nr, | ||
363 | apnr)); | ||
364 | data->auto_points[nr].fan[apnr] = | ||
365 | f71805f_read16(data, | ||
366 | F71805F_REG_PWM_AUTO_POINT_FAN(nr, | ||
367 | apnr)); | ||
368 | } | ||
369 | } | ||
345 | 370 | ||
346 | data->last_limits = jiffies; | 371 | data->last_limits = jiffies; |
347 | } | 372 | } |
@@ -705,6 +730,70 @@ static ssize_t set_pwm_freq(struct device *dev, struct device_attribute | |||
705 | return count; | 730 | return count; |
706 | } | 731 | } |
707 | 732 | ||
733 | static ssize_t show_pwm_auto_point_temp(struct device *dev, | ||
734 | struct device_attribute *devattr, | ||
735 | char* buf) | ||
736 | { | ||
737 | struct f71805f_data *data = dev_get_drvdata(dev); | ||
738 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); | ||
739 | int pwmnr = attr->nr; | ||
740 | int apnr = attr->index; | ||
741 | |||
742 | return sprintf(buf, "%ld\n", | ||
743 | temp_from_reg(data->auto_points[pwmnr].temp[apnr])); | ||
744 | } | ||
745 | |||
746 | static ssize_t set_pwm_auto_point_temp(struct device *dev, | ||
747 | struct device_attribute *devattr, | ||
748 | const char* buf, size_t count) | ||
749 | { | ||
750 | struct f71805f_data *data = dev_get_drvdata(dev); | ||
751 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); | ||
752 | int pwmnr = attr->nr; | ||
753 | int apnr = attr->index; | ||
754 | unsigned long val = simple_strtol(buf, NULL, 10); | ||
755 | |||
756 | mutex_lock(&data->update_lock); | ||
757 | data->auto_points[pwmnr].temp[apnr] = temp_to_reg(val); | ||
758 | f71805f_write8(data, F71805F_REG_PWM_AUTO_POINT_TEMP(pwmnr, apnr), | ||
759 | data->auto_points[pwmnr].temp[apnr]); | ||
760 | mutex_unlock(&data->update_lock); | ||
761 | |||
762 | return count; | ||
763 | } | ||
764 | |||
765 | static ssize_t show_pwm_auto_point_fan(struct device *dev, | ||
766 | struct device_attribute *devattr, | ||
767 | char* buf) | ||
768 | { | ||
769 | struct f71805f_data *data = dev_get_drvdata(dev); | ||
770 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); | ||
771 | int pwmnr = attr->nr; | ||
772 | int apnr = attr->index; | ||
773 | |||
774 | return sprintf(buf, "%ld\n", | ||
775 | fan_from_reg(data->auto_points[pwmnr].fan[apnr])); | ||
776 | } | ||
777 | |||
778 | static ssize_t set_pwm_auto_point_fan(struct device *dev, | ||
779 | struct device_attribute *devattr, | ||
780 | const char* buf, size_t count) | ||
781 | { | ||
782 | struct f71805f_data *data = dev_get_drvdata(dev); | ||
783 | struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr); | ||
784 | int pwmnr = attr->nr; | ||
785 | int apnr = attr->index; | ||
786 | unsigned long val = simple_strtoul(buf, NULL, 10); | ||
787 | |||
788 | mutex_lock(&data->update_lock); | ||
789 | data->auto_points[pwmnr].fan[apnr] = fan_to_reg(val); | ||
790 | f71805f_write16(data, F71805F_REG_PWM_AUTO_POINT_FAN(pwmnr, apnr), | ||
791 | data->auto_points[pwmnr].fan[apnr]); | ||
792 | mutex_unlock(&data->update_lock); | ||
793 | |||
794 | return count; | ||
795 | } | ||
796 | |||
708 | static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, | 797 | static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, |
709 | char *buf) | 798 | char *buf) |
710 | { | 799 | { |
@@ -932,6 +1021,63 @@ static SENSOR_DEVICE_ATTR(pwm3_freq, S_IRUGO | S_IWUSR, | |||
932 | show_pwm_freq, set_pwm_freq, 2); | 1021 | show_pwm_freq, set_pwm_freq, 2); |
933 | static SENSOR_DEVICE_ATTR(pwm3_mode, S_IRUGO, show_pwm_mode, NULL, 2); | 1022 | static SENSOR_DEVICE_ATTR(pwm3_mode, S_IRUGO, show_pwm_mode, NULL, 2); |
934 | 1023 | ||
1024 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR, | ||
1025 | show_pwm_auto_point_temp, set_pwm_auto_point_temp, | ||
1026 | 0, 0); | ||
1027 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_fan, S_IRUGO | S_IWUSR, | ||
1028 | show_pwm_auto_point_fan, set_pwm_auto_point_fan, | ||
1029 | 0, 0); | ||
1030 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR, | ||
1031 | show_pwm_auto_point_temp, set_pwm_auto_point_temp, | ||
1032 | 0, 1); | ||
1033 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_fan, S_IRUGO | S_IWUSR, | ||
1034 | show_pwm_auto_point_fan, set_pwm_auto_point_fan, | ||
1035 | 0, 1); | ||
1036 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR, | ||
1037 | show_pwm_auto_point_temp, set_pwm_auto_point_temp, | ||
1038 | 0, 2); | ||
1039 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_fan, S_IRUGO | S_IWUSR, | ||
1040 | show_pwm_auto_point_fan, set_pwm_auto_point_fan, | ||
1041 | 0, 2); | ||
1042 | |||
1043 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR, | ||
1044 | show_pwm_auto_point_temp, set_pwm_auto_point_temp, | ||
1045 | 1, 0); | ||
1046 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_fan, S_IRUGO | S_IWUSR, | ||
1047 | show_pwm_auto_point_fan, set_pwm_auto_point_fan, | ||
1048 | 1, 0); | ||
1049 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR, | ||
1050 | show_pwm_auto_point_temp, set_pwm_auto_point_temp, | ||
1051 | 1, 1); | ||
1052 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_fan, S_IRUGO | S_IWUSR, | ||
1053 | show_pwm_auto_point_fan, set_pwm_auto_point_fan, | ||
1054 | 1, 1); | ||
1055 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR, | ||
1056 | show_pwm_auto_point_temp, set_pwm_auto_point_temp, | ||
1057 | 1, 2); | ||
1058 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_fan, S_IRUGO | S_IWUSR, | ||
1059 | show_pwm_auto_point_fan, set_pwm_auto_point_fan, | ||
1060 | 1, 2); | ||
1061 | |||
1062 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp, S_IRUGO | S_IWUSR, | ||
1063 | show_pwm_auto_point_temp, set_pwm_auto_point_temp, | ||
1064 | 2, 0); | ||
1065 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_fan, S_IRUGO | S_IWUSR, | ||
1066 | show_pwm_auto_point_fan, set_pwm_auto_point_fan, | ||
1067 | 2, 0); | ||
1068 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_temp, S_IRUGO | S_IWUSR, | ||
1069 | show_pwm_auto_point_temp, set_pwm_auto_point_temp, | ||
1070 | 2, 1); | ||
1071 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_fan, S_IRUGO | S_IWUSR, | ||
1072 | show_pwm_auto_point_fan, set_pwm_auto_point_fan, | ||
1073 | 2, 1); | ||
1074 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_temp, S_IRUGO | S_IWUSR, | ||
1075 | show_pwm_auto_point_temp, set_pwm_auto_point_temp, | ||
1076 | 2, 2); | ||
1077 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_fan, S_IRUGO | S_IWUSR, | ||
1078 | show_pwm_auto_point_fan, set_pwm_auto_point_fan, | ||
1079 | 2, 2); | ||
1080 | |||
935 | static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); | 1081 | static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); |
936 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); | 1082 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); |
937 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2); | 1083 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2); |
@@ -1014,6 +1160,25 @@ static struct attribute *f71805f_attributes[] = { | |||
1014 | &sensor_dev_attr_temp3_max_hyst.dev_attr.attr, | 1160 | &sensor_dev_attr_temp3_max_hyst.dev_attr.attr, |
1015 | &sensor_dev_attr_temp3_type.dev_attr.attr, | 1161 | &sensor_dev_attr_temp3_type.dev_attr.attr, |
1016 | 1162 | ||
1163 | &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr, | ||
1164 | &sensor_dev_attr_pwm1_auto_point1_fan.dev_attr.attr, | ||
1165 | &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr, | ||
1166 | &sensor_dev_attr_pwm1_auto_point2_fan.dev_attr.attr, | ||
1167 | &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr, | ||
1168 | &sensor_dev_attr_pwm1_auto_point3_fan.dev_attr.attr, | ||
1169 | &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr, | ||
1170 | &sensor_dev_attr_pwm2_auto_point1_fan.dev_attr.attr, | ||
1171 | &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr, | ||
1172 | &sensor_dev_attr_pwm2_auto_point2_fan.dev_attr.attr, | ||
1173 | &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr, | ||
1174 | &sensor_dev_attr_pwm2_auto_point3_fan.dev_attr.attr, | ||
1175 | &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr, | ||
1176 | &sensor_dev_attr_pwm3_auto_point1_fan.dev_attr.attr, | ||
1177 | &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr, | ||
1178 | &sensor_dev_attr_pwm3_auto_point2_fan.dev_attr.attr, | ||
1179 | &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr, | ||
1180 | &sensor_dev_attr_pwm3_auto_point3_fan.dev_attr.attr, | ||
1181 | |||
1017 | &sensor_dev_attr_in0_alarm.dev_attr.attr, | 1182 | &sensor_dev_attr_in0_alarm.dev_attr.attr, |
1018 | &sensor_dev_attr_in1_alarm.dev_attr.attr, | 1183 | &sensor_dev_attr_in1_alarm.dev_attr.attr, |
1019 | &sensor_dev_attr_in2_alarm.dev_attr.attr, | 1184 | &sensor_dev_attr_in2_alarm.dev_attr.attr, |
@@ -1242,12 +1407,12 @@ static int __devexit f71805f_remove(struct platform_device *pdev) | |||
1242 | struct resource *res; | 1407 | struct resource *res; |
1243 | int i; | 1408 | int i; |
1244 | 1409 | ||
1245 | platform_set_drvdata(pdev, NULL); | ||
1246 | hwmon_device_unregister(data->class_dev); | 1410 | hwmon_device_unregister(data->class_dev); |
1247 | sysfs_remove_group(&pdev->dev.kobj, &f71805f_group); | 1411 | sysfs_remove_group(&pdev->dev.kobj, &f71805f_group); |
1248 | for (i = 0; i < 4; i++) | 1412 | for (i = 0; i < 4; i++) |
1249 | sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_optin[i]); | 1413 | sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_optin[i]); |
1250 | sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_pwm_freq); | 1414 | sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_pwm_freq); |
1415 | platform_set_drvdata(pdev, NULL); | ||
1251 | kfree(data); | 1416 | kfree(data); |
1252 | 1417 | ||
1253 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | 1418 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
@@ -1290,15 +1455,12 @@ static int __init f71805f_device_add(unsigned short address, | |||
1290 | goto exit_device_put; | 1455 | goto exit_device_put; |
1291 | } | 1456 | } |
1292 | 1457 | ||
1293 | pdev->dev.platform_data = kmalloc(sizeof(struct f71805f_sio_data), | 1458 | err = platform_device_add_data(pdev, sio_data, |
1294 | GFP_KERNEL); | 1459 | sizeof(struct f71805f_sio_data)); |
1295 | if (!pdev->dev.platform_data) { | 1460 | if (err) { |
1296 | err = -ENOMEM; | ||
1297 | printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); | 1461 | printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); |
1298 | goto exit_device_put; | 1462 | goto exit_device_put; |
1299 | } | 1463 | } |
1300 | memcpy(pdev->dev.platform_data, sio_data, | ||
1301 | sizeof(struct f71805f_sio_data)); | ||
1302 | 1464 | ||
1303 | err = platform_device_add(pdev); | 1465 | err = platform_device_add(pdev); |
1304 | if (err) { | 1466 | if (err) { |
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index 62afc63708a5..eff6036e15c0 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c | |||
@@ -6,6 +6,7 @@ | |||
6 | IT8712F Super I/O chip w/LPC interface | 6 | IT8712F Super I/O chip w/LPC interface |
7 | IT8716F Super I/O chip w/LPC interface | 7 | IT8716F Super I/O chip w/LPC interface |
8 | IT8718F Super I/O chip w/LPC interface | 8 | IT8718F Super I/O chip w/LPC interface |
9 | IT8726F Super I/O chip w/LPC interface | ||
9 | Sis950 A clone of the IT8705F | 10 | Sis950 A clone of the IT8705F |
10 | 11 | ||
11 | Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com> | 12 | Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com> |
@@ -30,8 +31,7 @@ | |||
30 | #include <linux/init.h> | 31 | #include <linux/init.h> |
31 | #include <linux/slab.h> | 32 | #include <linux/slab.h> |
32 | #include <linux/jiffies.h> | 33 | #include <linux/jiffies.h> |
33 | #include <linux/i2c.h> | 34 | #include <linux/platform_device.h> |
34 | #include <linux/i2c-isa.h> | ||
35 | #include <linux/hwmon.h> | 35 | #include <linux/hwmon.h> |
36 | #include <linux/hwmon-sysfs.h> | 36 | #include <linux/hwmon-sysfs.h> |
37 | #include <linux/hwmon-vid.h> | 37 | #include <linux/hwmon-vid.h> |
@@ -40,10 +40,12 @@ | |||
40 | #include <linux/sysfs.h> | 40 | #include <linux/sysfs.h> |
41 | #include <asm/io.h> | 41 | #include <asm/io.h> |
42 | 42 | ||
43 | #define DRVNAME "it87" | ||
43 | 44 | ||
44 | static unsigned short isa_address; | ||
45 | enum chips { it87, it8712, it8716, it8718 }; | 45 | enum chips { it87, it8712, it8716, it8718 }; |
46 | 46 | ||
47 | static struct platform_device *pdev; | ||
48 | |||
47 | #define REG 0x2e /* The register to read/write */ | 49 | #define REG 0x2e /* The register to read/write */ |
48 | #define DEV 0x07 /* Register: Logical device select */ | 50 | #define DEV 0x07 /* Register: Logical device select */ |
49 | #define VAL 0x2f /* The value to read/write */ | 51 | #define VAL 0x2f /* The value to read/write */ |
@@ -97,6 +99,7 @@ superio_exit(void) | |||
97 | #define IT8705F_DEVID 0x8705 | 99 | #define IT8705F_DEVID 0x8705 |
98 | #define IT8716F_DEVID 0x8716 | 100 | #define IT8716F_DEVID 0x8716 |
99 | #define IT8718F_DEVID 0x8718 | 101 | #define IT8718F_DEVID 0x8718 |
102 | #define IT8726F_DEVID 0x8726 | ||
100 | #define IT87_ACT_REG 0x30 | 103 | #define IT87_ACT_REG 0x30 |
101 | #define IT87_BASE_REG 0x60 | 104 | #define IT87_BASE_REG 0x60 |
102 | 105 | ||
@@ -110,10 +113,6 @@ static int update_vbat; | |||
110 | /* Not all BIOSes properly configure the PWM registers */ | 113 | /* Not all BIOSes properly configure the PWM registers */ |
111 | static int fix_pwm_polarity; | 114 | static int fix_pwm_polarity; |
112 | 115 | ||
113 | /* Values read from Super-I/O config space */ | ||
114 | static u16 chip_type; | ||
115 | static u8 vid_value; | ||
116 | |||
117 | /* Many IT87 constants specified below */ | 116 | /* Many IT87 constants specified below */ |
118 | 117 | ||
119 | /* Length of ISA address segment */ | 118 | /* Length of ISA address segment */ |
@@ -214,13 +213,20 @@ static const unsigned int pwm_freq[8] = { | |||
214 | }; | 213 | }; |
215 | 214 | ||
216 | 215 | ||
216 | struct it87_sio_data { | ||
217 | enum chips type; | ||
218 | /* Values read from Super-I/O config space */ | ||
219 | u8 vid_value; | ||
220 | }; | ||
221 | |||
217 | /* For each registered chip, we need to keep some data in memory. | 222 | /* For each registered chip, we need to keep some data in memory. |
218 | The structure is dynamically allocated. */ | 223 | The structure is dynamically allocated. */ |
219 | struct it87_data { | 224 | struct it87_data { |
220 | struct i2c_client client; | ||
221 | struct class_device *class_dev; | 225 | struct class_device *class_dev; |
222 | enum chips type; | 226 | enum chips type; |
223 | 227 | ||
228 | unsigned short addr; | ||
229 | const char *name; | ||
224 | struct mutex update_lock; | 230 | struct mutex update_lock; |
225 | char valid; /* !=0 if following fields are valid */ | 231 | char valid; /* !=0 if following fields are valid */ |
226 | unsigned long last_updated; /* In jiffies */ | 232 | unsigned long last_updated; /* In jiffies */ |
@@ -245,26 +251,25 @@ struct it87_data { | |||
245 | }; | 251 | }; |
246 | 252 | ||
247 | 253 | ||
248 | static int it87_detect(struct i2c_adapter *adapter); | 254 | static int it87_probe(struct platform_device *pdev); |
249 | static int it87_detach_client(struct i2c_client *client); | 255 | static int it87_remove(struct platform_device *pdev); |
250 | 256 | ||
251 | static int it87_read_value(struct i2c_client *client, u8 reg); | 257 | static int it87_read_value(struct it87_data *data, u8 reg); |
252 | static void it87_write_value(struct i2c_client *client, u8 reg, u8 value); | 258 | static void it87_write_value(struct it87_data *data, u8 reg, u8 value); |
253 | static struct it87_data *it87_update_device(struct device *dev); | 259 | static struct it87_data *it87_update_device(struct device *dev); |
254 | static int it87_check_pwm(struct i2c_client *client); | 260 | static int it87_check_pwm(struct device *dev); |
255 | static void it87_init_client(struct i2c_client *client, struct it87_data *data); | 261 | static void it87_init_device(struct platform_device *pdev); |
256 | 262 | ||
257 | 263 | ||
258 | static struct i2c_driver it87_isa_driver = { | 264 | static struct platform_driver it87_driver = { |
259 | .driver = { | 265 | .driver = { |
260 | .owner = THIS_MODULE, | 266 | .owner = THIS_MODULE, |
261 | .name = "it87-isa", | 267 | .name = DRVNAME, |
262 | }, | 268 | }, |
263 | .attach_adapter = it87_detect, | 269 | .probe = it87_probe, |
264 | .detach_client = it87_detach_client, | 270 | .remove = __devexit_p(it87_remove), |
265 | }; | 271 | }; |
266 | 272 | ||
267 | |||
268 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, | 273 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, |
269 | char *buf) | 274 | char *buf) |
270 | { | 275 | { |
@@ -301,13 +306,12 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | |||
301 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 306 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
302 | int nr = sensor_attr->index; | 307 | int nr = sensor_attr->index; |
303 | 308 | ||
304 | struct i2c_client *client = to_i2c_client(dev); | 309 | struct it87_data *data = dev_get_drvdata(dev); |
305 | struct it87_data *data = i2c_get_clientdata(client); | ||
306 | unsigned long val = simple_strtoul(buf, NULL, 10); | 310 | unsigned long val = simple_strtoul(buf, NULL, 10); |
307 | 311 | ||
308 | mutex_lock(&data->update_lock); | 312 | mutex_lock(&data->update_lock); |
309 | data->in_min[nr] = IN_TO_REG(val); | 313 | data->in_min[nr] = IN_TO_REG(val); |
310 | it87_write_value(client, IT87_REG_VIN_MIN(nr), | 314 | it87_write_value(data, IT87_REG_VIN_MIN(nr), |
311 | data->in_min[nr]); | 315 | data->in_min[nr]); |
312 | mutex_unlock(&data->update_lock); | 316 | mutex_unlock(&data->update_lock); |
313 | return count; | 317 | return count; |
@@ -318,13 +322,12 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | |||
318 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 322 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
319 | int nr = sensor_attr->index; | 323 | int nr = sensor_attr->index; |
320 | 324 | ||
321 | struct i2c_client *client = to_i2c_client(dev); | 325 | struct it87_data *data = dev_get_drvdata(dev); |
322 | struct it87_data *data = i2c_get_clientdata(client); | ||
323 | unsigned long val = simple_strtoul(buf, NULL, 10); | 326 | unsigned long val = simple_strtoul(buf, NULL, 10); |
324 | 327 | ||
325 | mutex_lock(&data->update_lock); | 328 | mutex_lock(&data->update_lock); |
326 | data->in_max[nr] = IN_TO_REG(val); | 329 | data->in_max[nr] = IN_TO_REG(val); |
327 | it87_write_value(client, IT87_REG_VIN_MAX(nr), | 330 | it87_write_value(data, IT87_REG_VIN_MAX(nr), |
328 | data->in_max[nr]); | 331 | data->in_max[nr]); |
329 | mutex_unlock(&data->update_lock); | 332 | mutex_unlock(&data->update_lock); |
330 | return count; | 333 | return count; |
@@ -392,13 +395,12 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
392 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 395 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
393 | int nr = sensor_attr->index; | 396 | int nr = sensor_attr->index; |
394 | 397 | ||
395 | struct i2c_client *client = to_i2c_client(dev); | 398 | struct it87_data *data = dev_get_drvdata(dev); |
396 | struct it87_data *data = i2c_get_clientdata(client); | ||
397 | int val = simple_strtol(buf, NULL, 10); | 399 | int val = simple_strtol(buf, NULL, 10); |
398 | 400 | ||
399 | mutex_lock(&data->update_lock); | 401 | mutex_lock(&data->update_lock); |
400 | data->temp_high[nr] = TEMP_TO_REG(val); | 402 | data->temp_high[nr] = TEMP_TO_REG(val); |
401 | it87_write_value(client, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]); | 403 | it87_write_value(data, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]); |
402 | mutex_unlock(&data->update_lock); | 404 | mutex_unlock(&data->update_lock); |
403 | return count; | 405 | return count; |
404 | } | 406 | } |
@@ -408,13 +410,12 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
408 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 410 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
409 | int nr = sensor_attr->index; | 411 | int nr = sensor_attr->index; |
410 | 412 | ||
411 | struct i2c_client *client = to_i2c_client(dev); | 413 | struct it87_data *data = dev_get_drvdata(dev); |
412 | struct it87_data *data = i2c_get_clientdata(client); | ||
413 | int val = simple_strtol(buf, NULL, 10); | 414 | int val = simple_strtol(buf, NULL, 10); |
414 | 415 | ||
415 | mutex_lock(&data->update_lock); | 416 | mutex_lock(&data->update_lock); |
416 | data->temp_low[nr] = TEMP_TO_REG(val); | 417 | data->temp_low[nr] = TEMP_TO_REG(val); |
417 | it87_write_value(client, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]); | 418 | it87_write_value(data, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]); |
418 | mutex_unlock(&data->update_lock); | 419 | mutex_unlock(&data->update_lock); |
419 | return count; | 420 | return count; |
420 | } | 421 | } |
@@ -451,8 +452,7 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, | |||
451 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 452 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
452 | int nr = sensor_attr->index; | 453 | int nr = sensor_attr->index; |
453 | 454 | ||
454 | struct i2c_client *client = to_i2c_client(dev); | 455 | struct it87_data *data = dev_get_drvdata(dev); |
455 | struct it87_data *data = i2c_get_clientdata(client); | ||
456 | int val = simple_strtol(buf, NULL, 10); | 456 | int val = simple_strtol(buf, NULL, 10); |
457 | 457 | ||
458 | mutex_lock(&data->update_lock); | 458 | mutex_lock(&data->update_lock); |
@@ -468,7 +468,7 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, | |||
468 | mutex_unlock(&data->update_lock); | 468 | mutex_unlock(&data->update_lock); |
469 | return -EINVAL; | 469 | return -EINVAL; |
470 | } | 470 | } |
471 | it87_write_value(client, IT87_REG_TEMP_ENABLE, data->sensor); | 471 | it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor); |
472 | mutex_unlock(&data->update_lock); | 472 | mutex_unlock(&data->update_lock); |
473 | return count; | 473 | return count; |
474 | } | 474 | } |
@@ -542,13 +542,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
542 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 542 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
543 | int nr = sensor_attr->index; | 543 | int nr = sensor_attr->index; |
544 | 544 | ||
545 | struct i2c_client *client = to_i2c_client(dev); | 545 | struct it87_data *data = dev_get_drvdata(dev); |
546 | struct it87_data *data = i2c_get_clientdata(client); | ||
547 | int val = simple_strtol(buf, NULL, 10); | 546 | int val = simple_strtol(buf, NULL, 10); |
548 | u8 reg; | 547 | u8 reg; |
549 | 548 | ||
550 | mutex_lock(&data->update_lock); | 549 | mutex_lock(&data->update_lock); |
551 | reg = it87_read_value(client, IT87_REG_FAN_DIV); | 550 | reg = it87_read_value(data, IT87_REG_FAN_DIV); |
552 | switch (nr) { | 551 | switch (nr) { |
553 | case 0: data->fan_div[nr] = reg & 0x07; break; | 552 | case 0: data->fan_div[nr] = reg & 0x07; break; |
554 | case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break; | 553 | case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break; |
@@ -556,7 +555,7 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
556 | } | 555 | } |
557 | 556 | ||
558 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); | 557 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
559 | it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]); | 558 | it87_write_value(data, IT87_REG_FAN_MIN(nr), data->fan_min[nr]); |
560 | mutex_unlock(&data->update_lock); | 559 | mutex_unlock(&data->update_lock); |
561 | return count; | 560 | return count; |
562 | } | 561 | } |
@@ -566,14 +565,13 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | |||
566 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 565 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
567 | int nr = sensor_attr->index; | 566 | int nr = sensor_attr->index; |
568 | 567 | ||
569 | struct i2c_client *client = to_i2c_client(dev); | 568 | struct it87_data *data = dev_get_drvdata(dev); |
570 | struct it87_data *data = i2c_get_clientdata(client); | ||
571 | unsigned long val = simple_strtoul(buf, NULL, 10); | 569 | unsigned long val = simple_strtoul(buf, NULL, 10); |
572 | int min; | 570 | int min; |
573 | u8 old; | 571 | u8 old; |
574 | 572 | ||
575 | mutex_lock(&data->update_lock); | 573 | mutex_lock(&data->update_lock); |
576 | old = it87_read_value(client, IT87_REG_FAN_DIV); | 574 | old = it87_read_value(data, IT87_REG_FAN_DIV); |
577 | 575 | ||
578 | /* Save fan min limit */ | 576 | /* Save fan min limit */ |
579 | min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); | 577 | min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); |
@@ -594,11 +592,11 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | |||
594 | val |= (data->fan_div[1] & 0x07) << 3; | 592 | val |= (data->fan_div[1] & 0x07) << 3; |
595 | if (data->fan_div[2] == 3) | 593 | if (data->fan_div[2] == 3) |
596 | val |= 0x1 << 6; | 594 | val |= 0x1 << 6; |
597 | it87_write_value(client, IT87_REG_FAN_DIV, val); | 595 | it87_write_value(data, IT87_REG_FAN_DIV, val); |
598 | 596 | ||
599 | /* Restore fan min limit */ | 597 | /* Restore fan min limit */ |
600 | data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); | 598 | data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); |
601 | it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]); | 599 | it87_write_value(data, IT87_REG_FAN_MIN(nr), data->fan_min[nr]); |
602 | 600 | ||
603 | mutex_unlock(&data->update_lock); | 601 | mutex_unlock(&data->update_lock); |
604 | return count; | 602 | return count; |
@@ -609,8 +607,7 @@ static ssize_t set_pwm_enable(struct device *dev, | |||
609 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 607 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
610 | int nr = sensor_attr->index; | 608 | int nr = sensor_attr->index; |
611 | 609 | ||
612 | struct i2c_client *client = to_i2c_client(dev); | 610 | struct it87_data *data = dev_get_drvdata(dev); |
613 | struct it87_data *data = i2c_get_clientdata(client); | ||
614 | int val = simple_strtol(buf, NULL, 10); | 611 | int val = simple_strtol(buf, NULL, 10); |
615 | 612 | ||
616 | mutex_lock(&data->update_lock); | 613 | mutex_lock(&data->update_lock); |
@@ -618,17 +615,17 @@ static ssize_t set_pwm_enable(struct device *dev, | |||
618 | if (val == 0) { | 615 | if (val == 0) { |
619 | int tmp; | 616 | int tmp; |
620 | /* make sure the fan is on when in on/off mode */ | 617 | /* make sure the fan is on when in on/off mode */ |
621 | tmp = it87_read_value(client, IT87_REG_FAN_CTL); | 618 | tmp = it87_read_value(data, IT87_REG_FAN_CTL); |
622 | it87_write_value(client, IT87_REG_FAN_CTL, tmp | (1 << nr)); | 619 | it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr)); |
623 | /* set on/off mode */ | 620 | /* set on/off mode */ |
624 | data->fan_main_ctrl &= ~(1 << nr); | 621 | data->fan_main_ctrl &= ~(1 << nr); |
625 | it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); | 622 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); |
626 | } else if (val == 1) { | 623 | } else if (val == 1) { |
627 | /* set SmartGuardian mode */ | 624 | /* set SmartGuardian mode */ |
628 | data->fan_main_ctrl |= (1 << nr); | 625 | data->fan_main_ctrl |= (1 << nr); |
629 | it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); | 626 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); |
630 | /* set saved pwm value, clear FAN_CTLX PWM mode bit */ | 627 | /* set saved pwm value, clear FAN_CTLX PWM mode bit */ |
631 | it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); | 628 | it87_write_value(data, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); |
632 | } else { | 629 | } else { |
633 | mutex_unlock(&data->update_lock); | 630 | mutex_unlock(&data->update_lock); |
634 | return -EINVAL; | 631 | return -EINVAL; |
@@ -643,8 +640,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
643 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 640 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
644 | int nr = sensor_attr->index; | 641 | int nr = sensor_attr->index; |
645 | 642 | ||
646 | struct i2c_client *client = to_i2c_client(dev); | 643 | struct it87_data *data = dev_get_drvdata(dev); |
647 | struct it87_data *data = i2c_get_clientdata(client); | ||
648 | int val = simple_strtol(buf, NULL, 10); | 644 | int val = simple_strtol(buf, NULL, 10); |
649 | 645 | ||
650 | if (val < 0 || val > 255) | 646 | if (val < 0 || val > 255) |
@@ -653,15 +649,14 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
653 | mutex_lock(&data->update_lock); | 649 | mutex_lock(&data->update_lock); |
654 | data->manual_pwm_ctl[nr] = val; | 650 | data->manual_pwm_ctl[nr] = val; |
655 | if (data->fan_main_ctrl & (1 << nr)) | 651 | if (data->fan_main_ctrl & (1 << nr)) |
656 | it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); | 652 | it87_write_value(data, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); |
657 | mutex_unlock(&data->update_lock); | 653 | mutex_unlock(&data->update_lock); |
658 | return count; | 654 | return count; |
659 | } | 655 | } |
660 | static ssize_t set_pwm_freq(struct device *dev, | 656 | static ssize_t set_pwm_freq(struct device *dev, |
661 | struct device_attribute *attr, const char *buf, size_t count) | 657 | struct device_attribute *attr, const char *buf, size_t count) |
662 | { | 658 | { |
663 | struct i2c_client *client = to_i2c_client(dev); | 659 | struct it87_data *data = dev_get_drvdata(dev); |
664 | struct it87_data *data = i2c_get_clientdata(client); | ||
665 | unsigned long val = simple_strtoul(buf, NULL, 10); | 660 | unsigned long val = simple_strtoul(buf, NULL, 10); |
666 | int i; | 661 | int i; |
667 | 662 | ||
@@ -672,9 +667,9 @@ static ssize_t set_pwm_freq(struct device *dev, | |||
672 | } | 667 | } |
673 | 668 | ||
674 | mutex_lock(&data->update_lock); | 669 | mutex_lock(&data->update_lock); |
675 | data->fan_ctl = it87_read_value(client, IT87_REG_FAN_CTL) & 0x8f; | 670 | data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f; |
676 | data->fan_ctl |= i << 4; | 671 | data->fan_ctl |= i << 4; |
677 | it87_write_value(client, IT87_REG_FAN_CTL, data->fan_ctl); | 672 | it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl); |
678 | mutex_unlock(&data->update_lock); | 673 | mutex_unlock(&data->update_lock); |
679 | 674 | ||
680 | return count; | 675 | return count; |
@@ -729,15 +724,14 @@ static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr, | |||
729 | { | 724 | { |
730 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 725 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
731 | int nr = sensor_attr->index; | 726 | int nr = sensor_attr->index; |
732 | struct i2c_client *client = to_i2c_client(dev); | 727 | struct it87_data *data = dev_get_drvdata(dev); |
733 | struct it87_data *data = i2c_get_clientdata(client); | ||
734 | int val = simple_strtol(buf, NULL, 10); | 728 | int val = simple_strtol(buf, NULL, 10); |
735 | 729 | ||
736 | mutex_lock(&data->update_lock); | 730 | mutex_lock(&data->update_lock); |
737 | data->fan_min[nr] = FAN16_TO_REG(val); | 731 | data->fan_min[nr] = FAN16_TO_REG(val); |
738 | it87_write_value(client, IT87_REG_FAN_MIN(nr), | 732 | it87_write_value(data, IT87_REG_FAN_MIN(nr), |
739 | data->fan_min[nr] & 0xff); | 733 | data->fan_min[nr] & 0xff); |
740 | it87_write_value(client, IT87_REG_FANX_MIN(nr), | 734 | it87_write_value(data, IT87_REG_FANX_MIN(nr), |
741 | data->fan_min[nr] >> 8); | 735 | data->fan_min[nr] >> 8); |
742 | mutex_unlock(&data->update_lock); | 736 | mutex_unlock(&data->update_lock); |
743 | return count; | 737 | return count; |
@@ -775,8 +769,7 @@ show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) | |||
775 | static ssize_t | 769 | static ssize_t |
776 | store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 770 | store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
777 | { | 771 | { |
778 | struct i2c_client *client = to_i2c_client(dev); | 772 | struct it87_data *data = dev_get_drvdata(dev); |
779 | struct it87_data *data = i2c_get_clientdata(client); | ||
780 | u32 val; | 773 | u32 val; |
781 | 774 | ||
782 | val = simple_strtoul(buf, NULL, 10); | 775 | val = simple_strtoul(buf, NULL, 10); |
@@ -794,6 +787,14 @@ show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) | |||
794 | } | 787 | } |
795 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); | 788 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); |
796 | 789 | ||
790 | static ssize_t show_name(struct device *dev, struct device_attribute | ||
791 | *devattr, char *buf) | ||
792 | { | ||
793 | struct it87_data *data = dev_get_drvdata(dev); | ||
794 | return sprintf(buf, "%s\n", data->name); | ||
795 | } | ||
796 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
797 | |||
797 | static struct attribute *it87_attributes[] = { | 798 | static struct attribute *it87_attributes[] = { |
798 | &sensor_dev_attr_in0_input.dev_attr.attr, | 799 | &sensor_dev_attr_in0_input.dev_attr.attr, |
799 | &sensor_dev_attr_in1_input.dev_attr.attr, | 800 | &sensor_dev_attr_in1_input.dev_attr.attr, |
@@ -835,6 +836,7 @@ static struct attribute *it87_attributes[] = { | |||
835 | &sensor_dev_attr_temp3_type.dev_attr.attr, | 836 | &sensor_dev_attr_temp3_type.dev_attr.attr, |
836 | 837 | ||
837 | &dev_attr_alarms.attr, | 838 | &dev_attr_alarms.attr, |
839 | &dev_attr_name.attr, | ||
838 | NULL | 840 | NULL |
839 | }; | 841 | }; |
840 | 842 | ||
@@ -877,17 +879,36 @@ static const struct attribute_group it87_group_opt = { | |||
877 | }; | 879 | }; |
878 | 880 | ||
879 | /* SuperIO detection - will change isa_address if a chip is found */ | 881 | /* SuperIO detection - will change isa_address if a chip is found */ |
880 | static int __init it87_find(unsigned short *address) | 882 | static int __init it87_find(unsigned short *address, |
883 | struct it87_sio_data *sio_data) | ||
881 | { | 884 | { |
882 | int err = -ENODEV; | 885 | int err = -ENODEV; |
886 | u16 chip_type; | ||
883 | 887 | ||
884 | superio_enter(); | 888 | superio_enter(); |
885 | chip_type = superio_inw(DEVID); | 889 | chip_type = superio_inw(DEVID); |
886 | if (chip_type != IT8712F_DEVID | 890 | |
887 | && chip_type != IT8716F_DEVID | 891 | switch (chip_type) { |
888 | && chip_type != IT8718F_DEVID | 892 | case IT8705F_DEVID: |
889 | && chip_type != IT8705F_DEVID) | 893 | sio_data->type = it87; |
890 | goto exit; | 894 | break; |
895 | case IT8712F_DEVID: | ||
896 | sio_data->type = it8712; | ||
897 | break; | ||
898 | case IT8716F_DEVID: | ||
899 | case IT8726F_DEVID: | ||
900 | sio_data->type = it8716; | ||
901 | break; | ||
902 | case IT8718F_DEVID: | ||
903 | sio_data->type = it8718; | ||
904 | break; | ||
905 | case 0xffff: /* No device at all */ | ||
906 | goto exit; | ||
907 | default: | ||
908 | pr_debug(DRVNAME ": Unsupported chip (DEVID=0x%x)\n", | ||
909 | chip_type); | ||
910 | goto exit; | ||
911 | } | ||
891 | 912 | ||
892 | superio_select(PME); | 913 | superio_select(PME); |
893 | if (!(superio_inb(IT87_ACT_REG) & 0x01)) { | 914 | if (!(superio_inb(IT87_ACT_REG) & 0x01)) { |
@@ -911,7 +932,7 @@ static int __init it87_find(unsigned short *address) | |||
911 | 932 | ||
912 | superio_select(GPIO); | 933 | superio_select(GPIO); |
913 | if (chip_type == it8718) | 934 | if (chip_type == it8718) |
914 | vid_value = superio_inb(IT87_SIO_VID_REG); | 935 | sio_data->vid_value = superio_inb(IT87_SIO_VID_REG); |
915 | 936 | ||
916 | reg = superio_inb(IT87_SIO_PINX2_REG); | 937 | reg = superio_inb(IT87_SIO_PINX2_REG); |
917 | if (reg & (1 << 0)) | 938 | if (reg & (1 << 0)) |
@@ -925,18 +946,26 @@ exit: | |||
925 | return err; | 946 | return err; |
926 | } | 947 | } |
927 | 948 | ||
928 | /* This function is called by i2c_probe */ | 949 | static int __devinit it87_probe(struct platform_device *pdev) |
929 | static int it87_detect(struct i2c_adapter *adapter) | ||
930 | { | 950 | { |
931 | struct i2c_client *new_client; | ||
932 | struct it87_data *data; | 951 | struct it87_data *data; |
952 | struct resource *res; | ||
953 | struct device *dev = &pdev->dev; | ||
954 | struct it87_sio_data *sio_data = dev->platform_data; | ||
933 | int err = 0; | 955 | int err = 0; |
934 | const char *name; | ||
935 | int enable_pwm_interface; | 956 | int enable_pwm_interface; |
936 | 957 | static const char *names[] = { | |
937 | /* Reserve the ISA region */ | 958 | "it87", |
938 | if (!request_region(isa_address, IT87_EXTENT, | 959 | "it8712", |
939 | it87_isa_driver.driver.name)){ | 960 | "it8716", |
961 | "it8718", | ||
962 | }; | ||
963 | |||
964 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | ||
965 | if (!request_region(res->start, IT87_EXTENT, DRVNAME)) { | ||
966 | dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", | ||
967 | (unsigned long)res->start, | ||
968 | (unsigned long)(res->start + IT87_EXTENT - 1)); | ||
940 | err = -EBUSY; | 969 | err = -EBUSY; |
941 | goto ERROR0; | 970 | goto ERROR0; |
942 | } | 971 | } |
@@ -946,129 +975,104 @@ static int it87_detect(struct i2c_adapter *adapter) | |||
946 | goto ERROR1; | 975 | goto ERROR1; |
947 | } | 976 | } |
948 | 977 | ||
949 | new_client = &data->client; | 978 | data->addr = res->start; |
950 | i2c_set_clientdata(new_client, data); | 979 | data->type = sio_data->type; |
951 | new_client->addr = isa_address; | 980 | data->name = names[sio_data->type]; |
952 | new_client->adapter = adapter; | ||
953 | new_client->driver = &it87_isa_driver; | ||
954 | 981 | ||
955 | /* Now, we do the remaining detection. */ | 982 | /* Now, we do the remaining detection. */ |
956 | if ((it87_read_value(new_client, IT87_REG_CONFIG) & 0x80) | 983 | if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80) |
957 | || it87_read_value(new_client, IT87_REG_CHIPID) != 0x90) { | 984 | || it87_read_value(data, IT87_REG_CHIPID) != 0x90) { |
958 | err = -ENODEV; | 985 | err = -ENODEV; |
959 | goto ERROR2; | 986 | goto ERROR2; |
960 | } | 987 | } |
961 | 988 | ||
962 | /* Determine the chip type. */ | 989 | platform_set_drvdata(pdev, data); |
963 | switch (chip_type) { | ||
964 | case IT8712F_DEVID: | ||
965 | data->type = it8712; | ||
966 | name = "it8712"; | ||
967 | break; | ||
968 | case IT8716F_DEVID: | ||
969 | data->type = it8716; | ||
970 | name = "it8716"; | ||
971 | break; | ||
972 | case IT8718F_DEVID: | ||
973 | data->type = it8718; | ||
974 | name = "it8718"; | ||
975 | break; | ||
976 | default: | ||
977 | data->type = it87; | ||
978 | name = "it87"; | ||
979 | } | ||
980 | 990 | ||
981 | /* Fill in the remaining client fields and put it into the global list */ | ||
982 | strlcpy(new_client->name, name, I2C_NAME_SIZE); | ||
983 | mutex_init(&data->update_lock); | 991 | mutex_init(&data->update_lock); |
984 | 992 | ||
985 | /* Tell the I2C layer a new client has arrived */ | ||
986 | if ((err = i2c_attach_client(new_client))) | ||
987 | goto ERROR2; | ||
988 | |||
989 | /* Check PWM configuration */ | 993 | /* Check PWM configuration */ |
990 | enable_pwm_interface = it87_check_pwm(new_client); | 994 | enable_pwm_interface = it87_check_pwm(dev); |
991 | 995 | ||
992 | /* Initialize the IT87 chip */ | 996 | /* Initialize the IT87 chip */ |
993 | it87_init_client(new_client, data); | 997 | it87_init_device(pdev); |
994 | 998 | ||
995 | /* Register sysfs hooks */ | 999 | /* Register sysfs hooks */ |
996 | if ((err = sysfs_create_group(&new_client->dev.kobj, &it87_group))) | 1000 | if ((err = sysfs_create_group(&dev->kobj, &it87_group))) |
997 | goto ERROR3; | 1001 | goto ERROR2; |
998 | 1002 | ||
999 | /* Do not create fan files for disabled fans */ | 1003 | /* Do not create fan files for disabled fans */ |
1000 | if (data->type == it8716 || data->type == it8718) { | 1004 | if (data->type == it8716 || data->type == it8718) { |
1001 | /* 16-bit tachometers */ | 1005 | /* 16-bit tachometers */ |
1002 | if (data->has_fan & (1 << 0)) { | 1006 | if (data->has_fan & (1 << 0)) { |
1003 | if ((err = device_create_file(&new_client->dev, | 1007 | if ((err = device_create_file(dev, |
1004 | &sensor_dev_attr_fan1_input16.dev_attr)) | 1008 | &sensor_dev_attr_fan1_input16.dev_attr)) |
1005 | || (err = device_create_file(&new_client->dev, | 1009 | || (err = device_create_file(dev, |
1006 | &sensor_dev_attr_fan1_min16.dev_attr))) | 1010 | &sensor_dev_attr_fan1_min16.dev_attr))) |
1007 | goto ERROR4; | 1011 | goto ERROR4; |
1008 | } | 1012 | } |
1009 | if (data->has_fan & (1 << 1)) { | 1013 | if (data->has_fan & (1 << 1)) { |
1010 | if ((err = device_create_file(&new_client->dev, | 1014 | if ((err = device_create_file(dev, |
1011 | &sensor_dev_attr_fan2_input16.dev_attr)) | 1015 | &sensor_dev_attr_fan2_input16.dev_attr)) |
1012 | || (err = device_create_file(&new_client->dev, | 1016 | || (err = device_create_file(dev, |
1013 | &sensor_dev_attr_fan2_min16.dev_attr))) | 1017 | &sensor_dev_attr_fan2_min16.dev_attr))) |
1014 | goto ERROR4; | 1018 | goto ERROR4; |
1015 | } | 1019 | } |
1016 | if (data->has_fan & (1 << 2)) { | 1020 | if (data->has_fan & (1 << 2)) { |
1017 | if ((err = device_create_file(&new_client->dev, | 1021 | if ((err = device_create_file(dev, |
1018 | &sensor_dev_attr_fan3_input16.dev_attr)) | 1022 | &sensor_dev_attr_fan3_input16.dev_attr)) |
1019 | || (err = device_create_file(&new_client->dev, | 1023 | || (err = device_create_file(dev, |
1020 | &sensor_dev_attr_fan3_min16.dev_attr))) | 1024 | &sensor_dev_attr_fan3_min16.dev_attr))) |
1021 | goto ERROR4; | 1025 | goto ERROR4; |
1022 | } | 1026 | } |
1023 | } else { | 1027 | } else { |
1024 | /* 8-bit tachometers with clock divider */ | 1028 | /* 8-bit tachometers with clock divider */ |
1025 | if (data->has_fan & (1 << 0)) { | 1029 | if (data->has_fan & (1 << 0)) { |
1026 | if ((err = device_create_file(&new_client->dev, | 1030 | if ((err = device_create_file(dev, |
1027 | &sensor_dev_attr_fan1_input.dev_attr)) | 1031 | &sensor_dev_attr_fan1_input.dev_attr)) |
1028 | || (err = device_create_file(&new_client->dev, | 1032 | || (err = device_create_file(dev, |
1029 | &sensor_dev_attr_fan1_min.dev_attr)) | 1033 | &sensor_dev_attr_fan1_min.dev_attr)) |
1030 | || (err = device_create_file(&new_client->dev, | 1034 | || (err = device_create_file(dev, |
1031 | &sensor_dev_attr_fan1_div.dev_attr))) | 1035 | &sensor_dev_attr_fan1_div.dev_attr))) |
1032 | goto ERROR4; | 1036 | goto ERROR4; |
1033 | } | 1037 | } |
1034 | if (data->has_fan & (1 << 1)) { | 1038 | if (data->has_fan & (1 << 1)) { |
1035 | if ((err = device_create_file(&new_client->dev, | 1039 | if ((err = device_create_file(dev, |
1036 | &sensor_dev_attr_fan2_input.dev_attr)) | 1040 | &sensor_dev_attr_fan2_input.dev_attr)) |
1037 | || (err = device_create_file(&new_client->dev, | 1041 | || (err = device_create_file(dev, |
1038 | &sensor_dev_attr_fan2_min.dev_attr)) | 1042 | &sensor_dev_attr_fan2_min.dev_attr)) |
1039 | || (err = device_create_file(&new_client->dev, | 1043 | || (err = device_create_file(dev, |
1040 | &sensor_dev_attr_fan2_div.dev_attr))) | 1044 | &sensor_dev_attr_fan2_div.dev_attr))) |
1041 | goto ERROR4; | 1045 | goto ERROR4; |
1042 | } | 1046 | } |
1043 | if (data->has_fan & (1 << 2)) { | 1047 | if (data->has_fan & (1 << 2)) { |
1044 | if ((err = device_create_file(&new_client->dev, | 1048 | if ((err = device_create_file(dev, |
1045 | &sensor_dev_attr_fan3_input.dev_attr)) | 1049 | &sensor_dev_attr_fan3_input.dev_attr)) |
1046 | || (err = device_create_file(&new_client->dev, | 1050 | || (err = device_create_file(dev, |
1047 | &sensor_dev_attr_fan3_min.dev_attr)) | 1051 | &sensor_dev_attr_fan3_min.dev_attr)) |
1048 | || (err = device_create_file(&new_client->dev, | 1052 | || (err = device_create_file(dev, |
1049 | &sensor_dev_attr_fan3_div.dev_attr))) | 1053 | &sensor_dev_attr_fan3_div.dev_attr))) |
1050 | goto ERROR4; | 1054 | goto ERROR4; |
1051 | } | 1055 | } |
1052 | } | 1056 | } |
1053 | 1057 | ||
1054 | if (enable_pwm_interface) { | 1058 | if (enable_pwm_interface) { |
1055 | if ((err = device_create_file(&new_client->dev, | 1059 | if ((err = device_create_file(dev, |
1056 | &sensor_dev_attr_pwm1_enable.dev_attr)) | 1060 | &sensor_dev_attr_pwm1_enable.dev_attr)) |
1057 | || (err = device_create_file(&new_client->dev, | 1061 | || (err = device_create_file(dev, |
1058 | &sensor_dev_attr_pwm2_enable.dev_attr)) | 1062 | &sensor_dev_attr_pwm2_enable.dev_attr)) |
1059 | || (err = device_create_file(&new_client->dev, | 1063 | || (err = device_create_file(dev, |
1060 | &sensor_dev_attr_pwm3_enable.dev_attr)) | 1064 | &sensor_dev_attr_pwm3_enable.dev_attr)) |
1061 | || (err = device_create_file(&new_client->dev, | 1065 | || (err = device_create_file(dev, |
1062 | &sensor_dev_attr_pwm1.dev_attr)) | 1066 | &sensor_dev_attr_pwm1.dev_attr)) |
1063 | || (err = device_create_file(&new_client->dev, | 1067 | || (err = device_create_file(dev, |
1064 | &sensor_dev_attr_pwm2.dev_attr)) | 1068 | &sensor_dev_attr_pwm2.dev_attr)) |
1065 | || (err = device_create_file(&new_client->dev, | 1069 | || (err = device_create_file(dev, |
1066 | &sensor_dev_attr_pwm3.dev_attr)) | 1070 | &sensor_dev_attr_pwm3.dev_attr)) |
1067 | || (err = device_create_file(&new_client->dev, | 1071 | || (err = device_create_file(dev, |
1068 | &dev_attr_pwm1_freq)) | 1072 | &dev_attr_pwm1_freq)) |
1069 | || (err = device_create_file(&new_client->dev, | 1073 | || (err = device_create_file(dev, |
1070 | &dev_attr_pwm2_freq)) | 1074 | &dev_attr_pwm2_freq)) |
1071 | || (err = device_create_file(&new_client->dev, | 1075 | || (err = device_create_file(dev, |
1072 | &dev_attr_pwm3_freq))) | 1076 | &dev_attr_pwm3_freq))) |
1073 | goto ERROR4; | 1077 | goto ERROR4; |
1074 | } | 1078 | } |
@@ -1077,15 +1081,15 @@ static int it87_detect(struct i2c_adapter *adapter) | |||
1077 | || data->type == it8718) { | 1081 | || data->type == it8718) { |
1078 | data->vrm = vid_which_vrm(); | 1082 | data->vrm = vid_which_vrm(); |
1079 | /* VID reading from Super-I/O config space if available */ | 1083 | /* VID reading from Super-I/O config space if available */ |
1080 | data->vid = vid_value; | 1084 | data->vid = sio_data->vid_value; |
1081 | if ((err = device_create_file(&new_client->dev, | 1085 | if ((err = device_create_file(dev, |
1082 | &dev_attr_vrm)) | 1086 | &dev_attr_vrm)) |
1083 | || (err = device_create_file(&new_client->dev, | 1087 | || (err = device_create_file(dev, |
1084 | &dev_attr_cpu0_vid))) | 1088 | &dev_attr_cpu0_vid))) |
1085 | goto ERROR4; | 1089 | goto ERROR4; |
1086 | } | 1090 | } |
1087 | 1091 | ||
1088 | data->class_dev = hwmon_device_register(&new_client->dev); | 1092 | data->class_dev = hwmon_device_register(dev); |
1089 | if (IS_ERR(data->class_dev)) { | 1093 | if (IS_ERR(data->class_dev)) { |
1090 | err = PTR_ERR(data->class_dev); | 1094 | err = PTR_ERR(data->class_dev); |
1091 | goto ERROR4; | 1095 | goto ERROR4; |
@@ -1094,31 +1098,27 @@ static int it87_detect(struct i2c_adapter *adapter) | |||
1094 | return 0; | 1098 | return 0; |
1095 | 1099 | ||
1096 | ERROR4: | 1100 | ERROR4: |
1097 | sysfs_remove_group(&new_client->dev.kobj, &it87_group); | 1101 | sysfs_remove_group(&dev->kobj, &it87_group); |
1098 | sysfs_remove_group(&new_client->dev.kobj, &it87_group_opt); | 1102 | sysfs_remove_group(&dev->kobj, &it87_group_opt); |
1099 | ERROR3: | ||
1100 | i2c_detach_client(new_client); | ||
1101 | ERROR2: | 1103 | ERROR2: |
1104 | platform_set_drvdata(pdev, NULL); | ||
1102 | kfree(data); | 1105 | kfree(data); |
1103 | ERROR1: | 1106 | ERROR1: |
1104 | release_region(isa_address, IT87_EXTENT); | 1107 | release_region(res->start, IT87_EXTENT); |
1105 | ERROR0: | 1108 | ERROR0: |
1106 | return err; | 1109 | return err; |
1107 | } | 1110 | } |
1108 | 1111 | ||
1109 | static int it87_detach_client(struct i2c_client *client) | 1112 | static int __devexit it87_remove(struct platform_device *pdev) |
1110 | { | 1113 | { |
1111 | struct it87_data *data = i2c_get_clientdata(client); | 1114 | struct it87_data *data = platform_get_drvdata(pdev); |
1112 | int err; | ||
1113 | 1115 | ||
1114 | hwmon_device_unregister(data->class_dev); | 1116 | hwmon_device_unregister(data->class_dev); |
1115 | sysfs_remove_group(&client->dev.kobj, &it87_group); | 1117 | sysfs_remove_group(&pdev->dev.kobj, &it87_group); |
1116 | sysfs_remove_group(&client->dev.kobj, &it87_group_opt); | 1118 | sysfs_remove_group(&pdev->dev.kobj, &it87_group_opt); |
1117 | 1119 | ||
1118 | if ((err = i2c_detach_client(client))) | 1120 | release_region(data->addr, IT87_EXTENT); |
1119 | return err; | 1121 | platform_set_drvdata(pdev, NULL); |
1120 | |||
1121 | release_region(client->addr, IT87_EXTENT); | ||
1122 | kfree(data); | 1122 | kfree(data); |
1123 | 1123 | ||
1124 | return 0; | 1124 | return 0; |
@@ -1127,28 +1127,29 @@ static int it87_detach_client(struct i2c_client *client) | |||
1127 | /* Must be called with data->update_lock held, except during initialization. | 1127 | /* Must be called with data->update_lock held, except during initialization. |
1128 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, | 1128 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |
1129 | would slow down the IT87 access and should not be necessary. */ | 1129 | would slow down the IT87 access and should not be necessary. */ |
1130 | static int it87_read_value(struct i2c_client *client, u8 reg) | 1130 | static int it87_read_value(struct it87_data *data, u8 reg) |
1131 | { | 1131 | { |
1132 | outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); | 1132 | outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); |
1133 | return inb_p(client->addr + IT87_DATA_REG_OFFSET); | 1133 | return inb_p(data->addr + IT87_DATA_REG_OFFSET); |
1134 | } | 1134 | } |
1135 | 1135 | ||
1136 | /* Must be called with data->update_lock held, except during initialization. | 1136 | /* Must be called with data->update_lock held, except during initialization. |
1137 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, | 1137 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |
1138 | would slow down the IT87 access and should not be necessary. */ | 1138 | would slow down the IT87 access and should not be necessary. */ |
1139 | static void it87_write_value(struct i2c_client *client, u8 reg, u8 value) | 1139 | static void it87_write_value(struct it87_data *data, u8 reg, u8 value) |
1140 | { | 1140 | { |
1141 | outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); | 1141 | outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); |
1142 | outb_p(value, client->addr + IT87_DATA_REG_OFFSET); | 1142 | outb_p(value, data->addr + IT87_DATA_REG_OFFSET); |
1143 | } | 1143 | } |
1144 | 1144 | ||
1145 | /* Return 1 if and only if the PWM interface is safe to use */ | 1145 | /* Return 1 if and only if the PWM interface is safe to use */ |
1146 | static int it87_check_pwm(struct i2c_client *client) | 1146 | static int __devinit it87_check_pwm(struct device *dev) |
1147 | { | 1147 | { |
1148 | struct it87_data *data = dev_get_drvdata(dev); | ||
1148 | /* Some BIOSes fail to correctly configure the IT87 fans. All fans off | 1149 | /* Some BIOSes fail to correctly configure the IT87 fans. All fans off |
1149 | * and polarity set to active low is sign that this is the case so we | 1150 | * and polarity set to active low is sign that this is the case so we |
1150 | * disable pwm control to protect the user. */ | 1151 | * disable pwm control to protect the user. */ |
1151 | int tmp = it87_read_value(client, IT87_REG_FAN_CTL); | 1152 | int tmp = it87_read_value(data, IT87_REG_FAN_CTL); |
1152 | if ((tmp & 0x87) == 0) { | 1153 | if ((tmp & 0x87) == 0) { |
1153 | if (fix_pwm_polarity) { | 1154 | if (fix_pwm_polarity) { |
1154 | /* The user asks us to attempt a chip reconfiguration. | 1155 | /* The user asks us to attempt a chip reconfiguration. |
@@ -1158,7 +1159,7 @@ static int it87_check_pwm(struct i2c_client *client) | |||
1158 | u8 pwm[3]; | 1159 | u8 pwm[3]; |
1159 | 1160 | ||
1160 | for (i = 0; i < 3; i++) | 1161 | for (i = 0; i < 3; i++) |
1161 | pwm[i] = it87_read_value(client, | 1162 | pwm[i] = it87_read_value(data, |
1162 | IT87_REG_PWM(i)); | 1163 | IT87_REG_PWM(i)); |
1163 | 1164 | ||
1164 | /* If any fan is in automatic pwm mode, the polarity | 1165 | /* If any fan is in automatic pwm mode, the polarity |
@@ -1166,26 +1167,26 @@ static int it87_check_pwm(struct i2c_client *client) | |||
1166 | * better don't change anything (but still disable the | 1167 | * better don't change anything (but still disable the |
1167 | * PWM interface). */ | 1168 | * PWM interface). */ |
1168 | if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) { | 1169 | if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) { |
1169 | dev_info(&client->dev, "Reconfiguring PWM to " | 1170 | dev_info(dev, "Reconfiguring PWM to " |
1170 | "active high polarity\n"); | 1171 | "active high polarity\n"); |
1171 | it87_write_value(client, IT87_REG_FAN_CTL, | 1172 | it87_write_value(data, IT87_REG_FAN_CTL, |
1172 | tmp | 0x87); | 1173 | tmp | 0x87); |
1173 | for (i = 0; i < 3; i++) | 1174 | for (i = 0; i < 3; i++) |
1174 | it87_write_value(client, | 1175 | it87_write_value(data, |
1175 | IT87_REG_PWM(i), | 1176 | IT87_REG_PWM(i), |
1176 | 0x7f & ~pwm[i]); | 1177 | 0x7f & ~pwm[i]); |
1177 | return 1; | 1178 | return 1; |
1178 | } | 1179 | } |
1179 | 1180 | ||
1180 | dev_info(&client->dev, "PWM configuration is " | 1181 | dev_info(dev, "PWM configuration is " |
1181 | "too broken to be fixed\n"); | 1182 | "too broken to be fixed\n"); |
1182 | } | 1183 | } |
1183 | 1184 | ||
1184 | dev_info(&client->dev, "Detected broken BIOS " | 1185 | dev_info(dev, "Detected broken BIOS " |
1185 | "defaults, disabling PWM interface\n"); | 1186 | "defaults, disabling PWM interface\n"); |
1186 | return 0; | 1187 | return 0; |
1187 | } else if (fix_pwm_polarity) { | 1188 | } else if (fix_pwm_polarity) { |
1188 | dev_info(&client->dev, "PWM configuration looks " | 1189 | dev_info(dev, "PWM configuration looks " |
1189 | "sane, won't touch\n"); | 1190 | "sane, won't touch\n"); |
1190 | } | 1191 | } |
1191 | 1192 | ||
@@ -1193,8 +1194,9 @@ static int it87_check_pwm(struct i2c_client *client) | |||
1193 | } | 1194 | } |
1194 | 1195 | ||
1195 | /* Called when we have found a new IT87. */ | 1196 | /* Called when we have found a new IT87. */ |
1196 | static void it87_init_client(struct i2c_client *client, struct it87_data *data) | 1197 | static void __devinit it87_init_device(struct platform_device *pdev) |
1197 | { | 1198 | { |
1199 | struct it87_data *data = platform_get_drvdata(pdev); | ||
1198 | int tmp, i; | 1200 | int tmp, i; |
1199 | 1201 | ||
1200 | /* initialize to sane defaults: | 1202 | /* initialize to sane defaults: |
@@ -1214,48 +1216,48 @@ static void it87_init_client(struct i2c_client *client, struct it87_data *data) | |||
1214 | * means -1 degree C, which surprisingly doesn't trigger an alarm, | 1216 | * means -1 degree C, which surprisingly doesn't trigger an alarm, |
1215 | * but is still confusing, so change to 127 degrees C. */ | 1217 | * but is still confusing, so change to 127 degrees C. */ |
1216 | for (i = 0; i < 8; i++) { | 1218 | for (i = 0; i < 8; i++) { |
1217 | tmp = it87_read_value(client, IT87_REG_VIN_MIN(i)); | 1219 | tmp = it87_read_value(data, IT87_REG_VIN_MIN(i)); |
1218 | if (tmp == 0xff) | 1220 | if (tmp == 0xff) |
1219 | it87_write_value(client, IT87_REG_VIN_MIN(i), 0); | 1221 | it87_write_value(data, IT87_REG_VIN_MIN(i), 0); |
1220 | } | 1222 | } |
1221 | for (i = 0; i < 3; i++) { | 1223 | for (i = 0; i < 3; i++) { |
1222 | tmp = it87_read_value(client, IT87_REG_TEMP_HIGH(i)); | 1224 | tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i)); |
1223 | if (tmp == 0xff) | 1225 | if (tmp == 0xff) |
1224 | it87_write_value(client, IT87_REG_TEMP_HIGH(i), 127); | 1226 | it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127); |
1225 | } | 1227 | } |
1226 | 1228 | ||
1227 | /* Check if temperature channnels are reset manually or by some reason */ | 1229 | /* Check if temperature channnels are reset manually or by some reason */ |
1228 | tmp = it87_read_value(client, IT87_REG_TEMP_ENABLE); | 1230 | tmp = it87_read_value(data, IT87_REG_TEMP_ENABLE); |
1229 | if ((tmp & 0x3f) == 0) { | 1231 | if ((tmp & 0x3f) == 0) { |
1230 | /* Temp1,Temp3=thermistor; Temp2=thermal diode */ | 1232 | /* Temp1,Temp3=thermistor; Temp2=thermal diode */ |
1231 | tmp = (tmp & 0xc0) | 0x2a; | 1233 | tmp = (tmp & 0xc0) | 0x2a; |
1232 | it87_write_value(client, IT87_REG_TEMP_ENABLE, tmp); | 1234 | it87_write_value(data, IT87_REG_TEMP_ENABLE, tmp); |
1233 | } | 1235 | } |
1234 | data->sensor = tmp; | 1236 | data->sensor = tmp; |
1235 | 1237 | ||
1236 | /* Check if voltage monitors are reset manually or by some reason */ | 1238 | /* Check if voltage monitors are reset manually or by some reason */ |
1237 | tmp = it87_read_value(client, IT87_REG_VIN_ENABLE); | 1239 | tmp = it87_read_value(data, IT87_REG_VIN_ENABLE); |
1238 | if ((tmp & 0xff) == 0) { | 1240 | if ((tmp & 0xff) == 0) { |
1239 | /* Enable all voltage monitors */ | 1241 | /* Enable all voltage monitors */ |
1240 | it87_write_value(client, IT87_REG_VIN_ENABLE, 0xff); | 1242 | it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff); |
1241 | } | 1243 | } |
1242 | 1244 | ||
1243 | /* Check if tachometers are reset manually or by some reason */ | 1245 | /* Check if tachometers are reset manually or by some reason */ |
1244 | data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL); | 1246 | data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL); |
1245 | if ((data->fan_main_ctrl & 0x70) == 0) { | 1247 | if ((data->fan_main_ctrl & 0x70) == 0) { |
1246 | /* Enable all fan tachometers */ | 1248 | /* Enable all fan tachometers */ |
1247 | data->fan_main_ctrl |= 0x70; | 1249 | data->fan_main_ctrl |= 0x70; |
1248 | it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); | 1250 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); |
1249 | } | 1251 | } |
1250 | data->has_fan = (data->fan_main_ctrl >> 4) & 0x07; | 1252 | data->has_fan = (data->fan_main_ctrl >> 4) & 0x07; |
1251 | 1253 | ||
1252 | /* Set tachometers to 16-bit mode if needed */ | 1254 | /* Set tachometers to 16-bit mode if needed */ |
1253 | if (data->type == it8716 || data->type == it8718) { | 1255 | if (data->type == it8716 || data->type == it8718) { |
1254 | tmp = it87_read_value(client, IT87_REG_FAN_16BIT); | 1256 | tmp = it87_read_value(data, IT87_REG_FAN_16BIT); |
1255 | if (~tmp & 0x07 & data->has_fan) { | 1257 | if (~tmp & 0x07 & data->has_fan) { |
1256 | dev_dbg(&client->dev, | 1258 | dev_dbg(&pdev->dev, |
1257 | "Setting fan1-3 to 16-bit mode\n"); | 1259 | "Setting fan1-3 to 16-bit mode\n"); |
1258 | it87_write_value(client, IT87_REG_FAN_16BIT, | 1260 | it87_write_value(data, IT87_REG_FAN_16BIT, |
1259 | tmp | 0x07); | 1261 | tmp | 0x07); |
1260 | } | 1262 | } |
1261 | } | 1263 | } |
@@ -1265,7 +1267,7 @@ static void it87_init_client(struct i2c_client *client, struct it87_data *data) | |||
1265 | for (i = 0; i < 3; i++) { | 1267 | for (i = 0; i < 3; i++) { |
1266 | if (data->fan_main_ctrl & (1 << i)) { | 1268 | if (data->fan_main_ctrl & (1 << i)) { |
1267 | /* pwm mode */ | 1269 | /* pwm mode */ |
1268 | tmp = it87_read_value(client, IT87_REG_PWM(i)); | 1270 | tmp = it87_read_value(data, IT87_REG_PWM(i)); |
1269 | if (tmp & 0x80) { | 1271 | if (tmp & 0x80) { |
1270 | /* automatic pwm - not yet implemented, but | 1272 | /* automatic pwm - not yet implemented, but |
1271 | * leave the settings made by the BIOS alone | 1273 | * leave the settings made by the BIOS alone |
@@ -1279,15 +1281,14 @@ static void it87_init_client(struct i2c_client *client, struct it87_data *data) | |||
1279 | } | 1281 | } |
1280 | 1282 | ||
1281 | /* Start monitoring */ | 1283 | /* Start monitoring */ |
1282 | it87_write_value(client, IT87_REG_CONFIG, | 1284 | it87_write_value(data, IT87_REG_CONFIG, |
1283 | (it87_read_value(client, IT87_REG_CONFIG) & 0x36) | 1285 | (it87_read_value(data, IT87_REG_CONFIG) & 0x36) |
1284 | | (update_vbat ? 0x41 : 0x01)); | 1286 | | (update_vbat ? 0x41 : 0x01)); |
1285 | } | 1287 | } |
1286 | 1288 | ||
1287 | static struct it87_data *it87_update_device(struct device *dev) | 1289 | static struct it87_data *it87_update_device(struct device *dev) |
1288 | { | 1290 | { |
1289 | struct i2c_client *client = to_i2c_client(dev); | 1291 | struct it87_data *data = dev_get_drvdata(dev); |
1290 | struct it87_data *data = i2c_get_clientdata(client); | ||
1291 | int i; | 1292 | int i; |
1292 | 1293 | ||
1293 | mutex_lock(&data->update_lock); | 1294 | mutex_lock(&data->update_lock); |
@@ -1298,20 +1299,20 @@ static struct it87_data *it87_update_device(struct device *dev) | |||
1298 | if (update_vbat) { | 1299 | if (update_vbat) { |
1299 | /* Cleared after each update, so reenable. Value | 1300 | /* Cleared after each update, so reenable. Value |
1300 | returned by this read will be previous value */ | 1301 | returned by this read will be previous value */ |
1301 | it87_write_value(client, IT87_REG_CONFIG, | 1302 | it87_write_value(data, IT87_REG_CONFIG, |
1302 | it87_read_value(client, IT87_REG_CONFIG) | 0x40); | 1303 | it87_read_value(data, IT87_REG_CONFIG) | 0x40); |
1303 | } | 1304 | } |
1304 | for (i = 0; i <= 7; i++) { | 1305 | for (i = 0; i <= 7; i++) { |
1305 | data->in[i] = | 1306 | data->in[i] = |
1306 | it87_read_value(client, IT87_REG_VIN(i)); | 1307 | it87_read_value(data, IT87_REG_VIN(i)); |
1307 | data->in_min[i] = | 1308 | data->in_min[i] = |
1308 | it87_read_value(client, IT87_REG_VIN_MIN(i)); | 1309 | it87_read_value(data, IT87_REG_VIN_MIN(i)); |
1309 | data->in_max[i] = | 1310 | data->in_max[i] = |
1310 | it87_read_value(client, IT87_REG_VIN_MAX(i)); | 1311 | it87_read_value(data, IT87_REG_VIN_MAX(i)); |
1311 | } | 1312 | } |
1312 | /* in8 (battery) has no limit registers */ | 1313 | /* in8 (battery) has no limit registers */ |
1313 | data->in[8] = | 1314 | data->in[8] = |
1314 | it87_read_value(client, IT87_REG_VIN(8)); | 1315 | it87_read_value(data, IT87_REG_VIN(8)); |
1315 | 1316 | ||
1316 | for (i = 0; i < 3; i++) { | 1317 | for (i = 0; i < 3; i++) { |
1317 | /* Skip disabled fans */ | 1318 | /* Skip disabled fans */ |
@@ -1319,46 +1320,47 @@ static struct it87_data *it87_update_device(struct device *dev) | |||
1319 | continue; | 1320 | continue; |
1320 | 1321 | ||
1321 | data->fan_min[i] = | 1322 | data->fan_min[i] = |
1322 | it87_read_value(client, IT87_REG_FAN_MIN(i)); | 1323 | it87_read_value(data, IT87_REG_FAN_MIN(i)); |
1323 | data->fan[i] = it87_read_value(client, | 1324 | data->fan[i] = it87_read_value(data, |
1324 | IT87_REG_FAN(i)); | 1325 | IT87_REG_FAN(i)); |
1325 | /* Add high byte if in 16-bit mode */ | 1326 | /* Add high byte if in 16-bit mode */ |
1326 | if (data->type == it8716 || data->type == it8718) { | 1327 | if (data->type == it8716 || data->type == it8718) { |
1327 | data->fan[i] |= it87_read_value(client, | 1328 | data->fan[i] |= it87_read_value(data, |
1328 | IT87_REG_FANX(i)) << 8; | 1329 | IT87_REG_FANX(i)) << 8; |
1329 | data->fan_min[i] |= it87_read_value(client, | 1330 | data->fan_min[i] |= it87_read_value(data, |
1330 | IT87_REG_FANX_MIN(i)) << 8; | 1331 | IT87_REG_FANX_MIN(i)) << 8; |
1331 | } | 1332 | } |
1332 | } | 1333 | } |
1333 | for (i = 0; i < 3; i++) { | 1334 | for (i = 0; i < 3; i++) { |
1334 | data->temp[i] = | 1335 | data->temp[i] = |
1335 | it87_read_value(client, IT87_REG_TEMP(i)); | 1336 | it87_read_value(data, IT87_REG_TEMP(i)); |
1336 | data->temp_high[i] = | 1337 | data->temp_high[i] = |
1337 | it87_read_value(client, IT87_REG_TEMP_HIGH(i)); | 1338 | it87_read_value(data, IT87_REG_TEMP_HIGH(i)); |
1338 | data->temp_low[i] = | 1339 | data->temp_low[i] = |
1339 | it87_read_value(client, IT87_REG_TEMP_LOW(i)); | 1340 | it87_read_value(data, IT87_REG_TEMP_LOW(i)); |
1340 | } | 1341 | } |
1341 | 1342 | ||
1342 | /* Newer chips don't have clock dividers */ | 1343 | /* Newer chips don't have clock dividers */ |
1343 | if ((data->has_fan & 0x07) && data->type != it8716 | 1344 | if ((data->has_fan & 0x07) && data->type != it8716 |
1344 | && data->type != it8718) { | 1345 | && data->type != it8718) { |
1345 | i = it87_read_value(client, IT87_REG_FAN_DIV); | 1346 | i = it87_read_value(data, IT87_REG_FAN_DIV); |
1346 | data->fan_div[0] = i & 0x07; | 1347 | data->fan_div[0] = i & 0x07; |
1347 | data->fan_div[1] = (i >> 3) & 0x07; | 1348 | data->fan_div[1] = (i >> 3) & 0x07; |
1348 | data->fan_div[2] = (i & 0x40) ? 3 : 1; | 1349 | data->fan_div[2] = (i & 0x40) ? 3 : 1; |
1349 | } | 1350 | } |
1350 | 1351 | ||
1351 | data->alarms = | 1352 | data->alarms = |
1352 | it87_read_value(client, IT87_REG_ALARM1) | | 1353 | it87_read_value(data, IT87_REG_ALARM1) | |
1353 | (it87_read_value(client, IT87_REG_ALARM2) << 8) | | 1354 | (it87_read_value(data, IT87_REG_ALARM2) << 8) | |
1354 | (it87_read_value(client, IT87_REG_ALARM3) << 16); | 1355 | (it87_read_value(data, IT87_REG_ALARM3) << 16); |
1355 | data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL); | 1356 | data->fan_main_ctrl = it87_read_value(data, |
1356 | data->fan_ctl = it87_read_value(client, IT87_REG_FAN_CTL); | 1357 | IT87_REG_FAN_MAIN_CTRL); |
1357 | 1358 | data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL); | |
1358 | data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE); | 1359 | |
1360 | data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); | ||
1359 | /* The 8705 does not have VID capability */ | 1361 | /* The 8705 does not have VID capability */ |
1360 | if (data->type == it8712 || data->type == it8716) { | 1362 | if (data->type == it8712 || data->type == it8716) { |
1361 | data->vid = it87_read_value(client, IT87_REG_VID); | 1363 | data->vid = it87_read_value(data, IT87_REG_VID); |
1362 | /* The older IT8712F revisions had only 5 VID pins, | 1364 | /* The older IT8712F revisions had only 5 VID pins, |
1363 | but we assume it is always safe to read 6 bits. */ | 1365 | but we assume it is always safe to read 6 bits. */ |
1364 | data->vid &= 0x3f; | 1366 | data->vid &= 0x3f; |
@@ -1372,24 +1374,85 @@ static struct it87_data *it87_update_device(struct device *dev) | |||
1372 | return data; | 1374 | return data; |
1373 | } | 1375 | } |
1374 | 1376 | ||
1377 | static int __init it87_device_add(unsigned short address, | ||
1378 | const struct it87_sio_data *sio_data) | ||
1379 | { | ||
1380 | struct resource res = { | ||
1381 | .start = address , | ||
1382 | .end = address + IT87_EXTENT - 1, | ||
1383 | .name = DRVNAME, | ||
1384 | .flags = IORESOURCE_IO, | ||
1385 | }; | ||
1386 | int err; | ||
1387 | |||
1388 | pdev = platform_device_alloc(DRVNAME, address); | ||
1389 | if (!pdev) { | ||
1390 | err = -ENOMEM; | ||
1391 | printk(KERN_ERR DRVNAME ": Device allocation failed\n"); | ||
1392 | goto exit; | ||
1393 | } | ||
1394 | |||
1395 | err = platform_device_add_resources(pdev, &res, 1); | ||
1396 | if (err) { | ||
1397 | printk(KERN_ERR DRVNAME ": Device resource addition failed " | ||
1398 | "(%d)\n", err); | ||
1399 | goto exit_device_put; | ||
1400 | } | ||
1401 | |||
1402 | err = platform_device_add_data(pdev, sio_data, | ||
1403 | sizeof(struct it87_sio_data)); | ||
1404 | if (err) { | ||
1405 | printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); | ||
1406 | goto exit_device_put; | ||
1407 | } | ||
1408 | |||
1409 | err = platform_device_add(pdev); | ||
1410 | if (err) { | ||
1411 | printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", | ||
1412 | err); | ||
1413 | goto exit_device_put; | ||
1414 | } | ||
1415 | |||
1416 | return 0; | ||
1417 | |||
1418 | exit_device_put: | ||
1419 | platform_device_put(pdev); | ||
1420 | exit: | ||
1421 | return err; | ||
1422 | } | ||
1423 | |||
1375 | static int __init sm_it87_init(void) | 1424 | static int __init sm_it87_init(void) |
1376 | { | 1425 | { |
1377 | int res; | 1426 | int err; |
1427 | unsigned short isa_address=0; | ||
1428 | struct it87_sio_data sio_data; | ||
1429 | |||
1430 | err = it87_find(&isa_address, &sio_data); | ||
1431 | if (err) | ||
1432 | return err; | ||
1433 | err = platform_driver_register(&it87_driver); | ||
1434 | if (err) | ||
1435 | return err; | ||
1378 | 1436 | ||
1379 | if ((res = it87_find(&isa_address))) | 1437 | err = it87_device_add(isa_address, &sio_data); |
1380 | return res; | 1438 | if (err){ |
1381 | return i2c_isa_add_driver(&it87_isa_driver); | 1439 | platform_driver_unregister(&it87_driver); |
1440 | return err; | ||
1441 | } | ||
1442 | |||
1443 | return 0; | ||
1382 | } | 1444 | } |
1383 | 1445 | ||
1384 | static void __exit sm_it87_exit(void) | 1446 | static void __exit sm_it87_exit(void) |
1385 | { | 1447 | { |
1386 | i2c_isa_del_driver(&it87_isa_driver); | 1448 | platform_device_unregister(pdev); |
1449 | platform_driver_unregister(&it87_driver); | ||
1387 | } | 1450 | } |
1388 | 1451 | ||
1389 | 1452 | ||
1390 | MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>, " | 1453 | MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>, " |
1391 | "Jean Delvare <khali@linux-fr.org>"); | 1454 | "Jean Delvare <khali@linux-fr.org>"); |
1392 | MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F, SiS950 driver"); | 1455 | MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8726F, SiS950 driver"); |
1393 | module_param(update_vbat, bool, 0); | 1456 | module_param(update_vbat, bool, 0); |
1394 | MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); | 1457 | MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); |
1395 | module_param(fix_pwm_polarity, bool, 0); | 1458 | module_param(fix_pwm_polarity, bool, 0); |
diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c index d69f3cf07122..2162d69a8c06 100644 --- a/drivers/hwmon/lm63.c +++ b/drivers/hwmon/lm63.c | |||
@@ -364,7 +364,7 @@ static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst, | |||
364 | /* Individual alarm files */ | 364 | /* Individual alarm files */ |
365 | static SENSOR_DEVICE_ATTR(fan1_min_alarm, S_IRUGO, show_alarm, NULL, 0); | 365 | static SENSOR_DEVICE_ATTR(fan1_min_alarm, S_IRUGO, show_alarm, NULL, 0); |
366 | static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1); | 366 | static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1); |
367 | static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 2); | 367 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); |
368 | static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); | 368 | static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); |
369 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); | 369 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); |
370 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); | 370 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); |
@@ -383,7 +383,7 @@ static struct attribute *lm63_attributes[] = { | |||
383 | &dev_attr_temp2_crit_hyst.attr, | 383 | &dev_attr_temp2_crit_hyst.attr, |
384 | 384 | ||
385 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, | 385 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, |
386 | &sensor_dev_attr_temp2_input_fault.dev_attr.attr, | 386 | &sensor_dev_attr_temp2_fault.dev_attr.attr, |
387 | &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, | 387 | &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, |
388 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, | 388 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, |
389 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, | 389 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, |
diff --git a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c index feb87b41e986..654c0f73464d 100644 --- a/drivers/hwmon/lm83.c +++ b/drivers/hwmon/lm83.c | |||
@@ -223,14 +223,14 @@ static SENSOR_DEVICE_ATTR(temp4_crit, S_IRUGO, show_temp, NULL, 8); | |||
223 | /* Individual alarm files */ | 223 | /* Individual alarm files */ |
224 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0); | 224 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0); |
225 | static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 1); | 225 | static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 1); |
226 | static SENSOR_DEVICE_ATTR(temp3_input_fault, S_IRUGO, show_alarm, NULL, 2); | 226 | static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 2); |
227 | static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 4); | 227 | static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 4); |
228 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); | 228 | static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6); |
229 | static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 8); | 229 | static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 8); |
230 | static SENSOR_DEVICE_ATTR(temp4_crit_alarm, S_IRUGO, show_alarm, NULL, 9); | 230 | static SENSOR_DEVICE_ATTR(temp4_crit_alarm, S_IRUGO, show_alarm, NULL, 9); |
231 | static SENSOR_DEVICE_ATTR(temp4_input_fault, S_IRUGO, show_alarm, NULL, 10); | 231 | static SENSOR_DEVICE_ATTR(temp4_fault, S_IRUGO, show_alarm, NULL, 10); |
232 | static SENSOR_DEVICE_ATTR(temp4_max_alarm, S_IRUGO, show_alarm, NULL, 12); | 232 | static SENSOR_DEVICE_ATTR(temp4_max_alarm, S_IRUGO, show_alarm, NULL, 12); |
233 | static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 13); | 233 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 13); |
234 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 15); | 234 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 15); |
235 | /* Raw alarm file for compatibility */ | 235 | /* Raw alarm file for compatibility */ |
236 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 236 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
@@ -245,7 +245,7 @@ static struct attribute *lm83_attributes[] = { | |||
245 | 245 | ||
246 | &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, | 246 | &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, |
247 | &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr, | 247 | &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr, |
248 | &sensor_dev_attr_temp3_input_fault.dev_attr.attr, | 248 | &sensor_dev_attr_temp3_fault.dev_attr.attr, |
249 | &sensor_dev_attr_temp3_max_alarm.dev_attr.attr, | 249 | &sensor_dev_attr_temp3_max_alarm.dev_attr.attr, |
250 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, | 250 | &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, |
251 | &dev_attr_alarms.attr, | 251 | &dev_attr_alarms.attr, |
@@ -266,9 +266,9 @@ static struct attribute *lm83_attributes_opt[] = { | |||
266 | 266 | ||
267 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, | 267 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, |
268 | &sensor_dev_attr_temp4_crit_alarm.dev_attr.attr, | 268 | &sensor_dev_attr_temp4_crit_alarm.dev_attr.attr, |
269 | &sensor_dev_attr_temp4_input_fault.dev_attr.attr, | 269 | &sensor_dev_attr_temp4_fault.dev_attr.attr, |
270 | &sensor_dev_attr_temp4_max_alarm.dev_attr.attr, | 270 | &sensor_dev_attr_temp4_max_alarm.dev_attr.attr, |
271 | &sensor_dev_attr_temp2_input_fault.dev_attr.attr, | 271 | &sensor_dev_attr_temp2_fault.dev_attr.attr, |
272 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, | 272 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, |
273 | NULL | 273 | NULL |
274 | }; | 274 | }; |
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c index 6882ce75feee..48833fff4920 100644 --- a/drivers/hwmon/lm90.c +++ b/drivers/hwmon/lm90.c | |||
@@ -43,6 +43,13 @@ | |||
43 | * variants. The extra address and features of the MAX6659 are not | 43 | * variants. The extra address and features of the MAX6659 are not |
44 | * supported by this driver. | 44 | * supported by this driver. |
45 | * | 45 | * |
46 | * This driver also supports the MAX6680 and MAX6681, two other sensor | ||
47 | * chips made by Maxim. These are quite similar to the other Maxim | ||
48 | * chips. Complete datasheet can be obtained at: | ||
49 | * http://www.maxim-ic.com/quick_view2.cfm/qv_pk/3370 | ||
50 | * The MAX6680 and MAX6681 only differ in the pinout so they can be | ||
51 | * treated identically. | ||
52 | * | ||
46 | * This driver also supports the ADT7461 chip from Analog Devices but | 53 | * This driver also supports the ADT7461 chip from Analog Devices but |
47 | * only in its "compatability mode". If an ADT7461 chip is found but | 54 | * only in its "compatability mode". If an ADT7461 chip is found but |
48 | * is configured in non-compatible mode (where its temperature | 55 | * is configured in non-compatible mode (where its temperature |
@@ -84,20 +91,25 @@ | |||
84 | /* | 91 | /* |
85 | * Addresses to scan | 92 | * Addresses to scan |
86 | * Address is fully defined internally and cannot be changed except for | 93 | * Address is fully defined internally and cannot be changed except for |
87 | * MAX6659. | 94 | * MAX6659, MAX6680 and MAX6681. |
88 | * LM86, LM89, LM90, LM99, ADM1032, ADM1032-1, ADT7461, MAX6657 and MAX6658 | 95 | * LM86, LM89, LM90, LM99, ADM1032, ADM1032-1, ADT7461, MAX6657 and MAX6658 |
89 | * have address 0x4c. | 96 | * have address 0x4c. |
90 | * ADM1032-2, ADT7461-2, LM89-1, and LM99-1 have address 0x4d. | 97 | * ADM1032-2, ADT7461-2, LM89-1, and LM99-1 have address 0x4d. |
91 | * MAX6659 can have address 0x4c, 0x4d or 0x4e (unsupported). | 98 | * MAX6659 can have address 0x4c, 0x4d or 0x4e (unsupported). |
99 | * MAX6680 and MAX6681 can have address 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, | ||
100 | * 0x4c, 0x4d or 0x4e. | ||
92 | */ | 101 | */ |
93 | 102 | ||
94 | static unsigned short normal_i2c[] = { 0x4c, 0x4d, I2C_CLIENT_END }; | 103 | static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a, |
104 | 0x29, 0x2a, 0x2b, | ||
105 | 0x4c, 0x4d, 0x4e, | ||
106 | I2C_CLIENT_END }; | ||
95 | 107 | ||
96 | /* | 108 | /* |
97 | * Insmod parameters | 109 | * Insmod parameters |
98 | */ | 110 | */ |
99 | 111 | ||
100 | I2C_CLIENT_INSMOD_6(lm90, adm1032, lm99, lm86, max6657, adt7461); | 112 | I2C_CLIENT_INSMOD_7(lm90, adm1032, lm99, lm86, max6657, adt7461, max6680); |
101 | 113 | ||
102 | /* | 114 | /* |
103 | * The LM90 registers | 115 | * The LM90 registers |
@@ -359,7 +371,7 @@ static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 4); | |||
359 | /* Individual alarm files */ | 371 | /* Individual alarm files */ |
360 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0); | 372 | static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0); |
361 | static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1); | 373 | static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1); |
362 | static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 2); | 374 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2); |
363 | static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); | 375 | static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3); |
364 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); | 376 | static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4); |
365 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 5); | 377 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 5); |
@@ -381,7 +393,7 @@ static struct attribute *lm90_attributes[] = { | |||
381 | 393 | ||
382 | &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, | 394 | &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr, |
383 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, | 395 | &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr, |
384 | &sensor_dev_attr_temp2_input_fault.dev_attr.attr, | 396 | &sensor_dev_attr_temp2_fault.dev_attr.attr, |
385 | &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, | 397 | &sensor_dev_attr_temp2_min_alarm.dev_attr.attr, |
386 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, | 398 | &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, |
387 | &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, | 399 | &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, |
@@ -429,7 +441,7 @@ static DEVICE_ATTR(pec, S_IWUSR | S_IRUGO, show_pec, set_pec); | |||
429 | */ | 441 | */ |
430 | 442 | ||
431 | /* The ADM1032 supports PEC but not on write byte transactions, so we need | 443 | /* The ADM1032 supports PEC but not on write byte transactions, so we need |
432 | to explicitely ask for a transaction without PEC. */ | 444 | to explicitly ask for a transaction without PEC. */ |
433 | static inline s32 adm1032_write_byte(struct i2c_client *client, u8 value) | 445 | static inline s32 adm1032_write_byte(struct i2c_client *client, u8 value) |
434 | { | 446 | { |
435 | return i2c_smbus_xfer(client->adapter, client->addr, | 447 | return i2c_smbus_xfer(client->adapter, client->addr, |
@@ -525,7 +537,8 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | |||
525 | ®_convrate) < 0) | 537 | ®_convrate) < 0) |
526 | goto exit_free; | 538 | goto exit_free; |
527 | 539 | ||
528 | if (man_id == 0x01) { /* National Semiconductor */ | 540 | if ((address == 0x4C || address == 0x4D) |
541 | && man_id == 0x01) { /* National Semiconductor */ | ||
529 | u8 reg_config2; | 542 | u8 reg_config2; |
530 | 543 | ||
531 | if (lm90_read_reg(new_client, LM90_REG_R_CONFIG2, | 544 | if (lm90_read_reg(new_client, LM90_REG_R_CONFIG2, |
@@ -548,7 +561,8 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | |||
548 | } | 561 | } |
549 | } | 562 | } |
550 | } else | 563 | } else |
551 | if (man_id == 0x41) { /* Analog Devices */ | 564 | if ((address == 0x4C || address == 0x4D) |
565 | && man_id == 0x41) { /* Analog Devices */ | ||
552 | if ((chip_id & 0xF0) == 0x40 /* ADM1032 */ | 566 | if ((chip_id & 0xF0) == 0x40 /* ADM1032 */ |
553 | && (reg_config1 & 0x3F) == 0x00 | 567 | && (reg_config1 & 0x3F) == 0x00 |
554 | && reg_convrate <= 0x0A) { | 568 | && reg_convrate <= 0x0A) { |
@@ -562,18 +576,30 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | |||
562 | } else | 576 | } else |
563 | if (man_id == 0x4D) { /* Maxim */ | 577 | if (man_id == 0x4D) { /* Maxim */ |
564 | /* | 578 | /* |
565 | * The Maxim variants do NOT have a chip_id register. | 579 | * The MAX6657, MAX6658 and MAX6659 do NOT have a |
566 | * Reading from that address will return the last read | 580 | * chip_id register. Reading from that address will |
567 | * value, which in our case is those of the man_id | 581 | * return the last read value, which in our case is |
568 | * register. Likewise, the config1 register seems to | 582 | * those of the man_id register. Likewise, the config1 |
569 | * lack a low nibble, so the value will be those of the | 583 | * register seems to lack a low nibble, so the value |
570 | * previous read, so in our case those of the man_id | 584 | * will be those of the previous read, so in our case |
571 | * register. | 585 | * those of the man_id register. |
572 | */ | 586 | */ |
573 | if (chip_id == man_id | 587 | if (chip_id == man_id |
588 | && (address == 0x4F || address == 0x4D) | ||
574 | && (reg_config1 & 0x1F) == (man_id & 0x0F) | 589 | && (reg_config1 & 0x1F) == (man_id & 0x0F) |
575 | && reg_convrate <= 0x09) { | 590 | && reg_convrate <= 0x09) { |
576 | kind = max6657; | 591 | kind = max6657; |
592 | } else | ||
593 | /* The chip_id register of the MAX6680 and MAX6681 | ||
594 | * holds the revision of the chip. | ||
595 | * the lowest bit of the config1 register is unused | ||
596 | * and should return zero when read, so should the | ||
597 | * second to last bit of config1 (software reset) | ||
598 | */ | ||
599 | if (chip_id == 0x01 | ||
600 | && (reg_config1 & 0x03) == 0x00 | ||
601 | && reg_convrate <= 0x07) { | ||
602 | kind = max6680; | ||
577 | } | 603 | } |
578 | } | 604 | } |
579 | 605 | ||
@@ -599,6 +625,8 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind) | |||
599 | name = "lm86"; | 625 | name = "lm86"; |
600 | } else if (kind == max6657) { | 626 | } else if (kind == max6657) { |
601 | name = "max6657"; | 627 | name = "max6657"; |
628 | } else if (kind == max6680) { | ||
629 | name = "max6680"; | ||
602 | } else if (kind == adt7461) { | 630 | } else if (kind == adt7461) { |
603 | name = "adt7461"; | 631 | name = "adt7461"; |
604 | } | 632 | } |
@@ -646,7 +674,8 @@ exit: | |||
646 | 674 | ||
647 | static void lm90_init_client(struct i2c_client *client) | 675 | static void lm90_init_client(struct i2c_client *client) |
648 | { | 676 | { |
649 | u8 config; | 677 | u8 config, config_orig; |
678 | struct lm90_data *data = i2c_get_clientdata(client); | ||
650 | 679 | ||
651 | /* | 680 | /* |
652 | * Start the conversions. | 681 | * Start the conversions. |
@@ -657,9 +686,20 @@ static void lm90_init_client(struct i2c_client *client) | |||
657 | dev_warn(&client->dev, "Initialization failed!\n"); | 686 | dev_warn(&client->dev, "Initialization failed!\n"); |
658 | return; | 687 | return; |
659 | } | 688 | } |
660 | if (config & 0x40) | 689 | config_orig = config; |
661 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, | 690 | |
662 | config & 0xBF); /* run */ | 691 | /* |
692 | * Put MAX6680/MAX8881 into extended resolution (bit 0x10, | ||
693 | * 0.125 degree resolution) and range (0x08, extend range | ||
694 | * to -64 degree) mode for the remote temperature sensor. | ||
695 | */ | ||
696 | if (data->kind == max6680) { | ||
697 | config |= 0x18; | ||
698 | } | ||
699 | |||
700 | config &= 0xBF; /* run */ | ||
701 | if (config != config_orig) /* Only write if changed */ | ||
702 | i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); | ||
663 | } | 703 | } |
664 | 704 | ||
665 | static int lm90_detach_client(struct i2c_client *client) | 705 | static int lm90_detach_client(struct i2c_client *client) |
diff --git a/drivers/hwmon/lm93.c b/drivers/hwmon/lm93.c new file mode 100644 index 000000000000..23edf4fe4221 --- /dev/null +++ b/drivers/hwmon/lm93.c | |||
@@ -0,0 +1,2655 @@ | |||
1 | /* | ||
2 | lm93.c - Part of lm_sensors, Linux kernel modules for hardware monitoring | ||
3 | |||
4 | Author/Maintainer: Mark M. Hoffman <mhoffman@lightlink.com> | ||
5 | Copyright (c) 2004 Utilitek Systems, Inc. | ||
6 | |||
7 | derived in part from lm78.c: | ||
8 | Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> | ||
9 | |||
10 | derived in part from lm85.c: | ||
11 | Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> | ||
12 | Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de> | ||
13 | |||
14 | derived in part from w83l785ts.c: | ||
15 | Copyright (c) 2003-2004 Jean Delvare <khali@linux-fr.org> | ||
16 | |||
17 | Ported to Linux 2.6 by Eric J. Bowersox <ericb@aspsys.com> | ||
18 | Copyright (c) 2005 Aspen Systems, Inc. | ||
19 | |||
20 | Adapted to 2.6.20 by Carsten Emde <cbe@osadl.org> | ||
21 | Copyright (c) 2006 Carsten Emde, Open Source Automation Development Lab | ||
22 | |||
23 | Modified for mainline integration by Hans J. Koch <hjk@linutronix.de> | ||
24 | Copyright (c) 2007 Hans J. Koch, Linutronix GmbH | ||
25 | |||
26 | This program is free software; you can redistribute it and/or modify | ||
27 | it under the terms of the GNU General Public License as published by | ||
28 | the Free Software Foundation; either version 2 of the License, or | ||
29 | (at your option) any later version. | ||
30 | |||
31 | This program is distributed in the hope that it will be useful, | ||
32 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
33 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
34 | GNU General Public License for more details. | ||
35 | |||
36 | You should have received a copy of the GNU General Public License | ||
37 | along with this program; if not, write to the Free Software | ||
38 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
39 | */ | ||
40 | |||
41 | #include <linux/module.h> | ||
42 | #include <linux/init.h> | ||
43 | #include <linux/slab.h> | ||
44 | #include <linux/i2c.h> | ||
45 | #include <linux/hwmon.h> | ||
46 | #include <linux/hwmon-sysfs.h> | ||
47 | #include <linux/hwmon-vid.h> | ||
48 | #include <linux/err.h> | ||
49 | #include <linux/delay.h> | ||
50 | |||
51 | /* LM93 REGISTER ADDRESSES */ | ||
52 | |||
53 | /* miscellaneous */ | ||
54 | #define LM93_REG_MFR_ID 0x3e | ||
55 | #define LM93_REG_VER 0x3f | ||
56 | #define LM93_REG_STATUS_CONTROL 0xe2 | ||
57 | #define LM93_REG_CONFIG 0xe3 | ||
58 | #define LM93_REG_SLEEP_CONTROL 0xe4 | ||
59 | |||
60 | /* alarm values start here */ | ||
61 | #define LM93_REG_HOST_ERROR_1 0x48 | ||
62 | |||
63 | /* voltage inputs: in1-in16 (nr => 0-15) */ | ||
64 | #define LM93_REG_IN(nr) (0x56 + (nr)) | ||
65 | #define LM93_REG_IN_MIN(nr) (0x90 + (nr) * 2) | ||
66 | #define LM93_REG_IN_MAX(nr) (0x91 + (nr) * 2) | ||
67 | |||
68 | /* temperature inputs: temp1-temp4 (nr => 0-3) */ | ||
69 | #define LM93_REG_TEMP(nr) (0x50 + (nr)) | ||
70 | #define LM93_REG_TEMP_MIN(nr) (0x78 + (nr) * 2) | ||
71 | #define LM93_REG_TEMP_MAX(nr) (0x79 + (nr) * 2) | ||
72 | |||
73 | /* temp[1-4]_auto_boost (nr => 0-3) */ | ||
74 | #define LM93_REG_BOOST(nr) (0x80 + (nr)) | ||
75 | |||
76 | /* #PROCHOT inputs: prochot1-prochot2 (nr => 0-1) */ | ||
77 | #define LM93_REG_PROCHOT_CUR(nr) (0x67 + (nr) * 2) | ||
78 | #define LM93_REG_PROCHOT_AVG(nr) (0x68 + (nr) * 2) | ||
79 | #define LM93_REG_PROCHOT_MAX(nr) (0xb0 + (nr)) | ||
80 | |||
81 | /* fan tach inputs: fan1-fan4 (nr => 0-3) */ | ||
82 | #define LM93_REG_FAN(nr) (0x6e + (nr) * 2) | ||
83 | #define LM93_REG_FAN_MIN(nr) (0xb4 + (nr) * 2) | ||
84 | |||
85 | /* pwm outputs: pwm1-pwm2 (nr => 0-1, reg => 0-3) */ | ||
86 | #define LM93_REG_PWM_CTL(nr,reg) (0xc8 + (reg) + (nr) * 4) | ||
87 | #define LM93_PWM_CTL1 0x0 | ||
88 | #define LM93_PWM_CTL2 0x1 | ||
89 | #define LM93_PWM_CTL3 0x2 | ||
90 | #define LM93_PWM_CTL4 0x3 | ||
91 | |||
92 | /* GPIO input state */ | ||
93 | #define LM93_REG_GPI 0x6b | ||
94 | |||
95 | /* vid inputs: vid1-vid2 (nr => 0-1) */ | ||
96 | #define LM93_REG_VID(nr) (0x6c + (nr)) | ||
97 | |||
98 | /* vccp1 & vccp2: VID relative inputs (nr => 0-1) */ | ||
99 | #define LM93_REG_VCCP_LIMIT_OFF(nr) (0xb2 + (nr)) | ||
100 | |||
101 | /* temp[1-4]_auto_boost_hyst */ | ||
102 | #define LM93_REG_BOOST_HYST_12 0xc0 | ||
103 | #define LM93_REG_BOOST_HYST_34 0xc1 | ||
104 | #define LM93_REG_BOOST_HYST(nr) (0xc0 + (nr)/2) | ||
105 | |||
106 | /* temp[1-4]_auto_pwm_[min|hyst] */ | ||
107 | #define LM93_REG_PWM_MIN_HYST_12 0xc3 | ||
108 | #define LM93_REG_PWM_MIN_HYST_34 0xc4 | ||
109 | #define LM93_REG_PWM_MIN_HYST(nr) (0xc3 + (nr)/2) | ||
110 | |||
111 | /* prochot_override & prochot_interval */ | ||
112 | #define LM93_REG_PROCHOT_OVERRIDE 0xc6 | ||
113 | #define LM93_REG_PROCHOT_INTERVAL 0xc7 | ||
114 | |||
115 | /* temp[1-4]_auto_base (nr => 0-3) */ | ||
116 | #define LM93_REG_TEMP_BASE(nr) (0xd0 + (nr)) | ||
117 | |||
118 | /* temp[1-4]_auto_offsets (step => 0-11) */ | ||
119 | #define LM93_REG_TEMP_OFFSET(step) (0xd4 + (step)) | ||
120 | |||
121 | /* #PROCHOT & #VRDHOT PWM ramp control */ | ||
122 | #define LM93_REG_PWM_RAMP_CTL 0xbf | ||
123 | |||
124 | /* miscellaneous */ | ||
125 | #define LM93_REG_SFC1 0xbc | ||
126 | #define LM93_REG_SFC2 0xbd | ||
127 | #define LM93_REG_GPI_VID_CTL 0xbe | ||
128 | #define LM93_REG_SF_TACH_TO_PWM 0xe0 | ||
129 | |||
130 | /* error masks */ | ||
131 | #define LM93_REG_GPI_ERR_MASK 0xec | ||
132 | #define LM93_REG_MISC_ERR_MASK 0xed | ||
133 | |||
134 | /* LM93 REGISTER VALUES */ | ||
135 | #define LM93_MFR_ID 0x73 | ||
136 | #define LM93_MFR_ID_PROTOTYPE 0x72 | ||
137 | |||
138 | /* SMBus capabilities */ | ||
139 | #define LM93_SMBUS_FUNC_FULL (I2C_FUNC_SMBUS_BYTE_DATA | \ | ||
140 | I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BLOCK_DATA) | ||
141 | #define LM93_SMBUS_FUNC_MIN (I2C_FUNC_SMBUS_BYTE_DATA | \ | ||
142 | I2C_FUNC_SMBUS_WORD_DATA) | ||
143 | |||
144 | /* Addresses to scan */ | ||
145 | static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; | ||
146 | |||
147 | /* Insmod parameters */ | ||
148 | I2C_CLIENT_INSMOD_1(lm93); | ||
149 | |||
150 | static int disable_block; | ||
151 | module_param(disable_block, bool, 0); | ||
152 | MODULE_PARM_DESC(disable_block, | ||
153 | "Set to non-zero to disable SMBus block data transactions."); | ||
154 | |||
155 | static int init; | ||
156 | module_param(init, bool, 0); | ||
157 | MODULE_PARM_DESC(init, "Set to non-zero to force chip initialization."); | ||
158 | |||
159 | static int vccp_limit_type[2] = {0,0}; | ||
160 | module_param_array(vccp_limit_type, int, NULL, 0); | ||
161 | MODULE_PARM_DESC(vccp_limit_type, "Configures in7 and in8 limit modes."); | ||
162 | |||
163 | static int vid_agtl; | ||
164 | module_param(vid_agtl, int, 0); | ||
165 | MODULE_PARM_DESC(vid_agtl, "Configures VID pin input thresholds."); | ||
166 | |||
167 | /* Driver data */ | ||
168 | static struct i2c_driver lm93_driver; | ||
169 | |||
170 | /* LM93 BLOCK READ COMMANDS */ | ||
171 | static const struct { u8 cmd; u8 len; } lm93_block_read_cmds[12] = { | ||
172 | { 0xf2, 8 }, | ||
173 | { 0xf3, 8 }, | ||
174 | { 0xf4, 6 }, | ||
175 | { 0xf5, 16 }, | ||
176 | { 0xf6, 4 }, | ||
177 | { 0xf7, 8 }, | ||
178 | { 0xf8, 12 }, | ||
179 | { 0xf9, 32 }, | ||
180 | { 0xfa, 8 }, | ||
181 | { 0xfb, 8 }, | ||
182 | { 0xfc, 16 }, | ||
183 | { 0xfd, 9 }, | ||
184 | }; | ||
185 | |||
186 | /* ALARMS: SYSCTL format described further below | ||
187 | REG: 64 bits in 8 registers, as immediately below */ | ||
188 | struct block1_t { | ||
189 | u8 host_status_1; | ||
190 | u8 host_status_2; | ||
191 | u8 host_status_3; | ||
192 | u8 host_status_4; | ||
193 | u8 p1_prochot_status; | ||
194 | u8 p2_prochot_status; | ||
195 | u8 gpi_status; | ||
196 | u8 fan_status; | ||
197 | }; | ||
198 | |||
199 | /* | ||
200 | * Client-specific data | ||
201 | */ | ||
202 | struct lm93_data { | ||
203 | struct i2c_client client; | ||
204 | struct class_device *class_dev; | ||
205 | |||
206 | struct mutex update_lock; | ||
207 | unsigned long last_updated; /* In jiffies */ | ||
208 | |||
209 | /* client update function */ | ||
210 | void (*update)(struct lm93_data *, struct i2c_client *); | ||
211 | |||
212 | char valid; /* !=0 if following fields are valid */ | ||
213 | |||
214 | /* register values, arranged by block read groups */ | ||
215 | struct block1_t block1; | ||
216 | |||
217 | /* temp1 - temp4: unfiltered readings | ||
218 | temp1 - temp2: filtered readings */ | ||
219 | u8 block2[6]; | ||
220 | |||
221 | /* vin1 - vin16: readings */ | ||
222 | u8 block3[16]; | ||
223 | |||
224 | /* prochot1 - prochot2: readings */ | ||
225 | struct { | ||
226 | u8 cur; | ||
227 | u8 avg; | ||
228 | } block4[2]; | ||
229 | |||
230 | /* fan counts 1-4 => 14-bits, LE, *left* justified */ | ||
231 | u16 block5[4]; | ||
232 | |||
233 | /* block6 has a lot of data we don't need */ | ||
234 | struct { | ||
235 | u8 min; | ||
236 | u8 max; | ||
237 | } temp_lim[3]; | ||
238 | |||
239 | /* vin1 - vin16: low and high limits */ | ||
240 | struct { | ||
241 | u8 min; | ||
242 | u8 max; | ||
243 | } block7[16]; | ||
244 | |||
245 | /* fan count limits 1-4 => same format as block5 */ | ||
246 | u16 block8[4]; | ||
247 | |||
248 | /* pwm control registers (2 pwms, 4 regs) */ | ||
249 | u8 block9[2][4]; | ||
250 | |||
251 | /* auto/pwm base temp and offset temp registers */ | ||
252 | struct { | ||
253 | u8 base[4]; | ||
254 | u8 offset[12]; | ||
255 | } block10; | ||
256 | |||
257 | /* master config register */ | ||
258 | u8 config; | ||
259 | |||
260 | /* VID1 & VID2 => register format, 6-bits, right justified */ | ||
261 | u8 vid[2]; | ||
262 | |||
263 | /* prochot1 - prochot2: limits */ | ||
264 | u8 prochot_max[2]; | ||
265 | |||
266 | /* vccp1 & vccp2 (in7 & in8): VID relative limits (register format) */ | ||
267 | u8 vccp_limits[2]; | ||
268 | |||
269 | /* GPIO input state (register format, i.e. inverted) */ | ||
270 | u8 gpi; | ||
271 | |||
272 | /* #PROCHOT override (register format) */ | ||
273 | u8 prochot_override; | ||
274 | |||
275 | /* #PROCHOT intervals (register format) */ | ||
276 | u8 prochot_interval; | ||
277 | |||
278 | /* Fan Boost Temperatures (register format) */ | ||
279 | u8 boost[4]; | ||
280 | |||
281 | /* Fan Boost Hysteresis (register format) */ | ||
282 | u8 boost_hyst[2]; | ||
283 | |||
284 | /* Temperature Zone Min. PWM & Hysteresis (register format) */ | ||
285 | u8 auto_pwm_min_hyst[2]; | ||
286 | |||
287 | /* #PROCHOT & #VRDHOT PWM Ramp Control */ | ||
288 | u8 pwm_ramp_ctl; | ||
289 | |||
290 | /* miscellaneous setup regs */ | ||
291 | u8 sfc1; | ||
292 | u8 sfc2; | ||
293 | u8 sf_tach_to_pwm; | ||
294 | |||
295 | /* The two PWM CTL2 registers can read something other than what was | ||
296 | last written for the OVR_DC field (duty cycle override). So, we | ||
297 | save the user-commanded value here. */ | ||
298 | u8 pwm_override[2]; | ||
299 | }; | ||
300 | |||
301 | /* VID: mV | ||
302 | REG: 6-bits, right justified, *always* using Intel VRM/VRD 10 */ | ||
303 | static int LM93_VID_FROM_REG(u8 reg) | ||
304 | { | ||
305 | return vid_from_reg((reg & 0x3f), 100); | ||
306 | } | ||
307 | |||
308 | /* min, max, and nominal register values, per channel (u8) */ | ||
309 | static const u8 lm93_vin_reg_min[16] = { | ||
310 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
311 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xae, | ||
312 | }; | ||
313 | static const u8 lm93_vin_reg_max[16] = { | ||
314 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
315 | 0xff, 0xfa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd1, | ||
316 | }; | ||
317 | /* Values from the datasheet. They're here for documentation only. | ||
318 | static const u8 lm93_vin_reg_nom[16] = { | ||
319 | 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, | ||
320 | 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x40, 0xc0, | ||
321 | }; | ||
322 | */ | ||
323 | |||
324 | /* min, max, and nominal voltage readings, per channel (mV)*/ | ||
325 | static const unsigned long lm93_vin_val_min[16] = { | ||
326 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
327 | 0, 0, 0, 0, 0, 0, 0, 3000, | ||
328 | }; | ||
329 | |||
330 | static const unsigned long lm93_vin_val_max[16] = { | ||
331 | 1236, 1236, 1236, 1600, 2000, 2000, 1600, 1600, | ||
332 | 4400, 6500, 3333, 2625, 1312, 1312, 1236, 3600, | ||
333 | }; | ||
334 | /* Values from the datasheet. They're here for documentation only. | ||
335 | static const unsigned long lm93_vin_val_nom[16] = { | ||
336 | 927, 927, 927, 1200, 1500, 1500, 1200, 1200, | ||
337 | 3300, 5000, 2500, 1969, 984, 984, 309, 3300, | ||
338 | }; | ||
339 | */ | ||
340 | |||
341 | static unsigned LM93_IN_FROM_REG(int nr, u8 reg) | ||
342 | { | ||
343 | const long uV_max = lm93_vin_val_max[nr] * 1000; | ||
344 | const long uV_min = lm93_vin_val_min[nr] * 1000; | ||
345 | |||
346 | const long slope = (uV_max - uV_min) / | ||
347 | (lm93_vin_reg_max[nr] - lm93_vin_reg_min[nr]); | ||
348 | const long intercept = uV_min - slope * lm93_vin_reg_min[nr]; | ||
349 | |||
350 | return (slope * reg + intercept + 500) / 1000; | ||
351 | } | ||
352 | |||
353 | /* IN: mV, limits determined by channel nr | ||
354 | REG: scaling determined by channel nr */ | ||
355 | static u8 LM93_IN_TO_REG(int nr, unsigned val) | ||
356 | { | ||
357 | /* range limit */ | ||
358 | const long mV = SENSORS_LIMIT(val, | ||
359 | lm93_vin_val_min[nr], lm93_vin_val_max[nr]); | ||
360 | |||
361 | /* try not to lose too much precision here */ | ||
362 | const long uV = mV * 1000; | ||
363 | const long uV_max = lm93_vin_val_max[nr] * 1000; | ||
364 | const long uV_min = lm93_vin_val_min[nr] * 1000; | ||
365 | |||
366 | /* convert */ | ||
367 | const long slope = (uV_max - uV_min) / | ||
368 | (lm93_vin_reg_max[nr] - lm93_vin_reg_min[nr]); | ||
369 | const long intercept = uV_min - slope * lm93_vin_reg_min[nr]; | ||
370 | |||
371 | u8 result = ((uV - intercept + (slope/2)) / slope); | ||
372 | result = SENSORS_LIMIT(result, | ||
373 | lm93_vin_reg_min[nr], lm93_vin_reg_max[nr]); | ||
374 | return result; | ||
375 | } | ||
376 | |||
377 | /* vid in mV, upper == 0 indicates low limit, otherwise upper limit */ | ||
378 | static unsigned LM93_IN_REL_FROM_REG(u8 reg, int upper, int vid) | ||
379 | { | ||
380 | const long uV_offset = upper ? (((reg >> 4 & 0x0f) + 1) * 12500) : | ||
381 | (((reg >> 0 & 0x0f) + 1) * -25000); | ||
382 | const long uV_vid = vid * 1000; | ||
383 | return (uV_vid + uV_offset + 5000) / 10000; | ||
384 | } | ||
385 | |||
386 | #define LM93_IN_MIN_FROM_REG(reg,vid) LM93_IN_REL_FROM_REG(reg,0,vid) | ||
387 | #define LM93_IN_MAX_FROM_REG(reg,vid) LM93_IN_REL_FROM_REG(reg,1,vid) | ||
388 | |||
389 | /* vid in mV , upper == 0 indicates low limit, otherwise upper limit | ||
390 | upper also determines which nibble of the register is returned | ||
391 | (the other nibble will be 0x0) */ | ||
392 | static u8 LM93_IN_REL_TO_REG(unsigned val, int upper, int vid) | ||
393 | { | ||
394 | long uV_offset = vid * 1000 - val * 10000; | ||
395 | if (upper) { | ||
396 | uV_offset = SENSORS_LIMIT(uV_offset, 12500, 200000); | ||
397 | return (u8)((uV_offset / 12500 - 1) << 4); | ||
398 | } else { | ||
399 | uV_offset = SENSORS_LIMIT(uV_offset, -400000, -25000); | ||
400 | return (u8)((uV_offset / -25000 - 1) << 0); | ||
401 | } | ||
402 | } | ||
403 | |||
404 | /* TEMP: 1/1000 degrees C (-128C to +127C) | ||
405 | REG: 1C/bit, two's complement */ | ||
406 | static int LM93_TEMP_FROM_REG(u8 reg) | ||
407 | { | ||
408 | return (s8)reg * 1000; | ||
409 | } | ||
410 | |||
411 | #define LM93_TEMP_MIN (-128000) | ||
412 | #define LM93_TEMP_MAX ( 127000) | ||
413 | |||
414 | /* TEMP: 1/1000 degrees C (-128C to +127C) | ||
415 | REG: 1C/bit, two's complement */ | ||
416 | static u8 LM93_TEMP_TO_REG(int temp) | ||
417 | { | ||
418 | int ntemp = SENSORS_LIMIT(temp, LM93_TEMP_MIN, LM93_TEMP_MAX); | ||
419 | ntemp += (ntemp<0 ? -500 : 500); | ||
420 | return (u8)(ntemp / 1000); | ||
421 | } | ||
422 | |||
423 | /* Determine 4-bit temperature offset resolution */ | ||
424 | static int LM93_TEMP_OFFSET_MODE_FROM_REG(u8 sfc2, int nr) | ||
425 | { | ||
426 | /* mode: 0 => 1C/bit, nonzero => 0.5C/bit */ | ||
427 | return sfc2 & (nr < 2 ? 0x10 : 0x20); | ||
428 | } | ||
429 | |||
430 | /* This function is common to all 4-bit temperature offsets | ||
431 | reg is 4 bits right justified | ||
432 | mode 0 => 1C/bit, mode !0 => 0.5C/bit */ | ||
433 | static int LM93_TEMP_OFFSET_FROM_REG(u8 reg, int mode) | ||
434 | { | ||
435 | return (reg & 0x0f) * (mode ? 5 : 10); | ||
436 | } | ||
437 | |||
438 | #define LM93_TEMP_OFFSET_MIN ( 0) | ||
439 | #define LM93_TEMP_OFFSET_MAX0 (150) | ||
440 | #define LM93_TEMP_OFFSET_MAX1 ( 75) | ||
441 | |||
442 | /* This function is common to all 4-bit temperature offsets | ||
443 | returns 4 bits right justified | ||
444 | mode 0 => 1C/bit, mode !0 => 0.5C/bit */ | ||
445 | static u8 LM93_TEMP_OFFSET_TO_REG(int off, int mode) | ||
446 | { | ||
447 | int factor = mode ? 5 : 10; | ||
448 | |||
449 | off = SENSORS_LIMIT(off, LM93_TEMP_OFFSET_MIN, | ||
450 | mode ? LM93_TEMP_OFFSET_MAX1 : LM93_TEMP_OFFSET_MAX0); | ||
451 | return (u8)((off + factor/2) / factor); | ||
452 | } | ||
453 | |||
454 | /* 0 <= nr <= 3 */ | ||
455 | static int LM93_TEMP_AUTO_OFFSET_FROM_REG(u8 reg, int nr, int mode) | ||
456 | { | ||
457 | /* temp1-temp2 (nr=0,1) use lower nibble */ | ||
458 | if (nr < 2) | ||
459 | return LM93_TEMP_OFFSET_FROM_REG(reg & 0x0f, mode); | ||
460 | |||
461 | /* temp3-temp4 (nr=2,3) use upper nibble */ | ||
462 | else | ||
463 | return LM93_TEMP_OFFSET_FROM_REG(reg >> 4 & 0x0f, mode); | ||
464 | } | ||
465 | |||
466 | /* TEMP: 1/10 degrees C (0C to +15C (mode 0) or +7.5C (mode non-zero)) | ||
467 | REG: 1.0C/bit (mode 0) or 0.5C/bit (mode non-zero) | ||
468 | 0 <= nr <= 3 */ | ||
469 | static u8 LM93_TEMP_AUTO_OFFSET_TO_REG(u8 old, int off, int nr, int mode) | ||
470 | { | ||
471 | u8 new = LM93_TEMP_OFFSET_TO_REG(off, mode); | ||
472 | |||
473 | /* temp1-temp2 (nr=0,1) use lower nibble */ | ||
474 | if (nr < 2) | ||
475 | return (old & 0xf0) | (new & 0x0f); | ||
476 | |||
477 | /* temp3-temp4 (nr=2,3) use upper nibble */ | ||
478 | else | ||
479 | return (new << 4 & 0xf0) | (old & 0x0f); | ||
480 | } | ||
481 | |||
482 | static int LM93_AUTO_BOOST_HYST_FROM_REGS(struct lm93_data *data, int nr, | ||
483 | int mode) | ||
484 | { | ||
485 | u8 reg; | ||
486 | |||
487 | switch (nr) { | ||
488 | case 0: | ||
489 | reg = data->boost_hyst[0] & 0x0f; | ||
490 | break; | ||
491 | case 1: | ||
492 | reg = data->boost_hyst[0] >> 4 & 0x0f; | ||
493 | break; | ||
494 | case 2: | ||
495 | reg = data->boost_hyst[1] & 0x0f; | ||
496 | break; | ||
497 | case 3: | ||
498 | default: | ||
499 | reg = data->boost_hyst[1] >> 4 & 0x0f; | ||
500 | break; | ||
501 | } | ||
502 | |||
503 | return LM93_TEMP_FROM_REG(data->boost[nr]) - | ||
504 | LM93_TEMP_OFFSET_FROM_REG(reg, mode); | ||
505 | } | ||
506 | |||
507 | static u8 LM93_AUTO_BOOST_HYST_TO_REG(struct lm93_data *data, long hyst, | ||
508 | int nr, int mode) | ||
509 | { | ||
510 | u8 reg = LM93_TEMP_OFFSET_TO_REG( | ||
511 | (LM93_TEMP_FROM_REG(data->boost[nr]) - hyst), mode); | ||
512 | |||
513 | switch (nr) { | ||
514 | case 0: | ||
515 | reg = (data->boost_hyst[0] & 0xf0) | (reg & 0x0f); | ||
516 | break; | ||
517 | case 1: | ||
518 | reg = (reg << 4 & 0xf0) | (data->boost_hyst[0] & 0x0f); | ||
519 | break; | ||
520 | case 2: | ||
521 | reg = (data->boost_hyst[1] & 0xf0) | (reg & 0x0f); | ||
522 | break; | ||
523 | case 3: | ||
524 | default: | ||
525 | reg = (reg << 4 & 0xf0) | (data->boost_hyst[1] & 0x0f); | ||
526 | break; | ||
527 | } | ||
528 | |||
529 | return reg; | ||
530 | } | ||
531 | |||
532 | /* PWM: 0-255 per sensors documentation | ||
533 | REG: 0-13 as mapped below... right justified */ | ||
534 | typedef enum { LM93_PWM_MAP_HI_FREQ, LM93_PWM_MAP_LO_FREQ } pwm_freq_t; | ||
535 | static int lm93_pwm_map[2][16] = { | ||
536 | { | ||
537 | 0x00, /* 0.00% */ 0x40, /* 25.00% */ | ||
538 | 0x50, /* 31.25% */ 0x60, /* 37.50% */ | ||
539 | 0x70, /* 43.75% */ 0x80, /* 50.00% */ | ||
540 | 0x90, /* 56.25% */ 0xa0, /* 62.50% */ | ||
541 | 0xb0, /* 68.75% */ 0xc0, /* 75.00% */ | ||
542 | 0xd0, /* 81.25% */ 0xe0, /* 87.50% */ | ||
543 | 0xf0, /* 93.75% */ 0xff, /* 100.00% */ | ||
544 | 0xff, 0xff, /* 14, 15 are reserved and should never occur */ | ||
545 | }, | ||
546 | { | ||
547 | 0x00, /* 0.00% */ 0x40, /* 25.00% */ | ||
548 | 0x49, /* 28.57% */ 0x52, /* 32.14% */ | ||
549 | 0x5b, /* 35.71% */ 0x64, /* 39.29% */ | ||
550 | 0x6d, /* 42.86% */ 0x76, /* 46.43% */ | ||
551 | 0x80, /* 50.00% */ 0x89, /* 53.57% */ | ||
552 | 0x92, /* 57.14% */ 0xb6, /* 71.43% */ | ||
553 | 0xdb, /* 85.71% */ 0xff, /* 100.00% */ | ||
554 | 0xff, 0xff, /* 14, 15 are reserved and should never occur */ | ||
555 | }, | ||
556 | }; | ||
557 | |||
558 | static int LM93_PWM_FROM_REG(u8 reg, pwm_freq_t freq) | ||
559 | { | ||
560 | return lm93_pwm_map[freq][reg & 0x0f]; | ||
561 | } | ||
562 | |||
563 | /* round up to nearest match */ | ||
564 | static u8 LM93_PWM_TO_REG(int pwm, pwm_freq_t freq) | ||
565 | { | ||
566 | int i; | ||
567 | for (i = 0; i < 13; i++) | ||
568 | if (pwm <= lm93_pwm_map[freq][i]) | ||
569 | break; | ||
570 | |||
571 | /* can fall through with i==13 */ | ||
572 | return (u8)i; | ||
573 | } | ||
574 | |||
575 | static int LM93_FAN_FROM_REG(u16 regs) | ||
576 | { | ||
577 | const u16 count = le16_to_cpu(regs) >> 2; | ||
578 | return count==0 ? -1 : count==0x3fff ? 0: 1350000 / count; | ||
579 | } | ||
580 | |||
581 | /* | ||
582 | * RPM: (82.5 to 1350000) | ||
583 | * REG: 14-bits, LE, *left* justified | ||
584 | */ | ||
585 | static u16 LM93_FAN_TO_REG(long rpm) | ||
586 | { | ||
587 | u16 count, regs; | ||
588 | |||
589 | if (rpm == 0) { | ||
590 | count = 0x3fff; | ||
591 | } else { | ||
592 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); | ||
593 | count = SENSORS_LIMIT((1350000 + rpm) / rpm, 1, 0x3ffe); | ||
594 | } | ||
595 | |||
596 | regs = count << 2; | ||
597 | return cpu_to_le16(regs); | ||
598 | } | ||
599 | |||
600 | /* PWM FREQ: HZ | ||
601 | REG: 0-7 as mapped below */ | ||
602 | static int lm93_pwm_freq_map[8] = { | ||
603 | 22500, 96, 84, 72, 60, 48, 36, 12 | ||
604 | }; | ||
605 | |||
606 | static int LM93_PWM_FREQ_FROM_REG(u8 reg) | ||
607 | { | ||
608 | return lm93_pwm_freq_map[reg & 0x07]; | ||
609 | } | ||
610 | |||
611 | /* round up to nearest match */ | ||
612 | static u8 LM93_PWM_FREQ_TO_REG(int freq) | ||
613 | { | ||
614 | int i; | ||
615 | for (i = 7; i > 0; i--) | ||
616 | if (freq <= lm93_pwm_freq_map[i]) | ||
617 | break; | ||
618 | |||
619 | /* can fall through with i==0 */ | ||
620 | return (u8)i; | ||
621 | } | ||
622 | |||
623 | /* TIME: 1/100 seconds | ||
624 | * REG: 0-7 as mapped below */ | ||
625 | static int lm93_spinup_time_map[8] = { | ||
626 | 0, 10, 25, 40, 70, 100, 200, 400, | ||
627 | }; | ||
628 | |||
629 | static int LM93_SPINUP_TIME_FROM_REG(u8 reg) | ||
630 | { | ||
631 | return lm93_spinup_time_map[reg >> 5 & 0x07]; | ||
632 | } | ||
633 | |||
634 | /* round up to nearest match */ | ||
635 | static u8 LM93_SPINUP_TIME_TO_REG(int time) | ||
636 | { | ||
637 | int i; | ||
638 | for (i = 0; i < 7; i++) | ||
639 | if (time <= lm93_spinup_time_map[i]) | ||
640 | break; | ||
641 | |||
642 | /* can fall through with i==8 */ | ||
643 | return (u8)i; | ||
644 | } | ||
645 | |||
646 | #define LM93_RAMP_MIN 0 | ||
647 | #define LM93_RAMP_MAX 75 | ||
648 | |||
649 | static int LM93_RAMP_FROM_REG(u8 reg) | ||
650 | { | ||
651 | return (reg & 0x0f) * 5; | ||
652 | } | ||
653 | |||
654 | /* RAMP: 1/100 seconds | ||
655 | REG: 50mS/bit 4-bits right justified */ | ||
656 | static u8 LM93_RAMP_TO_REG(int ramp) | ||
657 | { | ||
658 | ramp = SENSORS_LIMIT(ramp, LM93_RAMP_MIN, LM93_RAMP_MAX); | ||
659 | return (u8)((ramp + 2) / 5); | ||
660 | } | ||
661 | |||
662 | /* PROCHOT: 0-255, 0 => 0%, 255 => > 96.6% | ||
663 | * REG: (same) */ | ||
664 | static u8 LM93_PROCHOT_TO_REG(long prochot) | ||
665 | { | ||
666 | prochot = SENSORS_LIMIT(prochot, 0, 255); | ||
667 | return (u8)prochot; | ||
668 | } | ||
669 | |||
670 | /* PROCHOT-INTERVAL: 73 - 37200 (1/100 seconds) | ||
671 | * REG: 0-9 as mapped below */ | ||
672 | static int lm93_interval_map[10] = { | ||
673 | 73, 146, 290, 580, 1170, 2330, 4660, 9320, 18600, 37200, | ||
674 | }; | ||
675 | |||
676 | static int LM93_INTERVAL_FROM_REG(u8 reg) | ||
677 | { | ||
678 | return lm93_interval_map[reg & 0x0f]; | ||
679 | } | ||
680 | |||
681 | /* round up to nearest match */ | ||
682 | static u8 LM93_INTERVAL_TO_REG(long interval) | ||
683 | { | ||
684 | int i; | ||
685 | for (i = 0; i < 9; i++) | ||
686 | if (interval <= lm93_interval_map[i]) | ||
687 | break; | ||
688 | |||
689 | /* can fall through with i==9 */ | ||
690 | return (u8)i; | ||
691 | } | ||
692 | |||
693 | /* GPIO: 0-255, GPIO0 is LSB | ||
694 | * REG: inverted */ | ||
695 | static unsigned LM93_GPI_FROM_REG(u8 reg) | ||
696 | { | ||
697 | return ~reg & 0xff; | ||
698 | } | ||
699 | |||
700 | /* alarm bitmask definitions | ||
701 | The LM93 has nearly 64 bits of error status... I've pared that down to | ||
702 | what I think is a useful subset in order to fit it into 32 bits. | ||
703 | |||
704 | Especially note that the #VRD_HOT alarms are missing because we provide | ||
705 | that information as values in another sysfs file. | ||
706 | |||
707 | If libsensors is extended to support 64 bit values, this could be revisited. | ||
708 | */ | ||
709 | #define LM93_ALARM_IN1 0x00000001 | ||
710 | #define LM93_ALARM_IN2 0x00000002 | ||
711 | #define LM93_ALARM_IN3 0x00000004 | ||
712 | #define LM93_ALARM_IN4 0x00000008 | ||
713 | #define LM93_ALARM_IN5 0x00000010 | ||
714 | #define LM93_ALARM_IN6 0x00000020 | ||
715 | #define LM93_ALARM_IN7 0x00000040 | ||
716 | #define LM93_ALARM_IN8 0x00000080 | ||
717 | #define LM93_ALARM_IN9 0x00000100 | ||
718 | #define LM93_ALARM_IN10 0x00000200 | ||
719 | #define LM93_ALARM_IN11 0x00000400 | ||
720 | #define LM93_ALARM_IN12 0x00000800 | ||
721 | #define LM93_ALARM_IN13 0x00001000 | ||
722 | #define LM93_ALARM_IN14 0x00002000 | ||
723 | #define LM93_ALARM_IN15 0x00004000 | ||
724 | #define LM93_ALARM_IN16 0x00008000 | ||
725 | #define LM93_ALARM_FAN1 0x00010000 | ||
726 | #define LM93_ALARM_FAN2 0x00020000 | ||
727 | #define LM93_ALARM_FAN3 0x00040000 | ||
728 | #define LM93_ALARM_FAN4 0x00080000 | ||
729 | #define LM93_ALARM_PH1_ERR 0x00100000 | ||
730 | #define LM93_ALARM_PH2_ERR 0x00200000 | ||
731 | #define LM93_ALARM_SCSI1_ERR 0x00400000 | ||
732 | #define LM93_ALARM_SCSI2_ERR 0x00800000 | ||
733 | #define LM93_ALARM_DVDDP1_ERR 0x01000000 | ||
734 | #define LM93_ALARM_DVDDP2_ERR 0x02000000 | ||
735 | #define LM93_ALARM_D1_ERR 0x04000000 | ||
736 | #define LM93_ALARM_D2_ERR 0x08000000 | ||
737 | #define LM93_ALARM_TEMP1 0x10000000 | ||
738 | #define LM93_ALARM_TEMP2 0x20000000 | ||
739 | #define LM93_ALARM_TEMP3 0x40000000 | ||
740 | |||
741 | static unsigned LM93_ALARMS_FROM_REG(struct block1_t b1) | ||
742 | { | ||
743 | unsigned result; | ||
744 | result = b1.host_status_2 & 0x3f; | ||
745 | |||
746 | if (vccp_limit_type[0]) | ||
747 | result |= (b1.host_status_4 & 0x10) << 2; | ||
748 | else | ||
749 | result |= b1.host_status_2 & 0x40; | ||
750 | |||
751 | if (vccp_limit_type[1]) | ||
752 | result |= (b1.host_status_4 & 0x20) << 2; | ||
753 | else | ||
754 | result |= b1.host_status_2 & 0x80; | ||
755 | |||
756 | result |= b1.host_status_3 << 8; | ||
757 | result |= (b1.fan_status & 0x0f) << 16; | ||
758 | result |= (b1.p1_prochot_status & 0x80) << 13; | ||
759 | result |= (b1.p2_prochot_status & 0x80) << 14; | ||
760 | result |= (b1.host_status_4 & 0xfc) << 20; | ||
761 | result |= (b1.host_status_1 & 0x07) << 28; | ||
762 | return result; | ||
763 | } | ||
764 | |||
765 | #define MAX_RETRIES 5 | ||
766 | |||
767 | static u8 lm93_read_byte(struct i2c_client *client, u8 reg) | ||
768 | { | ||
769 | int value, i; | ||
770 | |||
771 | /* retry in case of read errors */ | ||
772 | for (i=1; i<=MAX_RETRIES; i++) { | ||
773 | if ((value = i2c_smbus_read_byte_data(client, reg)) >= 0) { | ||
774 | return value; | ||
775 | } else { | ||
776 | dev_warn(&client->dev,"lm93: read byte data failed, " | ||
777 | "address 0x%02x.\n", reg); | ||
778 | mdelay(i + 3); | ||
779 | } | ||
780 | |||
781 | } | ||
782 | |||
783 | /* <TODO> what to return in case of error? */ | ||
784 | dev_err(&client->dev,"lm93: All read byte retries failed!!\n"); | ||
785 | return 0; | ||
786 | } | ||
787 | |||
788 | static int lm93_write_byte(struct i2c_client *client, u8 reg, u8 value) | ||
789 | { | ||
790 | int result; | ||
791 | |||
792 | /* <TODO> how to handle write errors? */ | ||
793 | result = i2c_smbus_write_byte_data(client, reg, value); | ||
794 | |||
795 | if (result < 0) | ||
796 | dev_warn(&client->dev,"lm93: write byte data failed, " | ||
797 | "0x%02x at address 0x%02x.\n", value, reg); | ||
798 | |||
799 | return result; | ||
800 | } | ||
801 | |||
802 | static u16 lm93_read_word(struct i2c_client *client, u8 reg) | ||
803 | { | ||
804 | int value, i; | ||
805 | |||
806 | /* retry in case of read errors */ | ||
807 | for (i=1; i<=MAX_RETRIES; i++) { | ||
808 | if ((value = i2c_smbus_read_word_data(client, reg)) >= 0) { | ||
809 | return value; | ||
810 | } else { | ||
811 | dev_warn(&client->dev,"lm93: read word data failed, " | ||
812 | "address 0x%02x.\n", reg); | ||
813 | mdelay(i + 3); | ||
814 | } | ||
815 | |||
816 | } | ||
817 | |||
818 | /* <TODO> what to return in case of error? */ | ||
819 | dev_err(&client->dev,"lm93: All read word retries failed!!\n"); | ||
820 | return 0; | ||
821 | } | ||
822 | |||
823 | static int lm93_write_word(struct i2c_client *client, u8 reg, u16 value) | ||
824 | { | ||
825 | int result; | ||
826 | |||
827 | /* <TODO> how to handle write errors? */ | ||
828 | result = i2c_smbus_write_word_data(client, reg, value); | ||
829 | |||
830 | if (result < 0) | ||
831 | dev_warn(&client->dev,"lm93: write word data failed, " | ||
832 | "0x%04x at address 0x%02x.\n", value, reg); | ||
833 | |||
834 | return result; | ||
835 | } | ||
836 | |||
837 | static u8 lm93_block_buffer[I2C_SMBUS_BLOCK_MAX]; | ||
838 | |||
839 | /* | ||
840 | read block data into values, retry if not expected length | ||
841 | fbn => index to lm93_block_read_cmds table | ||
842 | (Fixed Block Number - section 14.5.2 of LM93 datasheet) | ||
843 | */ | ||
844 | static void lm93_read_block(struct i2c_client *client, u8 fbn, u8 *values) | ||
845 | { | ||
846 | int i, result=0; | ||
847 | |||
848 | for (i = 1; i <= MAX_RETRIES; i++) { | ||
849 | result = i2c_smbus_read_block_data(client, | ||
850 | lm93_block_read_cmds[fbn].cmd, lm93_block_buffer); | ||
851 | |||
852 | if (result == lm93_block_read_cmds[fbn].len) { | ||
853 | break; | ||
854 | } else { | ||
855 | dev_warn(&client->dev,"lm93: block read data failed, " | ||
856 | "command 0x%02x.\n", | ||
857 | lm93_block_read_cmds[fbn].cmd); | ||
858 | mdelay(i + 3); | ||
859 | } | ||
860 | } | ||
861 | |||
862 | if (result == lm93_block_read_cmds[fbn].len) { | ||
863 | memcpy(values,lm93_block_buffer,lm93_block_read_cmds[fbn].len); | ||
864 | } else { | ||
865 | /* <TODO> what to do in case of error? */ | ||
866 | } | ||
867 | } | ||
868 | |||
869 | static struct lm93_data *lm93_update_device(struct device *dev) | ||
870 | { | ||
871 | struct i2c_client *client = to_i2c_client(dev); | ||
872 | struct lm93_data *data = i2c_get_clientdata(client); | ||
873 | const unsigned long interval = HZ + (HZ / 2); | ||
874 | |||
875 | mutex_lock(&data->update_lock); | ||
876 | |||
877 | if (time_after(jiffies, data->last_updated + interval) || | ||
878 | !data->valid) { | ||
879 | |||
880 | data->update(data, client); | ||
881 | data->last_updated = jiffies; | ||
882 | data->valid = 1; | ||
883 | } | ||
884 | |||
885 | mutex_unlock(&data->update_lock); | ||
886 | return data; | ||
887 | } | ||
888 | |||
889 | /* update routine for data that has no corresponding SMBus block command */ | ||
890 | static void lm93_update_client_common(struct lm93_data *data, | ||
891 | struct i2c_client *client) | ||
892 | { | ||
893 | int i; | ||
894 | u8 *ptr; | ||
895 | |||
896 | /* temp1 - temp4: limits */ | ||
897 | for (i = 0; i < 4; i++) { | ||
898 | data->temp_lim[i].min = | ||
899 | lm93_read_byte(client, LM93_REG_TEMP_MIN(i)); | ||
900 | data->temp_lim[i].max = | ||
901 | lm93_read_byte(client, LM93_REG_TEMP_MAX(i)); | ||
902 | } | ||
903 | |||
904 | /* config register */ | ||
905 | data->config = lm93_read_byte(client, LM93_REG_CONFIG); | ||
906 | |||
907 | /* vid1 - vid2: values */ | ||
908 | for (i = 0; i < 2; i++) | ||
909 | data->vid[i] = lm93_read_byte(client, LM93_REG_VID(i)); | ||
910 | |||
911 | /* prochot1 - prochot2: limits */ | ||
912 | for (i = 0; i < 2; i++) | ||
913 | data->prochot_max[i] = lm93_read_byte(client, | ||
914 | LM93_REG_PROCHOT_MAX(i)); | ||
915 | |||
916 | /* vccp1 - vccp2: VID relative limits */ | ||
917 | for (i = 0; i < 2; i++) | ||
918 | data->vccp_limits[i] = lm93_read_byte(client, | ||
919 | LM93_REG_VCCP_LIMIT_OFF(i)); | ||
920 | |||
921 | /* GPIO input state */ | ||
922 | data->gpi = lm93_read_byte(client, LM93_REG_GPI); | ||
923 | |||
924 | /* #PROCHOT override state */ | ||
925 | data->prochot_override = lm93_read_byte(client, | ||
926 | LM93_REG_PROCHOT_OVERRIDE); | ||
927 | |||
928 | /* #PROCHOT intervals */ | ||
929 | data->prochot_interval = lm93_read_byte(client, | ||
930 | LM93_REG_PROCHOT_INTERVAL); | ||
931 | |||
932 | /* Fan Boost Termperature registers */ | ||
933 | for (i = 0; i < 4; i++) | ||
934 | data->boost[i] = lm93_read_byte(client, LM93_REG_BOOST(i)); | ||
935 | |||
936 | /* Fan Boost Temperature Hyst. registers */ | ||
937 | data->boost_hyst[0] = lm93_read_byte(client, LM93_REG_BOOST_HYST_12); | ||
938 | data->boost_hyst[1] = lm93_read_byte(client, LM93_REG_BOOST_HYST_34); | ||
939 | |||
940 | /* Temperature Zone Min. PWM & Hysteresis registers */ | ||
941 | data->auto_pwm_min_hyst[0] = | ||
942 | lm93_read_byte(client, LM93_REG_PWM_MIN_HYST_12); | ||
943 | data->auto_pwm_min_hyst[1] = | ||
944 | lm93_read_byte(client, LM93_REG_PWM_MIN_HYST_34); | ||
945 | |||
946 | /* #PROCHOT & #VRDHOT PWM Ramp Control register */ | ||
947 | data->pwm_ramp_ctl = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL); | ||
948 | |||
949 | /* misc setup registers */ | ||
950 | data->sfc1 = lm93_read_byte(client, LM93_REG_SFC1); | ||
951 | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); | ||
952 | data->sf_tach_to_pwm = lm93_read_byte(client, | ||
953 | LM93_REG_SF_TACH_TO_PWM); | ||
954 | |||
955 | /* write back alarm values to clear */ | ||
956 | for (i = 0, ptr = (u8 *)(&data->block1); i < 8; i++) | ||
957 | lm93_write_byte(client, LM93_REG_HOST_ERROR_1 + i, *(ptr + i)); | ||
958 | } | ||
959 | |||
960 | /* update routine which uses SMBus block data commands */ | ||
961 | static void lm93_update_client_full(struct lm93_data *data, | ||
962 | struct i2c_client *client) | ||
963 | { | ||
964 | dev_dbg(&client->dev,"starting device update (block data enabled)\n"); | ||
965 | |||
966 | /* in1 - in16: values & limits */ | ||
967 | lm93_read_block(client, 3, (u8 *)(data->block3)); | ||
968 | lm93_read_block(client, 7, (u8 *)(data->block7)); | ||
969 | |||
970 | /* temp1 - temp4: values */ | ||
971 | lm93_read_block(client, 2, (u8 *)(data->block2)); | ||
972 | |||
973 | /* prochot1 - prochot2: values */ | ||
974 | lm93_read_block(client, 4, (u8 *)(data->block4)); | ||
975 | |||
976 | /* fan1 - fan4: values & limits */ | ||
977 | lm93_read_block(client, 5, (u8 *)(data->block5)); | ||
978 | lm93_read_block(client, 8, (u8 *)(data->block8)); | ||
979 | |||
980 | /* pmw control registers */ | ||
981 | lm93_read_block(client, 9, (u8 *)(data->block9)); | ||
982 | |||
983 | /* alarm values */ | ||
984 | lm93_read_block(client, 1, (u8 *)(&data->block1)); | ||
985 | |||
986 | /* auto/pwm registers */ | ||
987 | lm93_read_block(client, 10, (u8 *)(&data->block10)); | ||
988 | |||
989 | lm93_update_client_common(data, client); | ||
990 | } | ||
991 | |||
992 | /* update routine which uses SMBus byte/word data commands only */ | ||
993 | static void lm93_update_client_min(struct lm93_data *data, | ||
994 | struct i2c_client *client) | ||
995 | { | ||
996 | int i,j; | ||
997 | u8 *ptr; | ||
998 | |||
999 | dev_dbg(&client->dev,"starting device update (block data disabled)\n"); | ||
1000 | |||
1001 | /* in1 - in16: values & limits */ | ||
1002 | for (i = 0; i < 16; i++) { | ||
1003 | data->block3[i] = | ||
1004 | lm93_read_byte(client, LM93_REG_IN(i)); | ||
1005 | data->block7[i].min = | ||
1006 | lm93_read_byte(client, LM93_REG_IN_MIN(i)); | ||
1007 | data->block7[i].max = | ||
1008 | lm93_read_byte(client, LM93_REG_IN_MAX(i)); | ||
1009 | } | ||
1010 | |||
1011 | /* temp1 - temp4: values */ | ||
1012 | for (i = 0; i < 4; i++) { | ||
1013 | data->block2[i] = | ||
1014 | lm93_read_byte(client, LM93_REG_TEMP(i)); | ||
1015 | } | ||
1016 | |||
1017 | /* prochot1 - prochot2: values */ | ||
1018 | for (i = 0; i < 2; i++) { | ||
1019 | data->block4[i].cur = | ||
1020 | lm93_read_byte(client, LM93_REG_PROCHOT_CUR(i)); | ||
1021 | data->block4[i].avg = | ||
1022 | lm93_read_byte(client, LM93_REG_PROCHOT_AVG(i)); | ||
1023 | } | ||
1024 | |||
1025 | /* fan1 - fan4: values & limits */ | ||
1026 | for (i = 0; i < 4; i++) { | ||
1027 | data->block5[i] = | ||
1028 | lm93_read_word(client, LM93_REG_FAN(i)); | ||
1029 | data->block8[i] = | ||
1030 | lm93_read_word(client, LM93_REG_FAN_MIN(i)); | ||
1031 | } | ||
1032 | |||
1033 | /* pwm control registers */ | ||
1034 | for (i = 0; i < 2; i++) { | ||
1035 | for (j = 0; j < 4; j++) { | ||
1036 | data->block9[i][j] = | ||
1037 | lm93_read_byte(client, LM93_REG_PWM_CTL(i,j)); | ||
1038 | } | ||
1039 | } | ||
1040 | |||
1041 | /* alarm values */ | ||
1042 | for (i = 0, ptr = (u8 *)(&data->block1); i < 8; i++) { | ||
1043 | *(ptr + i) = | ||
1044 | lm93_read_byte(client, LM93_REG_HOST_ERROR_1 + i); | ||
1045 | } | ||
1046 | |||
1047 | /* auto/pwm (base temp) registers */ | ||
1048 | for (i = 0; i < 4; i++) { | ||
1049 | data->block10.base[i] = | ||
1050 | lm93_read_byte(client, LM93_REG_TEMP_BASE(i)); | ||
1051 | } | ||
1052 | |||
1053 | /* auto/pwm (offset temp) registers */ | ||
1054 | for (i = 0; i < 12; i++) { | ||
1055 | data->block10.offset[i] = | ||
1056 | lm93_read_byte(client, LM93_REG_TEMP_OFFSET(i)); | ||
1057 | } | ||
1058 | |||
1059 | lm93_update_client_common(data, client); | ||
1060 | } | ||
1061 | |||
1062 | /* following are the sysfs callback functions */ | ||
1063 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, | ||
1064 | char *buf) | ||
1065 | { | ||
1066 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1067 | |||
1068 | struct lm93_data *data = lm93_update_device(dev); | ||
1069 | return sprintf(buf, "%d\n", LM93_IN_FROM_REG(nr, data->block3[nr])); | ||
1070 | } | ||
1071 | |||
1072 | static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 0); | ||
1073 | static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in, NULL, 1); | ||
1074 | static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in, NULL, 2); | ||
1075 | static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in, NULL, 3); | ||
1076 | static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in, NULL, 4); | ||
1077 | static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in, NULL, 5); | ||
1078 | static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_in, NULL, 6); | ||
1079 | static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_in, NULL, 7); | ||
1080 | static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, show_in, NULL, 8); | ||
1081 | static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, show_in, NULL, 9); | ||
1082 | static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, show_in, NULL, 10); | ||
1083 | static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, show_in, NULL, 11); | ||
1084 | static SENSOR_DEVICE_ATTR(in13_input, S_IRUGO, show_in, NULL, 12); | ||
1085 | static SENSOR_DEVICE_ATTR(in14_input, S_IRUGO, show_in, NULL, 13); | ||
1086 | static SENSOR_DEVICE_ATTR(in15_input, S_IRUGO, show_in, NULL, 14); | ||
1087 | static SENSOR_DEVICE_ATTR(in16_input, S_IRUGO, show_in, NULL, 15); | ||
1088 | |||
1089 | static ssize_t show_in_min(struct device *dev, | ||
1090 | struct device_attribute *attr, char *buf) | ||
1091 | { | ||
1092 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1093 | struct lm93_data *data = lm93_update_device(dev); | ||
1094 | int vccp = nr - 6; | ||
1095 | long rc, vid; | ||
1096 | |||
1097 | if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) { | ||
1098 | vid = LM93_VID_FROM_REG(data->vid[vccp]); | ||
1099 | rc = LM93_IN_MIN_FROM_REG(data->vccp_limits[vccp], vid); | ||
1100 | } | ||
1101 | else { | ||
1102 | rc = LM93_IN_FROM_REG(nr, data->block7[nr].min); \ | ||
1103 | } | ||
1104 | return sprintf(buf, "%ld\n", rc); \ | ||
1105 | } | ||
1106 | |||
1107 | static ssize_t store_in_min(struct device *dev, struct device_attribute *attr, | ||
1108 | const char *buf, size_t count) | ||
1109 | { | ||
1110 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1111 | struct i2c_client *client = to_i2c_client(dev); | ||
1112 | struct lm93_data *data = i2c_get_clientdata(client); | ||
1113 | u32 val = simple_strtoul(buf, NULL, 10); | ||
1114 | int vccp = nr - 6; | ||
1115 | long vid; | ||
1116 | |||
1117 | mutex_lock(&data->update_lock); | ||
1118 | if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) { | ||
1119 | vid = LM93_VID_FROM_REG(data->vid[vccp]); | ||
1120 | data->vccp_limits[vccp] = (data->vccp_limits[vccp] & 0xf0) | | ||
1121 | LM93_IN_REL_TO_REG(val, 0, vid); | ||
1122 | lm93_write_byte(client, LM93_REG_VCCP_LIMIT_OFF(vccp), | ||
1123 | data->vccp_limits[vccp]); | ||
1124 | } | ||
1125 | else { | ||
1126 | data->block7[nr].min = LM93_IN_TO_REG(nr,val); | ||
1127 | lm93_write_byte(client, LM93_REG_IN_MIN(nr), | ||
1128 | data->block7[nr].min); | ||
1129 | } | ||
1130 | mutex_unlock(&data->update_lock); | ||
1131 | return count; | ||
1132 | } | ||
1133 | |||
1134 | static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO, | ||
1135 | show_in_min, store_in_min, 0); | ||
1136 | static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO, | ||
1137 | show_in_min, store_in_min, 1); | ||
1138 | static SENSOR_DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO, | ||
1139 | show_in_min, store_in_min, 2); | ||
1140 | static SENSOR_DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO, | ||
1141 | show_in_min, store_in_min, 3); | ||
1142 | static SENSOR_DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO, | ||
1143 | show_in_min, store_in_min, 4); | ||
1144 | static SENSOR_DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO, | ||
1145 | show_in_min, store_in_min, 5); | ||
1146 | static SENSOR_DEVICE_ATTR(in7_min, S_IWUSR | S_IRUGO, | ||
1147 | show_in_min, store_in_min, 6); | ||
1148 | static SENSOR_DEVICE_ATTR(in8_min, S_IWUSR | S_IRUGO, | ||
1149 | show_in_min, store_in_min, 7); | ||
1150 | static SENSOR_DEVICE_ATTR(in9_min, S_IWUSR | S_IRUGO, | ||
1151 | show_in_min, store_in_min, 8); | ||
1152 | static SENSOR_DEVICE_ATTR(in10_min, S_IWUSR | S_IRUGO, | ||
1153 | show_in_min, store_in_min, 9); | ||
1154 | static SENSOR_DEVICE_ATTR(in11_min, S_IWUSR | S_IRUGO, | ||
1155 | show_in_min, store_in_min, 10); | ||
1156 | static SENSOR_DEVICE_ATTR(in12_min, S_IWUSR | S_IRUGO, | ||
1157 | show_in_min, store_in_min, 11); | ||
1158 | static SENSOR_DEVICE_ATTR(in13_min, S_IWUSR | S_IRUGO, | ||
1159 | show_in_min, store_in_min, 12); | ||
1160 | static SENSOR_DEVICE_ATTR(in14_min, S_IWUSR | S_IRUGO, | ||
1161 | show_in_min, store_in_min, 13); | ||
1162 | static SENSOR_DEVICE_ATTR(in15_min, S_IWUSR | S_IRUGO, | ||
1163 | show_in_min, store_in_min, 14); | ||
1164 | static SENSOR_DEVICE_ATTR(in16_min, S_IWUSR | S_IRUGO, | ||
1165 | show_in_min, store_in_min, 15); | ||
1166 | |||
1167 | static ssize_t show_in_max(struct device *dev, | ||
1168 | struct device_attribute *attr, char *buf) | ||
1169 | { | ||
1170 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1171 | struct lm93_data *data = lm93_update_device(dev); | ||
1172 | int vccp = nr - 6; | ||
1173 | long rc, vid; | ||
1174 | |||
1175 | if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) { | ||
1176 | vid = LM93_VID_FROM_REG(data->vid[vccp]); | ||
1177 | rc = LM93_IN_MAX_FROM_REG(data->vccp_limits[vccp],vid); | ||
1178 | } | ||
1179 | else { | ||
1180 | rc = LM93_IN_FROM_REG(nr,data->block7[nr].max); \ | ||
1181 | } | ||
1182 | return sprintf(buf,"%ld\n",rc); \ | ||
1183 | } | ||
1184 | |||
1185 | static ssize_t store_in_max(struct device *dev, struct device_attribute *attr, | ||
1186 | const char *buf, size_t count) | ||
1187 | { | ||
1188 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1189 | struct i2c_client *client = to_i2c_client(dev); | ||
1190 | struct lm93_data *data = i2c_get_clientdata(client); | ||
1191 | u32 val = simple_strtoul(buf, NULL, 10); | ||
1192 | int vccp = nr - 6; | ||
1193 | long vid; | ||
1194 | |||
1195 | mutex_lock(&data->update_lock); | ||
1196 | if ((nr==6 || nr==7) && (vccp_limit_type[vccp])) { | ||
1197 | vid = LM93_VID_FROM_REG(data->vid[vccp]); | ||
1198 | data->vccp_limits[vccp] = (data->vccp_limits[vccp] & 0x0f) | | ||
1199 | LM93_IN_REL_TO_REG(val, 1, vid); | ||
1200 | lm93_write_byte(client, LM93_REG_VCCP_LIMIT_OFF(vccp), | ||
1201 | data->vccp_limits[vccp]); | ||
1202 | } | ||
1203 | else { | ||
1204 | data->block7[nr].max = LM93_IN_TO_REG(nr,val); | ||
1205 | lm93_write_byte(client, LM93_REG_IN_MAX(nr), | ||
1206 | data->block7[nr].max); | ||
1207 | } | ||
1208 | mutex_unlock(&data->update_lock); | ||
1209 | return count; | ||
1210 | } | ||
1211 | |||
1212 | static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO, | ||
1213 | show_in_max, store_in_max, 0); | ||
1214 | static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO, | ||
1215 | show_in_max, store_in_max, 1); | ||
1216 | static SENSOR_DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO, | ||
1217 | show_in_max, store_in_max, 2); | ||
1218 | static SENSOR_DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO, | ||
1219 | show_in_max, store_in_max, 3); | ||
1220 | static SENSOR_DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO, | ||
1221 | show_in_max, store_in_max, 4); | ||
1222 | static SENSOR_DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO, | ||
1223 | show_in_max, store_in_max, 5); | ||
1224 | static SENSOR_DEVICE_ATTR(in7_max, S_IWUSR | S_IRUGO, | ||
1225 | show_in_max, store_in_max, 6); | ||
1226 | static SENSOR_DEVICE_ATTR(in8_max, S_IWUSR | S_IRUGO, | ||
1227 | show_in_max, store_in_max, 7); | ||
1228 | static SENSOR_DEVICE_ATTR(in9_max, S_IWUSR | S_IRUGO, | ||
1229 | show_in_max, store_in_max, 8); | ||
1230 | static SENSOR_DEVICE_ATTR(in10_max, S_IWUSR | S_IRUGO, | ||
1231 | show_in_max, store_in_max, 9); | ||
1232 | static SENSOR_DEVICE_ATTR(in11_max, S_IWUSR | S_IRUGO, | ||
1233 | show_in_max, store_in_max, 10); | ||
1234 | static SENSOR_DEVICE_ATTR(in12_max, S_IWUSR | S_IRUGO, | ||
1235 | show_in_max, store_in_max, 11); | ||
1236 | static SENSOR_DEVICE_ATTR(in13_max, S_IWUSR | S_IRUGO, | ||
1237 | show_in_max, store_in_max, 12); | ||
1238 | static SENSOR_DEVICE_ATTR(in14_max, S_IWUSR | S_IRUGO, | ||
1239 | show_in_max, store_in_max, 13); | ||
1240 | static SENSOR_DEVICE_ATTR(in15_max, S_IWUSR | S_IRUGO, | ||
1241 | show_in_max, store_in_max, 14); | ||
1242 | static SENSOR_DEVICE_ATTR(in16_max, S_IWUSR | S_IRUGO, | ||
1243 | show_in_max, store_in_max, 15); | ||
1244 | |||
1245 | static ssize_t show_temp(struct device *dev, | ||
1246 | struct device_attribute *attr, char *buf) | ||
1247 | { | ||
1248 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1249 | struct lm93_data *data = lm93_update_device(dev); | ||
1250 | return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->block2[nr])); | ||
1251 | } | ||
1252 | |||
1253 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); | ||
1254 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1); | ||
1255 | static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2); | ||
1256 | |||
1257 | static ssize_t show_temp_min(struct device *dev, | ||
1258 | struct device_attribute *attr, char *buf) | ||
1259 | { | ||
1260 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1261 | struct lm93_data *data = lm93_update_device(dev); | ||
1262 | return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->temp_lim[nr].min)); | ||
1263 | } | ||
1264 | |||
1265 | static ssize_t store_temp_min(struct device *dev, struct device_attribute *attr, | ||
1266 | const char *buf, size_t count) | ||
1267 | { | ||
1268 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1269 | struct i2c_client *client = to_i2c_client(dev); | ||
1270 | struct lm93_data *data = i2c_get_clientdata(client); | ||
1271 | u32 val = simple_strtoul(buf, NULL, 10); | ||
1272 | |||
1273 | mutex_lock(&data->update_lock); | ||
1274 | data->temp_lim[nr].min = LM93_TEMP_TO_REG(val); | ||
1275 | lm93_write_byte(client, LM93_REG_TEMP_MIN(nr), data->temp_lim[nr].min); | ||
1276 | mutex_unlock(&data->update_lock); | ||
1277 | return count; | ||
1278 | } | ||
1279 | |||
1280 | static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, | ||
1281 | show_temp_min, store_temp_min, 0); | ||
1282 | static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, | ||
1283 | show_temp_min, store_temp_min, 1); | ||
1284 | static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, | ||
1285 | show_temp_min, store_temp_min, 2); | ||
1286 | |||
1287 | static ssize_t show_temp_max(struct device *dev, | ||
1288 | struct device_attribute *attr, char *buf) | ||
1289 | { | ||
1290 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1291 | struct lm93_data *data = lm93_update_device(dev); | ||
1292 | return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->temp_lim[nr].max)); | ||
1293 | } | ||
1294 | |||
1295 | static ssize_t store_temp_max(struct device *dev, struct device_attribute *attr, | ||
1296 | const char *buf, size_t count) | ||
1297 | { | ||
1298 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1299 | struct i2c_client *client = to_i2c_client(dev); | ||
1300 | struct lm93_data *data = i2c_get_clientdata(client); | ||
1301 | u32 val = simple_strtoul(buf, NULL, 10); | ||
1302 | |||
1303 | mutex_lock(&data->update_lock); | ||
1304 | data->temp_lim[nr].max = LM93_TEMP_TO_REG(val); | ||
1305 | lm93_write_byte(client, LM93_REG_TEMP_MAX(nr), data->temp_lim[nr].max); | ||
1306 | mutex_unlock(&data->update_lock); | ||
1307 | return count; | ||
1308 | } | ||
1309 | |||
1310 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, | ||
1311 | show_temp_max, store_temp_max, 0); | ||
1312 | static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, | ||
1313 | show_temp_max, store_temp_max, 1); | ||
1314 | static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, | ||
1315 | show_temp_max, store_temp_max, 2); | ||
1316 | |||
1317 | static ssize_t show_temp_auto_base(struct device *dev, | ||
1318 | struct device_attribute *attr, char *buf) | ||
1319 | { | ||
1320 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1321 | struct lm93_data *data = lm93_update_device(dev); | ||
1322 | return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->block10.base[nr])); | ||
1323 | } | ||
1324 | |||
1325 | static ssize_t store_temp_auto_base(struct device *dev, | ||
1326 | struct device_attribute *attr, | ||
1327 | const char *buf, size_t count) | ||
1328 | { | ||
1329 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1330 | struct i2c_client *client = to_i2c_client(dev); | ||
1331 | struct lm93_data *data = i2c_get_clientdata(client); | ||
1332 | u32 val = simple_strtoul(buf, NULL, 10); | ||
1333 | |||
1334 | mutex_lock(&data->update_lock); | ||
1335 | data->block10.base[nr] = LM93_TEMP_TO_REG(val); | ||
1336 | lm93_write_byte(client, LM93_REG_TEMP_BASE(nr), data->block10.base[nr]); | ||
1337 | mutex_unlock(&data->update_lock); | ||
1338 | return count; | ||
1339 | } | ||
1340 | |||
1341 | static SENSOR_DEVICE_ATTR(temp1_auto_base, S_IWUSR | S_IRUGO, | ||
1342 | show_temp_auto_base, store_temp_auto_base, 0); | ||
1343 | static SENSOR_DEVICE_ATTR(temp2_auto_base, S_IWUSR | S_IRUGO, | ||
1344 | show_temp_auto_base, store_temp_auto_base, 1); | ||
1345 | static SENSOR_DEVICE_ATTR(temp3_auto_base, S_IWUSR | S_IRUGO, | ||
1346 | show_temp_auto_base, store_temp_auto_base, 2); | ||
1347 | |||
1348 | static ssize_t show_temp_auto_boost(struct device *dev, | ||
1349 | struct device_attribute *attr,char *buf) | ||
1350 | { | ||
1351 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1352 | struct lm93_data *data = lm93_update_device(dev); | ||
1353 | return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->boost[nr])); | ||
1354 | } | ||
1355 | |||
1356 | static ssize_t store_temp_auto_boost(struct device *dev, | ||
1357 | struct device_attribute *attr, | ||
1358 | const char *buf, size_t count) | ||
1359 | { | ||
1360 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1361 | struct i2c_client *client = to_i2c_client(dev); | ||
1362 | struct lm93_data *data = i2c_get_clientdata(client); | ||
1363 | u32 val = simple_strtoul(buf, NULL, 10); | ||
1364 | |||
1365 | mutex_lock(&data->update_lock); | ||
1366 | data->boost[nr] = LM93_TEMP_TO_REG(val); | ||
1367 | lm93_write_byte(client, LM93_REG_BOOST(nr), data->boost[nr]); | ||
1368 | mutex_unlock(&data->update_lock); | ||
1369 | return count; | ||
1370 | } | ||
1371 | |||
1372 | static SENSOR_DEVICE_ATTR(temp1_auto_boost, S_IWUSR | S_IRUGO, | ||
1373 | show_temp_auto_boost, store_temp_auto_boost, 0); | ||
1374 | static SENSOR_DEVICE_ATTR(temp2_auto_boost, S_IWUSR | S_IRUGO, | ||
1375 | show_temp_auto_boost, store_temp_auto_boost, 1); | ||
1376 | static SENSOR_DEVICE_ATTR(temp3_auto_boost, S_IWUSR | S_IRUGO, | ||
1377 | show_temp_auto_boost, store_temp_auto_boost, 2); | ||
1378 | |||
1379 | static ssize_t show_temp_auto_boost_hyst(struct device *dev, | ||
1380 | struct device_attribute *attr, | ||
1381 | char *buf) | ||
1382 | { | ||
1383 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1384 | struct lm93_data *data = lm93_update_device(dev); | ||
1385 | int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); | ||
1386 | return sprintf(buf,"%d\n", | ||
1387 | LM93_AUTO_BOOST_HYST_FROM_REGS(data, nr, mode)); | ||
1388 | } | ||
1389 | |||
1390 | static ssize_t store_temp_auto_boost_hyst(struct device *dev, | ||
1391 | struct device_attribute *attr, | ||
1392 | const char *buf, size_t count) | ||
1393 | { | ||
1394 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1395 | struct i2c_client *client = to_i2c_client(dev); | ||
1396 | struct lm93_data *data = i2c_get_clientdata(client); | ||
1397 | u32 val = simple_strtoul(buf, NULL, 10); | ||
1398 | |||
1399 | mutex_lock(&data->update_lock); | ||
1400 | /* force 0.5C/bit mode */ | ||
1401 | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); | ||
1402 | data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); | ||
1403 | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); | ||
1404 | data->boost_hyst[nr/2] = LM93_AUTO_BOOST_HYST_TO_REG(data, val, nr, 1); | ||
1405 | lm93_write_byte(client, LM93_REG_BOOST_HYST(nr), | ||
1406 | data->boost_hyst[nr/2]); | ||
1407 | mutex_unlock(&data->update_lock); | ||
1408 | return count; | ||
1409 | } | ||
1410 | |||
1411 | static SENSOR_DEVICE_ATTR(temp1_auto_boost_hyst, S_IWUSR | S_IRUGO, | ||
1412 | show_temp_auto_boost_hyst, | ||
1413 | store_temp_auto_boost_hyst, 0); | ||
1414 | static SENSOR_DEVICE_ATTR(temp2_auto_boost_hyst, S_IWUSR | S_IRUGO, | ||
1415 | show_temp_auto_boost_hyst, | ||
1416 | store_temp_auto_boost_hyst, 1); | ||
1417 | static SENSOR_DEVICE_ATTR(temp3_auto_boost_hyst, S_IWUSR | S_IRUGO, | ||
1418 | show_temp_auto_boost_hyst, | ||
1419 | store_temp_auto_boost_hyst, 2); | ||
1420 | |||
1421 | static ssize_t show_temp_auto_offset(struct device *dev, | ||
1422 | struct device_attribute *attr, char *buf) | ||
1423 | { | ||
1424 | struct sensor_device_attribute_2 *s_attr = to_sensor_dev_attr_2(attr); | ||
1425 | int nr = s_attr->index; | ||
1426 | int ofs = s_attr->nr; | ||
1427 | struct lm93_data *data = lm93_update_device(dev); | ||
1428 | int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); | ||
1429 | return sprintf(buf,"%d\n", | ||
1430 | LM93_TEMP_AUTO_OFFSET_FROM_REG(data->block10.offset[ofs], | ||
1431 | nr,mode)); | ||
1432 | } | ||
1433 | |||
1434 | static ssize_t store_temp_auto_offset(struct device *dev, | ||
1435 | struct device_attribute *attr, | ||
1436 | const char *buf, size_t count) | ||
1437 | { | ||
1438 | struct sensor_device_attribute_2 *s_attr = to_sensor_dev_attr_2(attr); | ||
1439 | int nr = s_attr->index; | ||
1440 | int ofs = s_attr->nr; | ||
1441 | struct i2c_client *client = to_i2c_client(dev); | ||
1442 | struct lm93_data *data = i2c_get_clientdata(client); | ||
1443 | u32 val = simple_strtoul(buf, NULL, 10); | ||
1444 | |||
1445 | mutex_lock(&data->update_lock); | ||
1446 | /* force 0.5C/bit mode */ | ||
1447 | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); | ||
1448 | data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); | ||
1449 | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); | ||
1450 | data->block10.offset[ofs] = LM93_TEMP_AUTO_OFFSET_TO_REG( | ||
1451 | data->block10.offset[ofs], val, nr, 1); | ||
1452 | lm93_write_byte(client, LM93_REG_TEMP_OFFSET(ofs), | ||
1453 | data->block10.offset[ofs]); | ||
1454 | mutex_unlock(&data->update_lock); | ||
1455 | return count; | ||
1456 | } | ||
1457 | |||
1458 | static SENSOR_DEVICE_ATTR_2(temp1_auto_offset1, S_IWUSR | S_IRUGO, | ||
1459 | show_temp_auto_offset, store_temp_auto_offset, 0, 0); | ||
1460 | static SENSOR_DEVICE_ATTR_2(temp1_auto_offset2, S_IWUSR | S_IRUGO, | ||
1461 | show_temp_auto_offset, store_temp_auto_offset, 1, 0); | ||
1462 | static SENSOR_DEVICE_ATTR_2(temp1_auto_offset3, S_IWUSR | S_IRUGO, | ||
1463 | show_temp_auto_offset, store_temp_auto_offset, 2, 0); | ||
1464 | static SENSOR_DEVICE_ATTR_2(temp1_auto_offset4, S_IWUSR | S_IRUGO, | ||
1465 | show_temp_auto_offset, store_temp_auto_offset, 3, 0); | ||
1466 | static SENSOR_DEVICE_ATTR_2(temp1_auto_offset5, S_IWUSR | S_IRUGO, | ||
1467 | show_temp_auto_offset, store_temp_auto_offset, 4, 0); | ||
1468 | static SENSOR_DEVICE_ATTR_2(temp1_auto_offset6, S_IWUSR | S_IRUGO, | ||
1469 | show_temp_auto_offset, store_temp_auto_offset, 5, 0); | ||
1470 | static SENSOR_DEVICE_ATTR_2(temp1_auto_offset7, S_IWUSR | S_IRUGO, | ||
1471 | show_temp_auto_offset, store_temp_auto_offset, 6, 0); | ||
1472 | static SENSOR_DEVICE_ATTR_2(temp1_auto_offset8, S_IWUSR | S_IRUGO, | ||
1473 | show_temp_auto_offset, store_temp_auto_offset, 7, 0); | ||
1474 | static SENSOR_DEVICE_ATTR_2(temp1_auto_offset9, S_IWUSR | S_IRUGO, | ||
1475 | show_temp_auto_offset, store_temp_auto_offset, 8, 0); | ||
1476 | static SENSOR_DEVICE_ATTR_2(temp1_auto_offset10, S_IWUSR | S_IRUGO, | ||
1477 | show_temp_auto_offset, store_temp_auto_offset, 9, 0); | ||
1478 | static SENSOR_DEVICE_ATTR_2(temp1_auto_offset11, S_IWUSR | S_IRUGO, | ||
1479 | show_temp_auto_offset, store_temp_auto_offset, 10, 0); | ||
1480 | static SENSOR_DEVICE_ATTR_2(temp1_auto_offset12, S_IWUSR | S_IRUGO, | ||
1481 | show_temp_auto_offset, store_temp_auto_offset, 11, 0); | ||
1482 | static SENSOR_DEVICE_ATTR_2(temp2_auto_offset1, S_IWUSR | S_IRUGO, | ||
1483 | show_temp_auto_offset, store_temp_auto_offset, 0, 1); | ||
1484 | static SENSOR_DEVICE_ATTR_2(temp2_auto_offset2, S_IWUSR | S_IRUGO, | ||
1485 | show_temp_auto_offset, store_temp_auto_offset, 1, 1); | ||
1486 | static SENSOR_DEVICE_ATTR_2(temp2_auto_offset3, S_IWUSR | S_IRUGO, | ||
1487 | show_temp_auto_offset, store_temp_auto_offset, 2, 1); | ||
1488 | static SENSOR_DEVICE_ATTR_2(temp2_auto_offset4, S_IWUSR | S_IRUGO, | ||
1489 | show_temp_auto_offset, store_temp_auto_offset, 3, 1); | ||
1490 | static SENSOR_DEVICE_ATTR_2(temp2_auto_offset5, S_IWUSR | S_IRUGO, | ||
1491 | show_temp_auto_offset, store_temp_auto_offset, 4, 1); | ||
1492 | static SENSOR_DEVICE_ATTR_2(temp2_auto_offset6, S_IWUSR | S_IRUGO, | ||
1493 | show_temp_auto_offset, store_temp_auto_offset, 5, 1); | ||
1494 | static SENSOR_DEVICE_ATTR_2(temp2_auto_offset7, S_IWUSR | S_IRUGO, | ||
1495 | show_temp_auto_offset, store_temp_auto_offset, 6, 1); | ||
1496 | static SENSOR_DEVICE_ATTR_2(temp2_auto_offset8, S_IWUSR | S_IRUGO, | ||
1497 | show_temp_auto_offset, store_temp_auto_offset, 7, 1); | ||
1498 | static SENSOR_DEVICE_ATTR_2(temp2_auto_offset9, S_IWUSR | S_IRUGO, | ||
1499 | show_temp_auto_offset, store_temp_auto_offset, 8, 1); | ||
1500 | static SENSOR_DEVICE_ATTR_2(temp2_auto_offset10, S_IWUSR | S_IRUGO, | ||
1501 | show_temp_auto_offset, store_temp_auto_offset, 9, 1); | ||
1502 | static SENSOR_DEVICE_ATTR_2(temp2_auto_offset11, S_IWUSR | S_IRUGO, | ||
1503 | show_temp_auto_offset, store_temp_auto_offset, 10, 1); | ||
1504 | static SENSOR_DEVICE_ATTR_2(temp2_auto_offset12, S_IWUSR | S_IRUGO, | ||
1505 | show_temp_auto_offset, store_temp_auto_offset, 11, 1); | ||
1506 | static SENSOR_DEVICE_ATTR_2(temp3_auto_offset1, S_IWUSR | S_IRUGO, | ||
1507 | show_temp_auto_offset, store_temp_auto_offset, 0, 2); | ||
1508 | static SENSOR_DEVICE_ATTR_2(temp3_auto_offset2, S_IWUSR | S_IRUGO, | ||
1509 | show_temp_auto_offset, store_temp_auto_offset, 1, 2); | ||
1510 | static SENSOR_DEVICE_ATTR_2(temp3_auto_offset3, S_IWUSR | S_IRUGO, | ||
1511 | show_temp_auto_offset, store_temp_auto_offset, 2, 2); | ||
1512 | static SENSOR_DEVICE_ATTR_2(temp3_auto_offset4, S_IWUSR | S_IRUGO, | ||
1513 | show_temp_auto_offset, store_temp_auto_offset, 3, 2); | ||
1514 | static SENSOR_DEVICE_ATTR_2(temp3_auto_offset5, S_IWUSR | S_IRUGO, | ||
1515 | show_temp_auto_offset, store_temp_auto_offset, 4, 2); | ||
1516 | static SENSOR_DEVICE_ATTR_2(temp3_auto_offset6, S_IWUSR | S_IRUGO, | ||
1517 | show_temp_auto_offset, store_temp_auto_offset, 5, 2); | ||
1518 | static SENSOR_DEVICE_ATTR_2(temp3_auto_offset7, S_IWUSR | S_IRUGO, | ||
1519 | show_temp_auto_offset, store_temp_auto_offset, 6, 2); | ||
1520 | static SENSOR_DEVICE_ATTR_2(temp3_auto_offset8, S_IWUSR | S_IRUGO, | ||
1521 | show_temp_auto_offset, store_temp_auto_offset, 7, 2); | ||
1522 | static SENSOR_DEVICE_ATTR_2(temp3_auto_offset9, S_IWUSR | S_IRUGO, | ||
1523 | show_temp_auto_offset, store_temp_auto_offset, 8, 2); | ||
1524 | static SENSOR_DEVICE_ATTR_2(temp3_auto_offset10, S_IWUSR | S_IRUGO, | ||
1525 | show_temp_auto_offset, store_temp_auto_offset, 9, 2); | ||
1526 | static SENSOR_DEVICE_ATTR_2(temp3_auto_offset11, S_IWUSR | S_IRUGO, | ||
1527 | show_temp_auto_offset, store_temp_auto_offset, 10, 2); | ||
1528 | static SENSOR_DEVICE_ATTR_2(temp3_auto_offset12, S_IWUSR | S_IRUGO, | ||
1529 | show_temp_auto_offset, store_temp_auto_offset, 11, 2); | ||
1530 | |||
1531 | static ssize_t show_temp_auto_pwm_min(struct device *dev, | ||
1532 | struct device_attribute *attr, char *buf) | ||
1533 | { | ||
1534 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1535 | u8 reg, ctl4; | ||
1536 | struct lm93_data *data = lm93_update_device(dev); | ||
1537 | reg = data->auto_pwm_min_hyst[nr/2] >> 4 & 0x0f; | ||
1538 | ctl4 = data->block9[nr][LM93_PWM_CTL4]; | ||
1539 | return sprintf(buf,"%d\n",LM93_PWM_FROM_REG(reg, (ctl4 & 0x07) ? | ||
1540 | LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ)); | ||
1541 | } | ||
1542 | |||
1543 | static ssize_t store_temp_auto_pwm_min(struct device *dev, | ||
1544 | struct device_attribute *attr, | ||
1545 | const char *buf, size_t count) | ||
1546 | { | ||
1547 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1548 | struct i2c_client *client = to_i2c_client(dev); | ||
1549 | struct lm93_data *data = i2c_get_clientdata(client); | ||
1550 | u32 val = simple_strtoul(buf, NULL, 10); | ||
1551 | u8 reg, ctl4; | ||
1552 | |||
1553 | mutex_lock(&data->update_lock); | ||
1554 | reg = lm93_read_byte(client, LM93_REG_PWM_MIN_HYST(nr)); | ||
1555 | ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4)); | ||
1556 | reg = (reg & 0x0f) | | ||
1557 | LM93_PWM_TO_REG(val, (ctl4 & 0x07) ? | ||
1558 | LM93_PWM_MAP_LO_FREQ : | ||
1559 | LM93_PWM_MAP_HI_FREQ) << 4; | ||
1560 | data->auto_pwm_min_hyst[nr/2] = reg; | ||
1561 | lm93_write_byte(client, LM93_REG_PWM_MIN_HYST(nr), reg); | ||
1562 | mutex_unlock(&data->update_lock); | ||
1563 | return count; | ||
1564 | } | ||
1565 | |||
1566 | static SENSOR_DEVICE_ATTR(temp1_auto_pwm_min, S_IWUSR | S_IRUGO, | ||
1567 | show_temp_auto_pwm_min, | ||
1568 | store_temp_auto_pwm_min, 0); | ||
1569 | static SENSOR_DEVICE_ATTR(temp2_auto_pwm_min, S_IWUSR | S_IRUGO, | ||
1570 | show_temp_auto_pwm_min, | ||
1571 | store_temp_auto_pwm_min, 1); | ||
1572 | static SENSOR_DEVICE_ATTR(temp3_auto_pwm_min, S_IWUSR | S_IRUGO, | ||
1573 | show_temp_auto_pwm_min, | ||
1574 | store_temp_auto_pwm_min, 2); | ||
1575 | |||
1576 | static ssize_t show_temp_auto_offset_hyst(struct device *dev, | ||
1577 | struct device_attribute *attr, char *buf) | ||
1578 | { | ||
1579 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1580 | struct lm93_data *data = lm93_update_device(dev); | ||
1581 | int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); | ||
1582 | return sprintf(buf,"%d\n",LM93_TEMP_OFFSET_FROM_REG( | ||
1583 | data->auto_pwm_min_hyst[nr/2], mode)); | ||
1584 | } | ||
1585 | |||
1586 | static ssize_t store_temp_auto_offset_hyst(struct device *dev, | ||
1587 | struct device_attribute *attr, | ||
1588 | const char *buf, size_t count) | ||
1589 | { | ||
1590 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1591 | struct i2c_client *client = to_i2c_client(dev); | ||
1592 | struct lm93_data *data = i2c_get_clientdata(client); | ||
1593 | u32 val = simple_strtoul(buf, NULL, 10); | ||
1594 | u8 reg; | ||
1595 | |||
1596 | mutex_lock(&data->update_lock); | ||
1597 | /* force 0.5C/bit mode */ | ||
1598 | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); | ||
1599 | data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); | ||
1600 | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); | ||
1601 | reg = data->auto_pwm_min_hyst[nr/2]; | ||
1602 | reg = (reg & 0xf0) | (LM93_TEMP_OFFSET_TO_REG(val, 1) & 0x0f); | ||
1603 | data->auto_pwm_min_hyst[nr/2] = reg; | ||
1604 | lm93_write_byte(client, LM93_REG_PWM_MIN_HYST(nr), reg); | ||
1605 | mutex_unlock(&data->update_lock); | ||
1606 | return count; | ||
1607 | } | ||
1608 | |||
1609 | static SENSOR_DEVICE_ATTR(temp1_auto_offset_hyst, S_IWUSR | S_IRUGO, | ||
1610 | show_temp_auto_offset_hyst, | ||
1611 | store_temp_auto_offset_hyst, 0); | ||
1612 | static SENSOR_DEVICE_ATTR(temp2_auto_offset_hyst, S_IWUSR | S_IRUGO, | ||
1613 | show_temp_auto_offset_hyst, | ||
1614 | store_temp_auto_offset_hyst, 1); | ||
1615 | static SENSOR_DEVICE_ATTR(temp3_auto_offset_hyst, S_IWUSR | S_IRUGO, | ||
1616 | show_temp_auto_offset_hyst, | ||
1617 | store_temp_auto_offset_hyst, 2); | ||
1618 | |||
1619 | static ssize_t show_fan_input(struct device *dev, | ||
1620 | struct device_attribute *attr, char *buf) | ||
1621 | { | ||
1622 | struct sensor_device_attribute *s_attr = to_sensor_dev_attr(attr); | ||
1623 | int nr = s_attr->index; | ||
1624 | struct lm93_data *data = lm93_update_device(dev); | ||
1625 | |||
1626 | return sprintf(buf,"%d\n",LM93_FAN_FROM_REG(data->block5[nr])); | ||
1627 | } | ||
1628 | |||
1629 | static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0); | ||
1630 | static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1); | ||
1631 | static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan_input, NULL, 2); | ||
1632 | static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan_input, NULL, 3); | ||
1633 | |||
1634 | static ssize_t show_fan_min(struct device *dev, | ||
1635 | struct device_attribute *attr, char *buf) | ||
1636 | { | ||
1637 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1638 | struct lm93_data *data = lm93_update_device(dev); | ||
1639 | |||
1640 | return sprintf(buf,"%d\n",LM93_FAN_FROM_REG(data->block8[nr])); | ||
1641 | } | ||
1642 | |||
1643 | static ssize_t store_fan_min(struct device *dev, struct device_attribute *attr, | ||
1644 | const char *buf, size_t count) | ||
1645 | { | ||
1646 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1647 | struct i2c_client *client = to_i2c_client(dev); | ||
1648 | struct lm93_data *data = i2c_get_clientdata(client); | ||
1649 | u32 val = simple_strtoul(buf, NULL, 10); | ||
1650 | |||
1651 | mutex_lock(&data->update_lock); | ||
1652 | data->block8[nr] = LM93_FAN_TO_REG(val); | ||
1653 | lm93_write_word(client,LM93_REG_FAN_MIN(nr),data->block8[nr]); | ||
1654 | mutex_unlock(&data->update_lock); | ||
1655 | return count; | ||
1656 | } | ||
1657 | |||
1658 | static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, | ||
1659 | show_fan_min, store_fan_min, 0); | ||
1660 | static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, | ||
1661 | show_fan_min, store_fan_min, 1); | ||
1662 | static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO, | ||
1663 | show_fan_min, store_fan_min, 2); | ||
1664 | static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO, | ||
1665 | show_fan_min, store_fan_min, 3); | ||
1666 | |||
1667 | /* some tedious bit-twiddling here to deal with the register format: | ||
1668 | |||
1669 | data->sf_tach_to_pwm: (tach to pwm mapping bits) | ||
1670 | |||
1671 | bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | ||
1672 | T4:P2 T4:P1 T3:P2 T3:P1 T2:P2 T2:P1 T1:P2 T1:P1 | ||
1673 | |||
1674 | data->sfc2: (enable bits) | ||
1675 | |||
1676 | bit | 3 | 2 | 1 | 0 | ||
1677 | T4 T3 T2 T1 | ||
1678 | */ | ||
1679 | |||
1680 | static ssize_t show_fan_smart_tach(struct device *dev, | ||
1681 | struct device_attribute *attr, char *buf) | ||
1682 | { | ||
1683 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1684 | struct lm93_data *data = lm93_update_device(dev); | ||
1685 | long rc = 0; | ||
1686 | int mapping; | ||
1687 | |||
1688 | /* extract the relevant mapping */ | ||
1689 | mapping = (data->sf_tach_to_pwm >> (nr * 2)) & 0x03; | ||
1690 | |||
1691 | /* if there's a mapping and it's enabled */ | ||
1692 | if (mapping && ((data->sfc2 >> nr) & 0x01)) | ||
1693 | rc = mapping; | ||
1694 | return sprintf(buf,"%ld\n",rc); | ||
1695 | } | ||
1696 | |||
1697 | /* helper function - must grab data->update_lock before calling | ||
1698 | fan is 0-3, indicating fan1-fan4 */ | ||
1699 | static void lm93_write_fan_smart_tach(struct i2c_client *client, | ||
1700 | struct lm93_data *data, int fan, long value) | ||
1701 | { | ||
1702 | /* insert the new mapping and write it out */ | ||
1703 | data->sf_tach_to_pwm = lm93_read_byte(client, LM93_REG_SF_TACH_TO_PWM); | ||
1704 | data->sf_tach_to_pwm &= ~(0x3 << fan * 2); | ||
1705 | data->sf_tach_to_pwm |= value << fan * 2; | ||
1706 | lm93_write_byte(client, LM93_REG_SF_TACH_TO_PWM, data->sf_tach_to_pwm); | ||
1707 | |||
1708 | /* insert the enable bit and write it out */ | ||
1709 | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); | ||
1710 | if (value) | ||
1711 | data->sfc2 |= 1 << fan; | ||
1712 | else | ||
1713 | data->sfc2 &= ~(1 << fan); | ||
1714 | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); | ||
1715 | } | ||
1716 | |||
1717 | static ssize_t store_fan_smart_tach(struct device *dev, | ||
1718 | struct device_attribute *attr, | ||
1719 | const char *buf, size_t count) | ||
1720 | { | ||
1721 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1722 | struct i2c_client *client = to_i2c_client(dev); | ||
1723 | struct lm93_data *data = i2c_get_clientdata(client); | ||
1724 | u32 val = simple_strtoul(buf, NULL, 10); | ||
1725 | |||
1726 | mutex_lock(&data->update_lock); | ||
1727 | /* sanity test, ignore the write otherwise */ | ||
1728 | if (0 <= val && val <= 2) { | ||
1729 | /* can't enable if pwm freq is 22.5KHz */ | ||
1730 | if (val) { | ||
1731 | u8 ctl4 = lm93_read_byte(client, | ||
1732 | LM93_REG_PWM_CTL(val-1,LM93_PWM_CTL4)); | ||
1733 | if ((ctl4 & 0x07) == 0) | ||
1734 | val = 0; | ||
1735 | } | ||
1736 | lm93_write_fan_smart_tach(client, data, nr, val); | ||
1737 | } | ||
1738 | mutex_unlock(&data->update_lock); | ||
1739 | return count; | ||
1740 | } | ||
1741 | |||
1742 | static SENSOR_DEVICE_ATTR(fan1_smart_tach, S_IWUSR | S_IRUGO, | ||
1743 | show_fan_smart_tach, store_fan_smart_tach, 0); | ||
1744 | static SENSOR_DEVICE_ATTR(fan2_smart_tach, S_IWUSR | S_IRUGO, | ||
1745 | show_fan_smart_tach, store_fan_smart_tach, 1); | ||
1746 | static SENSOR_DEVICE_ATTR(fan3_smart_tach, S_IWUSR | S_IRUGO, | ||
1747 | show_fan_smart_tach, store_fan_smart_tach, 2); | ||
1748 | static SENSOR_DEVICE_ATTR(fan4_smart_tach, S_IWUSR | S_IRUGO, | ||
1749 | show_fan_smart_tach, store_fan_smart_tach, 3); | ||
1750 | |||
1751 | static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, | ||
1752 | char *buf) | ||
1753 | { | ||
1754 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1755 | struct lm93_data *data = lm93_update_device(dev); | ||
1756 | u8 ctl2, ctl4; | ||
1757 | long rc; | ||
1758 | |||
1759 | ctl2 = data->block9[nr][LM93_PWM_CTL2]; | ||
1760 | ctl4 = data->block9[nr][LM93_PWM_CTL4]; | ||
1761 | if (ctl2 & 0x01) /* show user commanded value if enabled */ | ||
1762 | rc = data->pwm_override[nr]; | ||
1763 | else /* show present h/w value if manual pwm disabled */ | ||
1764 | rc = LM93_PWM_FROM_REG(ctl2 >> 4, (ctl4 & 0x07) ? | ||
1765 | LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ); | ||
1766 | return sprintf(buf,"%ld\n",rc); | ||
1767 | } | ||
1768 | |||
1769 | static ssize_t store_pwm(struct device *dev, struct device_attribute *attr, | ||
1770 | const char *buf, size_t count) | ||
1771 | { | ||
1772 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1773 | struct i2c_client *client = to_i2c_client(dev); | ||
1774 | struct lm93_data *data = i2c_get_clientdata(client); | ||
1775 | u32 val = simple_strtoul(buf, NULL, 10); | ||
1776 | u8 ctl2, ctl4; | ||
1777 | |||
1778 | mutex_lock(&data->update_lock); | ||
1779 | ctl2 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2)); | ||
1780 | ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4)); | ||
1781 | ctl2 = (ctl2 & 0x0f) | LM93_PWM_TO_REG(val,(ctl4 & 0x07) ? | ||
1782 | LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ) << 4; | ||
1783 | /* save user commanded value */ | ||
1784 | data->pwm_override[nr] = LM93_PWM_FROM_REG(ctl2 >> 4, | ||
1785 | (ctl4 & 0x07) ? LM93_PWM_MAP_LO_FREQ : | ||
1786 | LM93_PWM_MAP_HI_FREQ); | ||
1787 | lm93_write_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2),ctl2); | ||
1788 | mutex_unlock(&data->update_lock); | ||
1789 | return count; | ||
1790 | } | ||
1791 | |||
1792 | static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0); | ||
1793 | static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1); | ||
1794 | |||
1795 | static ssize_t show_pwm_enable(struct device *dev, | ||
1796 | struct device_attribute *attr, char *buf) | ||
1797 | { | ||
1798 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1799 | struct lm93_data *data = lm93_update_device(dev); | ||
1800 | u8 ctl2; | ||
1801 | long rc; | ||
1802 | |||
1803 | ctl2 = data->block9[nr][LM93_PWM_CTL2]; | ||
1804 | if (ctl2 & 0x01) /* manual override enabled ? */ | ||
1805 | rc = ((ctl2 & 0xF0) == 0xF0) ? 0 : 1; | ||
1806 | else | ||
1807 | rc = 2; | ||
1808 | return sprintf(buf,"%ld\n",rc); | ||
1809 | } | ||
1810 | |||
1811 | static ssize_t store_pwm_enable(struct device *dev, | ||
1812 | struct device_attribute *attr, | ||
1813 | const char *buf, size_t count) | ||
1814 | { | ||
1815 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1816 | struct i2c_client *client = to_i2c_client(dev); | ||
1817 | struct lm93_data *data = i2c_get_clientdata(client); | ||
1818 | u32 val = simple_strtoul(buf, NULL, 10); | ||
1819 | u8 ctl2; | ||
1820 | |||
1821 | mutex_lock(&data->update_lock); | ||
1822 | ctl2 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2)); | ||
1823 | |||
1824 | switch (val) { | ||
1825 | case 0: | ||
1826 | ctl2 |= 0xF1; /* enable manual override, set PWM to max */ | ||
1827 | break; | ||
1828 | case 1: ctl2 |= 0x01; /* enable manual override */ | ||
1829 | break; | ||
1830 | case 2: ctl2 &= ~0x01; /* disable manual override */ | ||
1831 | break; | ||
1832 | default: | ||
1833 | mutex_unlock(&data->update_lock); | ||
1834 | return -EINVAL; | ||
1835 | } | ||
1836 | |||
1837 | lm93_write_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL2),ctl2); | ||
1838 | mutex_unlock(&data->update_lock); | ||
1839 | return count; | ||
1840 | } | ||
1841 | |||
1842 | static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, | ||
1843 | show_pwm_enable, store_pwm_enable, 0); | ||
1844 | static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, | ||
1845 | show_pwm_enable, store_pwm_enable, 1); | ||
1846 | |||
1847 | static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr, | ||
1848 | char *buf) | ||
1849 | { | ||
1850 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1851 | struct lm93_data *data = lm93_update_device(dev); | ||
1852 | u8 ctl4; | ||
1853 | |||
1854 | ctl4 = data->block9[nr][LM93_PWM_CTL4]; | ||
1855 | return sprintf(buf,"%d\n",LM93_PWM_FREQ_FROM_REG(ctl4)); | ||
1856 | } | ||
1857 | |||
1858 | /* helper function - must grab data->update_lock before calling | ||
1859 | pwm is 0-1, indicating pwm1-pwm2 | ||
1860 | this disables smart tach for all tach channels bound to the given pwm */ | ||
1861 | static void lm93_disable_fan_smart_tach(struct i2c_client *client, | ||
1862 | struct lm93_data *data, int pwm) | ||
1863 | { | ||
1864 | int mapping = lm93_read_byte(client, LM93_REG_SF_TACH_TO_PWM); | ||
1865 | int mask; | ||
1866 | |||
1867 | /* collapse the mapping into a mask of enable bits */ | ||
1868 | mapping = (mapping >> pwm) & 0x55; | ||
1869 | mask = mapping & 0x01; | ||
1870 | mask |= (mapping & 0x04) >> 1; | ||
1871 | mask |= (mapping & 0x10) >> 2; | ||
1872 | mask |= (mapping & 0x40) >> 3; | ||
1873 | |||
1874 | /* disable smart tach according to the mask */ | ||
1875 | data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); | ||
1876 | data->sfc2 &= ~mask; | ||
1877 | lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); | ||
1878 | } | ||
1879 | |||
1880 | static ssize_t store_pwm_freq(struct device *dev, | ||
1881 | struct device_attribute *attr, | ||
1882 | const char *buf, size_t count) | ||
1883 | { | ||
1884 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1885 | struct i2c_client *client = to_i2c_client(dev); | ||
1886 | struct lm93_data *data = i2c_get_clientdata(client); | ||
1887 | u32 val = simple_strtoul(buf, NULL, 10); | ||
1888 | u8 ctl4; | ||
1889 | |||
1890 | mutex_lock(&data->update_lock); | ||
1891 | ctl4 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4)); | ||
1892 | ctl4 = (ctl4 & 0xf8) | LM93_PWM_FREQ_TO_REG(val); | ||
1893 | data->block9[nr][LM93_PWM_CTL4] = ctl4; | ||
1894 | /* ctl4 == 0 -> 22.5KHz -> disable smart tach */ | ||
1895 | if (!ctl4) | ||
1896 | lm93_disable_fan_smart_tach(client, data, nr); | ||
1897 | lm93_write_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4), ctl4); | ||
1898 | mutex_unlock(&data->update_lock); | ||
1899 | return count; | ||
1900 | } | ||
1901 | |||
1902 | static SENSOR_DEVICE_ATTR(pwm1_freq, S_IWUSR | S_IRUGO, | ||
1903 | show_pwm_freq, store_pwm_freq, 0); | ||
1904 | static SENSOR_DEVICE_ATTR(pwm2_freq, S_IWUSR | S_IRUGO, | ||
1905 | show_pwm_freq, store_pwm_freq, 1); | ||
1906 | |||
1907 | static ssize_t show_pwm_auto_channels(struct device *dev, | ||
1908 | struct device_attribute *attr, char *buf) | ||
1909 | { | ||
1910 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1911 | struct lm93_data *data = lm93_update_device(dev); | ||
1912 | return sprintf(buf,"%d\n",data->block9[nr][LM93_PWM_CTL1]); | ||
1913 | } | ||
1914 | |||
1915 | static ssize_t store_pwm_auto_channels(struct device *dev, | ||
1916 | struct device_attribute *attr, | ||
1917 | const char *buf, size_t count) | ||
1918 | { | ||
1919 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1920 | struct i2c_client *client = to_i2c_client(dev); | ||
1921 | struct lm93_data *data = i2c_get_clientdata(client); | ||
1922 | u32 val = simple_strtoul(buf, NULL, 10); | ||
1923 | |||
1924 | mutex_lock(&data->update_lock); | ||
1925 | data->block9[nr][LM93_PWM_CTL1] = SENSORS_LIMIT(val, 0, 255); | ||
1926 | lm93_write_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL1), | ||
1927 | data->block9[nr][LM93_PWM_CTL1]); | ||
1928 | mutex_unlock(&data->update_lock); | ||
1929 | return count; | ||
1930 | } | ||
1931 | |||
1932 | static SENSOR_DEVICE_ATTR(pwm1_auto_channels, S_IWUSR | S_IRUGO, | ||
1933 | show_pwm_auto_channels, store_pwm_auto_channels, 0); | ||
1934 | static SENSOR_DEVICE_ATTR(pwm2_auto_channels, S_IWUSR | S_IRUGO, | ||
1935 | show_pwm_auto_channels, store_pwm_auto_channels, 1); | ||
1936 | |||
1937 | static ssize_t show_pwm_auto_spinup_min(struct device *dev, | ||
1938 | struct device_attribute *attr,char *buf) | ||
1939 | { | ||
1940 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1941 | struct lm93_data *data = lm93_update_device(dev); | ||
1942 | u8 ctl3, ctl4; | ||
1943 | |||
1944 | ctl3 = data->block9[nr][LM93_PWM_CTL3]; | ||
1945 | ctl4 = data->block9[nr][LM93_PWM_CTL4]; | ||
1946 | return sprintf(buf,"%d\n", | ||
1947 | LM93_PWM_FROM_REG(ctl3 & 0x0f, (ctl4 & 0x07) ? | ||
1948 | LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ)); | ||
1949 | } | ||
1950 | |||
1951 | static ssize_t store_pwm_auto_spinup_min(struct device *dev, | ||
1952 | struct device_attribute *attr, | ||
1953 | const char *buf, size_t count) | ||
1954 | { | ||
1955 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1956 | struct i2c_client *client = to_i2c_client(dev); | ||
1957 | struct lm93_data *data = i2c_get_clientdata(client); | ||
1958 | u32 val = simple_strtoul(buf, NULL, 10); | ||
1959 | u8 ctl3, ctl4; | ||
1960 | |||
1961 | mutex_lock(&data->update_lock); | ||
1962 | ctl3 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3)); | ||
1963 | ctl4 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL4)); | ||
1964 | ctl3 = (ctl3 & 0xf0) | LM93_PWM_TO_REG(val, (ctl4 & 0x07) ? | ||
1965 | LM93_PWM_MAP_LO_FREQ : | ||
1966 | LM93_PWM_MAP_HI_FREQ); | ||
1967 | data->block9[nr][LM93_PWM_CTL3] = ctl3; | ||
1968 | lm93_write_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3), ctl3); | ||
1969 | mutex_unlock(&data->update_lock); | ||
1970 | return count; | ||
1971 | } | ||
1972 | |||
1973 | static SENSOR_DEVICE_ATTR(pwm1_auto_spinup_min, S_IWUSR | S_IRUGO, | ||
1974 | show_pwm_auto_spinup_min, | ||
1975 | store_pwm_auto_spinup_min, 0); | ||
1976 | static SENSOR_DEVICE_ATTR(pwm2_auto_spinup_min, S_IWUSR | S_IRUGO, | ||
1977 | show_pwm_auto_spinup_min, | ||
1978 | store_pwm_auto_spinup_min, 1); | ||
1979 | |||
1980 | static ssize_t show_pwm_auto_spinup_time(struct device *dev, | ||
1981 | struct device_attribute *attr, char *buf) | ||
1982 | { | ||
1983 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1984 | struct lm93_data *data = lm93_update_device(dev); | ||
1985 | return sprintf(buf,"%d\n",LM93_SPINUP_TIME_FROM_REG( | ||
1986 | data->block9[nr][LM93_PWM_CTL3])); | ||
1987 | } | ||
1988 | |||
1989 | static ssize_t store_pwm_auto_spinup_time(struct device *dev, | ||
1990 | struct device_attribute *attr, | ||
1991 | const char *buf, size_t count) | ||
1992 | { | ||
1993 | int nr = (to_sensor_dev_attr(attr))->index; | ||
1994 | struct i2c_client *client = to_i2c_client(dev); | ||
1995 | struct lm93_data *data = i2c_get_clientdata(client); | ||
1996 | u32 val = simple_strtoul(buf, NULL, 10); | ||
1997 | u8 ctl3; | ||
1998 | |||
1999 | mutex_lock(&data->update_lock); | ||
2000 | ctl3 = lm93_read_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3)); | ||
2001 | ctl3 = (ctl3 & 0x1f) | (LM93_SPINUP_TIME_TO_REG(val) << 5 & 0xe0); | ||
2002 | data->block9[nr][LM93_PWM_CTL3] = ctl3; | ||
2003 | lm93_write_byte(client,LM93_REG_PWM_CTL(nr, LM93_PWM_CTL3), ctl3); | ||
2004 | mutex_unlock(&data->update_lock); | ||
2005 | return count; | ||
2006 | } | ||
2007 | |||
2008 | static SENSOR_DEVICE_ATTR(pwm1_auto_spinup_time, S_IWUSR | S_IRUGO, | ||
2009 | show_pwm_auto_spinup_time, | ||
2010 | store_pwm_auto_spinup_time, 0); | ||
2011 | static SENSOR_DEVICE_ATTR(pwm2_auto_spinup_time, S_IWUSR | S_IRUGO, | ||
2012 | show_pwm_auto_spinup_time, | ||
2013 | store_pwm_auto_spinup_time, 1); | ||
2014 | |||
2015 | static ssize_t show_pwm_auto_prochot_ramp(struct device *dev, | ||
2016 | struct device_attribute *attr, char *buf) | ||
2017 | { | ||
2018 | struct lm93_data *data = lm93_update_device(dev); | ||
2019 | return sprintf(buf,"%d\n", | ||
2020 | LM93_RAMP_FROM_REG(data->pwm_ramp_ctl >> 4 & 0x0f)); | ||
2021 | } | ||
2022 | |||
2023 | static ssize_t store_pwm_auto_prochot_ramp(struct device *dev, | ||
2024 | struct device_attribute *attr, | ||
2025 | const char *buf, size_t count) | ||
2026 | { | ||
2027 | struct i2c_client *client = to_i2c_client(dev); | ||
2028 | struct lm93_data *data = i2c_get_clientdata(client); | ||
2029 | u32 val = simple_strtoul(buf, NULL, 10); | ||
2030 | u8 ramp; | ||
2031 | |||
2032 | mutex_lock(&data->update_lock); | ||
2033 | ramp = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL); | ||
2034 | ramp = (ramp & 0x0f) | (LM93_RAMP_TO_REG(val) << 4 & 0xf0); | ||
2035 | lm93_write_byte(client, LM93_REG_PWM_RAMP_CTL, ramp); | ||
2036 | mutex_unlock(&data->update_lock); | ||
2037 | return count; | ||
2038 | } | ||
2039 | |||
2040 | static DEVICE_ATTR(pwm_auto_prochot_ramp, S_IRUGO | S_IWUSR, | ||
2041 | show_pwm_auto_prochot_ramp, | ||
2042 | store_pwm_auto_prochot_ramp); | ||
2043 | |||
2044 | static ssize_t show_pwm_auto_vrdhot_ramp(struct device *dev, | ||
2045 | struct device_attribute *attr, char *buf) | ||
2046 | { | ||
2047 | struct lm93_data *data = lm93_update_device(dev); | ||
2048 | return sprintf(buf,"%d\n", | ||
2049 | LM93_RAMP_FROM_REG(data->pwm_ramp_ctl & 0x0f)); | ||
2050 | } | ||
2051 | |||
2052 | static ssize_t store_pwm_auto_vrdhot_ramp(struct device *dev, | ||
2053 | struct device_attribute *attr, | ||
2054 | const char *buf, size_t count) | ||
2055 | { | ||
2056 | struct i2c_client *client = to_i2c_client(dev); | ||
2057 | struct lm93_data *data = i2c_get_clientdata(client); | ||
2058 | u32 val = simple_strtoul(buf, NULL, 10); | ||
2059 | u8 ramp; | ||
2060 | |||
2061 | mutex_lock(&data->update_lock); | ||
2062 | ramp = lm93_read_byte(client, LM93_REG_PWM_RAMP_CTL); | ||
2063 | ramp = (ramp & 0xf0) | (LM93_RAMP_TO_REG(val) & 0x0f); | ||
2064 | lm93_write_byte(client, LM93_REG_PWM_RAMP_CTL, ramp); | ||
2065 | mutex_unlock(&data->update_lock); | ||
2066 | return 0; | ||
2067 | } | ||
2068 | |||
2069 | static DEVICE_ATTR(pwm_auto_vrdhot_ramp, S_IRUGO | S_IWUSR, | ||
2070 | show_pwm_auto_vrdhot_ramp, | ||
2071 | store_pwm_auto_vrdhot_ramp); | ||
2072 | |||
2073 | static ssize_t show_vid(struct device *dev, struct device_attribute *attr, | ||
2074 | char *buf) | ||
2075 | { | ||
2076 | int nr = (to_sensor_dev_attr(attr))->index; | ||
2077 | struct lm93_data *data = lm93_update_device(dev); | ||
2078 | return sprintf(buf,"%d\n",LM93_VID_FROM_REG(data->vid[nr])); | ||
2079 | } | ||
2080 | |||
2081 | static SENSOR_DEVICE_ATTR(vid1, S_IRUGO, show_vid, NULL, 0); | ||
2082 | static SENSOR_DEVICE_ATTR(vid2, S_IRUGO, show_vid, NULL, 1); | ||
2083 | |||
2084 | static ssize_t show_prochot(struct device *dev, struct device_attribute *attr, | ||
2085 | char *buf) | ||
2086 | { | ||
2087 | int nr = (to_sensor_dev_attr(attr))->index; | ||
2088 | struct lm93_data *data = lm93_update_device(dev); | ||
2089 | return sprintf(buf,"%d\n",data->block4[nr].cur); | ||
2090 | } | ||
2091 | |||
2092 | static SENSOR_DEVICE_ATTR(prochot1, S_IRUGO, show_prochot, NULL, 0); | ||
2093 | static SENSOR_DEVICE_ATTR(prochot2, S_IRUGO, show_prochot, NULL, 1); | ||
2094 | |||
2095 | static ssize_t show_prochot_avg(struct device *dev, | ||
2096 | struct device_attribute *attr, char *buf) | ||
2097 | { | ||
2098 | int nr = (to_sensor_dev_attr(attr))->index; | ||
2099 | struct lm93_data *data = lm93_update_device(dev); | ||
2100 | return sprintf(buf,"%d\n",data->block4[nr].avg); | ||
2101 | } | ||
2102 | |||
2103 | static SENSOR_DEVICE_ATTR(prochot1_avg, S_IRUGO, show_prochot_avg, NULL, 0); | ||
2104 | static SENSOR_DEVICE_ATTR(prochot2_avg, S_IRUGO, show_prochot_avg, NULL, 1); | ||
2105 | |||
2106 | static ssize_t show_prochot_max(struct device *dev, | ||
2107 | struct device_attribute *attr, char *buf) | ||
2108 | { | ||
2109 | int nr = (to_sensor_dev_attr(attr))->index; | ||
2110 | struct lm93_data *data = lm93_update_device(dev); | ||
2111 | return sprintf(buf,"%d\n",data->prochot_max[nr]); | ||
2112 | } | ||
2113 | |||
2114 | static ssize_t store_prochot_max(struct device *dev, | ||
2115 | struct device_attribute *attr, | ||
2116 | const char *buf, size_t count) | ||
2117 | { | ||
2118 | int nr = (to_sensor_dev_attr(attr))->index; | ||
2119 | struct i2c_client *client = to_i2c_client(dev); | ||
2120 | struct lm93_data *data = i2c_get_clientdata(client); | ||
2121 | u32 val = simple_strtoul(buf, NULL, 10); | ||
2122 | |||
2123 | mutex_lock(&data->update_lock); | ||
2124 | data->prochot_max[nr] = LM93_PROCHOT_TO_REG(val); | ||
2125 | lm93_write_byte(client, LM93_REG_PROCHOT_MAX(nr), | ||
2126 | data->prochot_max[nr]); | ||
2127 | mutex_unlock(&data->update_lock); | ||
2128 | return count; | ||
2129 | } | ||
2130 | |||
2131 | static SENSOR_DEVICE_ATTR(prochot1_max, S_IWUSR | S_IRUGO, | ||
2132 | show_prochot_max, store_prochot_max, 0); | ||
2133 | static SENSOR_DEVICE_ATTR(prochot2_max, S_IWUSR | S_IRUGO, | ||
2134 | show_prochot_max, store_prochot_max, 1); | ||
2135 | |||
2136 | static const u8 prochot_override_mask[] = { 0x80, 0x40 }; | ||
2137 | |||
2138 | static ssize_t show_prochot_override(struct device *dev, | ||
2139 | struct device_attribute *attr, char *buf) | ||
2140 | { | ||
2141 | int nr = (to_sensor_dev_attr(attr))->index; | ||
2142 | struct lm93_data *data = lm93_update_device(dev); | ||
2143 | return sprintf(buf,"%d\n", | ||
2144 | (data->prochot_override & prochot_override_mask[nr]) ? 1 : 0); | ||
2145 | } | ||
2146 | |||
2147 | static ssize_t store_prochot_override(struct device *dev, | ||
2148 | struct device_attribute *attr, | ||
2149 | const char *buf, size_t count) | ||
2150 | { | ||
2151 | int nr = (to_sensor_dev_attr(attr))->index; | ||
2152 | struct i2c_client *client = to_i2c_client(dev); | ||
2153 | struct lm93_data *data = i2c_get_clientdata(client); | ||
2154 | u32 val = simple_strtoul(buf, NULL, 10); | ||
2155 | |||
2156 | mutex_lock(&data->update_lock); | ||
2157 | if (val) | ||
2158 | data->prochot_override |= prochot_override_mask[nr]; | ||
2159 | else | ||
2160 | data->prochot_override &= (~prochot_override_mask[nr]); | ||
2161 | lm93_write_byte(client, LM93_REG_PROCHOT_OVERRIDE, | ||
2162 | data->prochot_override); | ||
2163 | mutex_unlock(&data->update_lock); | ||
2164 | return count; | ||
2165 | } | ||
2166 | |||
2167 | static SENSOR_DEVICE_ATTR(prochot1_override, S_IWUSR | S_IRUGO, | ||
2168 | show_prochot_override, store_prochot_override, 0); | ||
2169 | static SENSOR_DEVICE_ATTR(prochot2_override, S_IWUSR | S_IRUGO, | ||
2170 | show_prochot_override, store_prochot_override, 1); | ||
2171 | |||
2172 | static ssize_t show_prochot_interval(struct device *dev, | ||
2173 | struct device_attribute *attr, char *buf) | ||
2174 | { | ||
2175 | int nr = (to_sensor_dev_attr(attr))->index; | ||
2176 | struct lm93_data *data = lm93_update_device(dev); | ||
2177 | u8 tmp; | ||
2178 | if (nr==1) | ||
2179 | tmp = (data->prochot_interval & 0xf0) >> 4; | ||
2180 | else | ||
2181 | tmp = data->prochot_interval & 0x0f; | ||
2182 | return sprintf(buf,"%d\n",LM93_INTERVAL_FROM_REG(tmp)); | ||
2183 | } | ||
2184 | |||
2185 | static ssize_t store_prochot_interval(struct device *dev, | ||
2186 | struct device_attribute *attr, | ||
2187 | const char *buf, size_t count) | ||
2188 | { | ||
2189 | int nr = (to_sensor_dev_attr(attr))->index; | ||
2190 | struct i2c_client *client = to_i2c_client(dev); | ||
2191 | struct lm93_data *data = i2c_get_clientdata(client); | ||
2192 | u32 val = simple_strtoul(buf, NULL, 10); | ||
2193 | u8 tmp; | ||
2194 | |||
2195 | mutex_lock(&data->update_lock); | ||
2196 | tmp = lm93_read_byte(client, LM93_REG_PROCHOT_INTERVAL); | ||
2197 | if (nr==1) | ||
2198 | tmp = (tmp & 0x0f) | (LM93_INTERVAL_TO_REG(val) << 4); | ||
2199 | else | ||
2200 | tmp = (tmp & 0xf0) | LM93_INTERVAL_TO_REG(val); | ||
2201 | data->prochot_interval = tmp; | ||
2202 | lm93_write_byte(client, LM93_REG_PROCHOT_INTERVAL, tmp); | ||
2203 | mutex_unlock(&data->update_lock); | ||
2204 | return count; | ||
2205 | } | ||
2206 | |||
2207 | static SENSOR_DEVICE_ATTR(prochot1_interval, S_IWUSR | S_IRUGO, | ||
2208 | show_prochot_interval, store_prochot_interval, 0); | ||
2209 | static SENSOR_DEVICE_ATTR(prochot2_interval, S_IWUSR | S_IRUGO, | ||
2210 | show_prochot_interval, store_prochot_interval, 1); | ||
2211 | |||
2212 | static ssize_t show_prochot_override_duty_cycle(struct device *dev, | ||
2213 | struct device_attribute *attr, | ||
2214 | char *buf) | ||
2215 | { | ||
2216 | struct lm93_data *data = lm93_update_device(dev); | ||
2217 | return sprintf(buf,"%d\n",data->prochot_override & 0x0f); | ||
2218 | } | ||
2219 | |||
2220 | static ssize_t store_prochot_override_duty_cycle(struct device *dev, | ||
2221 | struct device_attribute *attr, | ||
2222 | const char *buf, size_t count) | ||
2223 | { | ||
2224 | struct i2c_client *client = to_i2c_client(dev); | ||
2225 | struct lm93_data *data = i2c_get_clientdata(client); | ||
2226 | u32 val = simple_strtoul(buf, NULL, 10); | ||
2227 | |||
2228 | mutex_lock(&data->update_lock); | ||
2229 | data->prochot_override = (data->prochot_override & 0xf0) | | ||
2230 | SENSORS_LIMIT(val, 0, 15); | ||
2231 | lm93_write_byte(client, LM93_REG_PROCHOT_OVERRIDE, | ||
2232 | data->prochot_override); | ||
2233 | mutex_unlock(&data->update_lock); | ||
2234 | return count; | ||
2235 | } | ||
2236 | |||
2237 | static DEVICE_ATTR(prochot_override_duty_cycle, S_IRUGO | S_IWUSR, | ||
2238 | show_prochot_override_duty_cycle, | ||
2239 | store_prochot_override_duty_cycle); | ||
2240 | |||
2241 | static ssize_t show_prochot_short(struct device *dev, | ||
2242 | struct device_attribute *attr, char *buf) | ||
2243 | { | ||
2244 | struct lm93_data *data = lm93_update_device(dev); | ||
2245 | return sprintf(buf,"%d\n",(data->config & 0x10) ? 1 : 0); | ||
2246 | } | ||
2247 | |||
2248 | static ssize_t store_prochot_short(struct device *dev, | ||
2249 | struct device_attribute *attr, | ||
2250 | const char *buf, size_t count) | ||
2251 | { | ||
2252 | struct i2c_client *client = to_i2c_client(dev); | ||
2253 | struct lm93_data *data = i2c_get_clientdata(client); | ||
2254 | u32 val = simple_strtoul(buf, NULL, 10); | ||
2255 | |||
2256 | mutex_lock(&data->update_lock); | ||
2257 | if (val) | ||
2258 | data->config |= 0x10; | ||
2259 | else | ||
2260 | data->config &= ~0x10; | ||
2261 | lm93_write_byte(client, LM93_REG_CONFIG, data->config); | ||
2262 | mutex_unlock(&data->update_lock); | ||
2263 | return count; | ||
2264 | } | ||
2265 | |||
2266 | static DEVICE_ATTR(prochot_short, S_IRUGO | S_IWUSR, | ||
2267 | show_prochot_short, store_prochot_short); | ||
2268 | |||
2269 | static ssize_t show_vrdhot(struct device *dev, struct device_attribute *attr, | ||
2270 | char *buf) | ||
2271 | { | ||
2272 | int nr = (to_sensor_dev_attr(attr))->index; | ||
2273 | struct lm93_data *data = lm93_update_device(dev); | ||
2274 | return sprintf(buf,"%d\n", | ||
2275 | data->block1.host_status_1 & (1 << (nr+4)) ? 1 : 0); | ||
2276 | } | ||
2277 | |||
2278 | static SENSOR_DEVICE_ATTR(vrdhot1, S_IRUGO, show_vrdhot, NULL, 0); | ||
2279 | static SENSOR_DEVICE_ATTR(vrdhot2, S_IRUGO, show_vrdhot, NULL, 1); | ||
2280 | |||
2281 | static ssize_t show_gpio(struct device *dev, struct device_attribute *attr, | ||
2282 | char *buf) | ||
2283 | { | ||
2284 | struct lm93_data *data = lm93_update_device(dev); | ||
2285 | return sprintf(buf,"%d\n",LM93_GPI_FROM_REG(data->gpi)); | ||
2286 | } | ||
2287 | |||
2288 | static DEVICE_ATTR(gpio, S_IRUGO, show_gpio, NULL); | ||
2289 | |||
2290 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, | ||
2291 | char *buf) | ||
2292 | { | ||
2293 | struct lm93_data *data = lm93_update_device(dev); | ||
2294 | return sprintf(buf,"%d\n",LM93_ALARMS_FROM_REG(data->block1)); | ||
2295 | } | ||
2296 | |||
2297 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | ||
2298 | |||
2299 | static struct attribute *lm93_attrs[] = { | ||
2300 | &sensor_dev_attr_in1_input.dev_attr.attr, | ||
2301 | &sensor_dev_attr_in2_input.dev_attr.attr, | ||
2302 | &sensor_dev_attr_in3_input.dev_attr.attr, | ||
2303 | &sensor_dev_attr_in4_input.dev_attr.attr, | ||
2304 | &sensor_dev_attr_in5_input.dev_attr.attr, | ||
2305 | &sensor_dev_attr_in6_input.dev_attr.attr, | ||
2306 | &sensor_dev_attr_in7_input.dev_attr.attr, | ||
2307 | &sensor_dev_attr_in8_input.dev_attr.attr, | ||
2308 | &sensor_dev_attr_in9_input.dev_attr.attr, | ||
2309 | &sensor_dev_attr_in10_input.dev_attr.attr, | ||
2310 | &sensor_dev_attr_in11_input.dev_attr.attr, | ||
2311 | &sensor_dev_attr_in12_input.dev_attr.attr, | ||
2312 | &sensor_dev_attr_in13_input.dev_attr.attr, | ||
2313 | &sensor_dev_attr_in14_input.dev_attr.attr, | ||
2314 | &sensor_dev_attr_in15_input.dev_attr.attr, | ||
2315 | &sensor_dev_attr_in16_input.dev_attr.attr, | ||
2316 | &sensor_dev_attr_in1_min.dev_attr.attr, | ||
2317 | &sensor_dev_attr_in2_min.dev_attr.attr, | ||
2318 | &sensor_dev_attr_in3_min.dev_attr.attr, | ||
2319 | &sensor_dev_attr_in4_min.dev_attr.attr, | ||
2320 | &sensor_dev_attr_in5_min.dev_attr.attr, | ||
2321 | &sensor_dev_attr_in6_min.dev_attr.attr, | ||
2322 | &sensor_dev_attr_in7_min.dev_attr.attr, | ||
2323 | &sensor_dev_attr_in8_min.dev_attr.attr, | ||
2324 | &sensor_dev_attr_in9_min.dev_attr.attr, | ||
2325 | &sensor_dev_attr_in10_min.dev_attr.attr, | ||
2326 | &sensor_dev_attr_in11_min.dev_attr.attr, | ||
2327 | &sensor_dev_attr_in12_min.dev_attr.attr, | ||
2328 | &sensor_dev_attr_in13_min.dev_attr.attr, | ||
2329 | &sensor_dev_attr_in14_min.dev_attr.attr, | ||
2330 | &sensor_dev_attr_in15_min.dev_attr.attr, | ||
2331 | &sensor_dev_attr_in16_min.dev_attr.attr, | ||
2332 | &sensor_dev_attr_in1_max.dev_attr.attr, | ||
2333 | &sensor_dev_attr_in2_max.dev_attr.attr, | ||
2334 | &sensor_dev_attr_in3_max.dev_attr.attr, | ||
2335 | &sensor_dev_attr_in4_max.dev_attr.attr, | ||
2336 | &sensor_dev_attr_in5_max.dev_attr.attr, | ||
2337 | &sensor_dev_attr_in6_max.dev_attr.attr, | ||
2338 | &sensor_dev_attr_in7_max.dev_attr.attr, | ||
2339 | &sensor_dev_attr_in8_max.dev_attr.attr, | ||
2340 | &sensor_dev_attr_in9_max.dev_attr.attr, | ||
2341 | &sensor_dev_attr_in10_max.dev_attr.attr, | ||
2342 | &sensor_dev_attr_in11_max.dev_attr.attr, | ||
2343 | &sensor_dev_attr_in12_max.dev_attr.attr, | ||
2344 | &sensor_dev_attr_in13_max.dev_attr.attr, | ||
2345 | &sensor_dev_attr_in14_max.dev_attr.attr, | ||
2346 | &sensor_dev_attr_in15_max.dev_attr.attr, | ||
2347 | &sensor_dev_attr_in16_max.dev_attr.attr, | ||
2348 | &sensor_dev_attr_temp1_input.dev_attr.attr, | ||
2349 | &sensor_dev_attr_temp2_input.dev_attr.attr, | ||
2350 | &sensor_dev_attr_temp3_input.dev_attr.attr, | ||
2351 | &sensor_dev_attr_temp1_min.dev_attr.attr, | ||
2352 | &sensor_dev_attr_temp2_min.dev_attr.attr, | ||
2353 | &sensor_dev_attr_temp3_min.dev_attr.attr, | ||
2354 | &sensor_dev_attr_temp1_max.dev_attr.attr, | ||
2355 | &sensor_dev_attr_temp2_max.dev_attr.attr, | ||
2356 | &sensor_dev_attr_temp3_max.dev_attr.attr, | ||
2357 | &sensor_dev_attr_temp1_auto_base.dev_attr.attr, | ||
2358 | &sensor_dev_attr_temp2_auto_base.dev_attr.attr, | ||
2359 | &sensor_dev_attr_temp3_auto_base.dev_attr.attr, | ||
2360 | &sensor_dev_attr_temp1_auto_boost.dev_attr.attr, | ||
2361 | &sensor_dev_attr_temp2_auto_boost.dev_attr.attr, | ||
2362 | &sensor_dev_attr_temp3_auto_boost.dev_attr.attr, | ||
2363 | &sensor_dev_attr_temp1_auto_boost_hyst.dev_attr.attr, | ||
2364 | &sensor_dev_attr_temp2_auto_boost_hyst.dev_attr.attr, | ||
2365 | &sensor_dev_attr_temp3_auto_boost_hyst.dev_attr.attr, | ||
2366 | &sensor_dev_attr_temp1_auto_offset1.dev_attr.attr, | ||
2367 | &sensor_dev_attr_temp1_auto_offset2.dev_attr.attr, | ||
2368 | &sensor_dev_attr_temp1_auto_offset3.dev_attr.attr, | ||
2369 | &sensor_dev_attr_temp1_auto_offset4.dev_attr.attr, | ||
2370 | &sensor_dev_attr_temp1_auto_offset5.dev_attr.attr, | ||
2371 | &sensor_dev_attr_temp1_auto_offset6.dev_attr.attr, | ||
2372 | &sensor_dev_attr_temp1_auto_offset7.dev_attr.attr, | ||
2373 | &sensor_dev_attr_temp1_auto_offset8.dev_attr.attr, | ||
2374 | &sensor_dev_attr_temp1_auto_offset9.dev_attr.attr, | ||
2375 | &sensor_dev_attr_temp1_auto_offset10.dev_attr.attr, | ||
2376 | &sensor_dev_attr_temp1_auto_offset11.dev_attr.attr, | ||
2377 | &sensor_dev_attr_temp1_auto_offset12.dev_attr.attr, | ||
2378 | &sensor_dev_attr_temp2_auto_offset1.dev_attr.attr, | ||
2379 | &sensor_dev_attr_temp2_auto_offset2.dev_attr.attr, | ||
2380 | &sensor_dev_attr_temp2_auto_offset3.dev_attr.attr, | ||
2381 | &sensor_dev_attr_temp2_auto_offset4.dev_attr.attr, | ||
2382 | &sensor_dev_attr_temp2_auto_offset5.dev_attr.attr, | ||
2383 | &sensor_dev_attr_temp2_auto_offset6.dev_attr.attr, | ||
2384 | &sensor_dev_attr_temp2_auto_offset7.dev_attr.attr, | ||
2385 | &sensor_dev_attr_temp2_auto_offset8.dev_attr.attr, | ||
2386 | &sensor_dev_attr_temp2_auto_offset9.dev_attr.attr, | ||
2387 | &sensor_dev_attr_temp2_auto_offset10.dev_attr.attr, | ||
2388 | &sensor_dev_attr_temp2_auto_offset11.dev_attr.attr, | ||
2389 | &sensor_dev_attr_temp2_auto_offset12.dev_attr.attr, | ||
2390 | &sensor_dev_attr_temp3_auto_offset1.dev_attr.attr, | ||
2391 | &sensor_dev_attr_temp3_auto_offset2.dev_attr.attr, | ||
2392 | &sensor_dev_attr_temp3_auto_offset3.dev_attr.attr, | ||
2393 | &sensor_dev_attr_temp3_auto_offset4.dev_attr.attr, | ||
2394 | &sensor_dev_attr_temp3_auto_offset5.dev_attr.attr, | ||
2395 | &sensor_dev_attr_temp3_auto_offset6.dev_attr.attr, | ||
2396 | &sensor_dev_attr_temp3_auto_offset7.dev_attr.attr, | ||
2397 | &sensor_dev_attr_temp3_auto_offset8.dev_attr.attr, | ||
2398 | &sensor_dev_attr_temp3_auto_offset9.dev_attr.attr, | ||
2399 | &sensor_dev_attr_temp3_auto_offset10.dev_attr.attr, | ||
2400 | &sensor_dev_attr_temp3_auto_offset11.dev_attr.attr, | ||
2401 | &sensor_dev_attr_temp3_auto_offset12.dev_attr.attr, | ||
2402 | &sensor_dev_attr_temp1_auto_pwm_min.dev_attr.attr, | ||
2403 | &sensor_dev_attr_temp2_auto_pwm_min.dev_attr.attr, | ||
2404 | &sensor_dev_attr_temp3_auto_pwm_min.dev_attr.attr, | ||
2405 | &sensor_dev_attr_temp1_auto_offset_hyst.dev_attr.attr, | ||
2406 | &sensor_dev_attr_temp2_auto_offset_hyst.dev_attr.attr, | ||
2407 | &sensor_dev_attr_temp3_auto_offset_hyst.dev_attr.attr, | ||
2408 | &sensor_dev_attr_fan1_input.dev_attr.attr, | ||
2409 | &sensor_dev_attr_fan2_input.dev_attr.attr, | ||
2410 | &sensor_dev_attr_fan3_input.dev_attr.attr, | ||
2411 | &sensor_dev_attr_fan4_input.dev_attr.attr, | ||
2412 | &sensor_dev_attr_fan1_min.dev_attr.attr, | ||
2413 | &sensor_dev_attr_fan2_min.dev_attr.attr, | ||
2414 | &sensor_dev_attr_fan3_min.dev_attr.attr, | ||
2415 | &sensor_dev_attr_fan4_min.dev_attr.attr, | ||
2416 | &sensor_dev_attr_fan1_smart_tach.dev_attr.attr, | ||
2417 | &sensor_dev_attr_fan2_smart_tach.dev_attr.attr, | ||
2418 | &sensor_dev_attr_fan3_smart_tach.dev_attr.attr, | ||
2419 | &sensor_dev_attr_fan4_smart_tach.dev_attr.attr, | ||
2420 | &sensor_dev_attr_pwm1.dev_attr.attr, | ||
2421 | &sensor_dev_attr_pwm2.dev_attr.attr, | ||
2422 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, | ||
2423 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, | ||
2424 | &sensor_dev_attr_pwm1_freq.dev_attr.attr, | ||
2425 | &sensor_dev_attr_pwm2_freq.dev_attr.attr, | ||
2426 | &sensor_dev_attr_pwm1_auto_channels.dev_attr.attr, | ||
2427 | &sensor_dev_attr_pwm2_auto_channels.dev_attr.attr, | ||
2428 | &sensor_dev_attr_pwm1_auto_spinup_min.dev_attr.attr, | ||
2429 | &sensor_dev_attr_pwm2_auto_spinup_min.dev_attr.attr, | ||
2430 | &sensor_dev_attr_pwm1_auto_spinup_time.dev_attr.attr, | ||
2431 | &sensor_dev_attr_pwm2_auto_spinup_time.dev_attr.attr, | ||
2432 | &dev_attr_pwm_auto_prochot_ramp.attr, | ||
2433 | &dev_attr_pwm_auto_vrdhot_ramp.attr, | ||
2434 | &sensor_dev_attr_vid1.dev_attr.attr, | ||
2435 | &sensor_dev_attr_vid2.dev_attr.attr, | ||
2436 | &sensor_dev_attr_prochot1.dev_attr.attr, | ||
2437 | &sensor_dev_attr_prochot2.dev_attr.attr, | ||
2438 | &sensor_dev_attr_prochot1_avg.dev_attr.attr, | ||
2439 | &sensor_dev_attr_prochot2_avg.dev_attr.attr, | ||
2440 | &sensor_dev_attr_prochot1_max.dev_attr.attr, | ||
2441 | &sensor_dev_attr_prochot2_max.dev_attr.attr, | ||
2442 | &sensor_dev_attr_prochot1_override.dev_attr.attr, | ||
2443 | &sensor_dev_attr_prochot2_override.dev_attr.attr, | ||
2444 | &sensor_dev_attr_prochot1_interval.dev_attr.attr, | ||
2445 | &sensor_dev_attr_prochot2_interval.dev_attr.attr, | ||
2446 | &dev_attr_prochot_override_duty_cycle.attr, | ||
2447 | &dev_attr_prochot_short.attr, | ||
2448 | &sensor_dev_attr_vrdhot1.dev_attr.attr, | ||
2449 | &sensor_dev_attr_vrdhot2.dev_attr.attr, | ||
2450 | &dev_attr_gpio.attr, | ||
2451 | &dev_attr_alarms.attr, | ||
2452 | NULL | ||
2453 | }; | ||
2454 | |||
2455 | static struct attribute_group lm93_attr_grp = { | ||
2456 | .attrs = lm93_attrs, | ||
2457 | }; | ||
2458 | |||
2459 | static void lm93_init_client(struct i2c_client *client) | ||
2460 | { | ||
2461 | int i; | ||
2462 | u8 reg; | ||
2463 | |||
2464 | /* configure VID pin input thresholds */ | ||
2465 | reg = lm93_read_byte(client, LM93_REG_GPI_VID_CTL); | ||
2466 | lm93_write_byte(client, LM93_REG_GPI_VID_CTL, | ||
2467 | reg | (vid_agtl ? 0x03 : 0x00)); | ||
2468 | |||
2469 | if (init) { | ||
2470 | /* enable #ALERT pin */ | ||
2471 | reg = lm93_read_byte(client, LM93_REG_CONFIG); | ||
2472 | lm93_write_byte(client, LM93_REG_CONFIG, reg | 0x08); | ||
2473 | |||
2474 | /* enable ASF mode for BMC status registers */ | ||
2475 | reg = lm93_read_byte(client, LM93_REG_STATUS_CONTROL); | ||
2476 | lm93_write_byte(client, LM93_REG_STATUS_CONTROL, reg | 0x02); | ||
2477 | |||
2478 | /* set sleep state to S0 */ | ||
2479 | lm93_write_byte(client, LM93_REG_SLEEP_CONTROL, 0); | ||
2480 | |||
2481 | /* unmask #VRDHOT and dynamic VCCP (if nec) error events */ | ||
2482 | reg = lm93_read_byte(client, LM93_REG_MISC_ERR_MASK); | ||
2483 | reg &= ~0x03; | ||
2484 | reg &= ~(vccp_limit_type[0] ? 0x10 : 0); | ||
2485 | reg &= ~(vccp_limit_type[1] ? 0x20 : 0); | ||
2486 | lm93_write_byte(client, LM93_REG_MISC_ERR_MASK, reg); | ||
2487 | } | ||
2488 | |||
2489 | /* start monitoring */ | ||
2490 | reg = lm93_read_byte(client, LM93_REG_CONFIG); | ||
2491 | lm93_write_byte(client, LM93_REG_CONFIG, reg | 0x01); | ||
2492 | |||
2493 | /* spin until ready */ | ||
2494 | for (i=0; i<20; i++) { | ||
2495 | msleep(10); | ||
2496 | if ((lm93_read_byte(client, LM93_REG_CONFIG) & 0x80) == 0x80) | ||
2497 | return; | ||
2498 | } | ||
2499 | |||
2500 | dev_warn(&client->dev,"timed out waiting for sensor " | ||
2501 | "chip to signal ready!\n"); | ||
2502 | } | ||
2503 | |||
2504 | static int lm93_detect(struct i2c_adapter *adapter, int address, int kind) | ||
2505 | { | ||
2506 | struct lm93_data *data; | ||
2507 | struct i2c_client *client; | ||
2508 | |||
2509 | int err = -ENODEV, func; | ||
2510 | void (*update)(struct lm93_data *, struct i2c_client *); | ||
2511 | |||
2512 | /* choose update routine based on bus capabilities */ | ||
2513 | func = i2c_get_functionality(adapter); | ||
2514 | if ( ((LM93_SMBUS_FUNC_FULL & func) == LM93_SMBUS_FUNC_FULL) && | ||
2515 | (!disable_block) ) { | ||
2516 | dev_dbg(&adapter->dev,"using SMBus block data transactions\n"); | ||
2517 | update = lm93_update_client_full; | ||
2518 | } else if ((LM93_SMBUS_FUNC_MIN & func) == LM93_SMBUS_FUNC_MIN) { | ||
2519 | dev_dbg(&adapter->dev,"disabled SMBus block data " | ||
2520 | "transactions\n"); | ||
2521 | update = lm93_update_client_min; | ||
2522 | } else { | ||
2523 | dev_dbg(&adapter->dev,"detect failed, " | ||
2524 | "smbus byte and/or word data not supported!\n"); | ||
2525 | goto err_out; | ||
2526 | } | ||
2527 | |||
2528 | /* OK. For now, we presume we have a valid client. We now create the | ||
2529 | client structure, even though we cannot fill it completely yet. | ||
2530 | But it allows us to access lm78_{read,write}_value. */ | ||
2531 | |||
2532 | if ( !(data = kzalloc(sizeof(struct lm93_data), GFP_KERNEL))) { | ||
2533 | dev_dbg(&adapter->dev,"out of memory!\n"); | ||
2534 | err = -ENOMEM; | ||
2535 | goto err_out; | ||
2536 | } | ||
2537 | |||
2538 | client = &data->client; | ||
2539 | i2c_set_clientdata(client, data); | ||
2540 | client->addr = address; | ||
2541 | client->adapter = adapter; | ||
2542 | client->driver = &lm93_driver; | ||
2543 | |||
2544 | /* detection */ | ||
2545 | if (kind < 0) { | ||
2546 | int mfr = lm93_read_byte(client, LM93_REG_MFR_ID); | ||
2547 | |||
2548 | if (mfr != 0x01) { | ||
2549 | dev_dbg(&adapter->dev,"detect failed, " | ||
2550 | "bad manufacturer id 0x%02x!\n", mfr); | ||
2551 | goto err_free; | ||
2552 | } | ||
2553 | } | ||
2554 | |||
2555 | if (kind <= 0) { | ||
2556 | int ver = lm93_read_byte(client, LM93_REG_VER); | ||
2557 | |||
2558 | if ((ver == LM93_MFR_ID) || (ver == LM93_MFR_ID_PROTOTYPE)) { | ||
2559 | kind = lm93; | ||
2560 | } else { | ||
2561 | dev_dbg(&adapter->dev,"detect failed, " | ||
2562 | "bad version id 0x%02x!\n", ver); | ||
2563 | if (kind == 0) | ||
2564 | dev_dbg(&adapter->dev, | ||
2565 | "(ignored 'force' parameter)\n"); | ||
2566 | goto err_free; | ||
2567 | } | ||
2568 | } | ||
2569 | |||
2570 | /* fill in remaining client fields */ | ||
2571 | strlcpy(client->name, "lm93", I2C_NAME_SIZE); | ||
2572 | dev_dbg(&adapter->dev,"loading %s at %d,0x%02x\n", | ||
2573 | client->name, i2c_adapter_id(client->adapter), | ||
2574 | client->addr); | ||
2575 | |||
2576 | /* housekeeping */ | ||
2577 | data->valid = 0; | ||
2578 | data->update = update; | ||
2579 | mutex_init(&data->update_lock); | ||
2580 | |||
2581 | /* tell the I2C layer a new client has arrived */ | ||
2582 | if ((err = i2c_attach_client(client))) | ||
2583 | goto err_free; | ||
2584 | |||
2585 | /* initialize the chip */ | ||
2586 | lm93_init_client(client); | ||
2587 | |||
2588 | err = sysfs_create_group(&client->dev.kobj, &lm93_attr_grp); | ||
2589 | if (err) | ||
2590 | goto err_detach; | ||
2591 | |||
2592 | /* Register hwmon driver class */ | ||
2593 | data->class_dev = hwmon_device_register(&client->dev); | ||
2594 | if ( !IS_ERR(data->class_dev)) | ||
2595 | return 0; | ||
2596 | |||
2597 | err = PTR_ERR(data->class_dev); | ||
2598 | dev_err(&client->dev, "error registering hwmon device.\n"); | ||
2599 | sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp); | ||
2600 | err_detach: | ||
2601 | i2c_detach_client(client); | ||
2602 | err_free: | ||
2603 | kfree(data); | ||
2604 | err_out: | ||
2605 | return err; | ||
2606 | } | ||
2607 | |||
2608 | /* This function is called when: | ||
2609 | * lm93_driver is inserted (when this module is loaded), for each | ||
2610 | available adapter | ||
2611 | * when a new adapter is inserted (and lm93_driver is still present) */ | ||
2612 | static int lm93_attach_adapter(struct i2c_adapter *adapter) | ||
2613 | { | ||
2614 | return i2c_probe(adapter, &addr_data, lm93_detect); | ||
2615 | } | ||
2616 | |||
2617 | static int lm93_detach_client(struct i2c_client *client) | ||
2618 | { | ||
2619 | struct lm93_data *data = i2c_get_clientdata(client); | ||
2620 | int err = 0; | ||
2621 | |||
2622 | hwmon_device_unregister(data->class_dev); | ||
2623 | sysfs_remove_group(&client->dev.kobj, &lm93_attr_grp); | ||
2624 | |||
2625 | err = i2c_detach_client(client); | ||
2626 | if (!err) | ||
2627 | kfree(data); | ||
2628 | return err; | ||
2629 | } | ||
2630 | |||
2631 | static struct i2c_driver lm93_driver = { | ||
2632 | .driver = { | ||
2633 | .name = "lm93", | ||
2634 | }, | ||
2635 | .attach_adapter = lm93_attach_adapter, | ||
2636 | .detach_client = lm93_detach_client, | ||
2637 | }; | ||
2638 | |||
2639 | static int __init lm93_init(void) | ||
2640 | { | ||
2641 | return i2c_add_driver(&lm93_driver); | ||
2642 | } | ||
2643 | |||
2644 | static void __exit lm93_exit(void) | ||
2645 | { | ||
2646 | i2c_del_driver(&lm93_driver); | ||
2647 | } | ||
2648 | |||
2649 | MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>, " | ||
2650 | "Hans J. Koch <hjk@linutronix.de"); | ||
2651 | MODULE_DESCRIPTION("LM93 driver"); | ||
2652 | MODULE_LICENSE("GPL"); | ||
2653 | |||
2654 | module_init(lm93_init); | ||
2655 | module_exit(lm93_exit); | ||
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c index c8a21be09d87..cb72526c346a 100644 --- a/drivers/hwmon/pc87360.c +++ b/drivers/hwmon/pc87360.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * pc87360.c - Part of lm_sensors, Linux kernel modules | 2 | * pc87360.c - Part of lm_sensors, Linux kernel modules |
3 | * for hardware monitoring | 3 | * for hardware monitoring |
4 | * Copyright (C) 2004 Jean Delvare <khali@linux-fr.org> | 4 | * Copyright (C) 2004, 2007 Jean Delvare <khali@linux-fr.org> |
5 | * | 5 | * |
6 | * Copied from smsc47m1.c: | 6 | * Copied from smsc47m1.c: |
7 | * Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com> | 7 | * Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com> |
@@ -37,8 +37,7 @@ | |||
37 | #include <linux/init.h> | 37 | #include <linux/init.h> |
38 | #include <linux/slab.h> | 38 | #include <linux/slab.h> |
39 | #include <linux/jiffies.h> | 39 | #include <linux/jiffies.h> |
40 | #include <linux/i2c.h> | 40 | #include <linux/platform_device.h> |
41 | #include <linux/i2c-isa.h> | ||
42 | #include <linux/hwmon.h> | 41 | #include <linux/hwmon.h> |
43 | #include <linux/hwmon-sysfs.h> | 42 | #include <linux/hwmon-sysfs.h> |
44 | #include <linux/hwmon-vid.h> | 43 | #include <linux/hwmon-vid.h> |
@@ -47,12 +46,10 @@ | |||
47 | #include <asm/io.h> | 46 | #include <asm/io.h> |
48 | 47 | ||
49 | static u8 devid; | 48 | static u8 devid; |
50 | static unsigned short address; | 49 | static struct platform_device *pdev; |
51 | static unsigned short extra_isa[3]; | 50 | static unsigned short extra_isa[3]; |
52 | static u8 confreg[4]; | 51 | static u8 confreg[4]; |
53 | 52 | ||
54 | enum chips { any_chip, pc87360, pc87363, pc87364, pc87365, pc87366 }; | ||
55 | |||
56 | static int init = 1; | 53 | static int init = 1; |
57 | module_param(init, int, 0); | 54 | module_param(init, int, 0); |
58 | MODULE_PARM_DESC(init, | 55 | MODULE_PARM_DESC(init, |
@@ -178,11 +175,11 @@ static inline u8 PWM_TO_REG(int val, int inv) | |||
178 | ((val) + 500) / 1000) | 175 | ((val) + 500) / 1000) |
179 | 176 | ||
180 | /* | 177 | /* |
181 | * Client data (each client gets its own) | 178 | * Device data |
182 | */ | 179 | */ |
183 | 180 | ||
184 | struct pc87360_data { | 181 | struct pc87360_data { |
185 | struct i2c_client client; | 182 | const char *name; |
186 | struct class_device *class_dev; | 183 | struct class_device *class_dev; |
187 | struct mutex lock; | 184 | struct mutex lock; |
188 | struct mutex update_lock; | 185 | struct mutex update_lock; |
@@ -222,27 +219,28 @@ struct pc87360_data { | |||
222 | * Functions declaration | 219 | * Functions declaration |
223 | */ | 220 | */ |
224 | 221 | ||
225 | static int pc87360_detect(struct i2c_adapter *adapter); | 222 | static int pc87360_probe(struct platform_device *pdev); |
226 | static int pc87360_detach_client(struct i2c_client *client); | 223 | static int pc87360_remove(struct platform_device *pdev); |
227 | 224 | ||
228 | static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank, | 225 | static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank, |
229 | u8 reg); | 226 | u8 reg); |
230 | static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank, | 227 | static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank, |
231 | u8 reg, u8 value); | 228 | u8 reg, u8 value); |
232 | static void pc87360_init_client(struct i2c_client *client, int use_thermistors); | 229 | static void pc87360_init_device(struct platform_device *pdev, |
230 | int use_thermistors); | ||
233 | static struct pc87360_data *pc87360_update_device(struct device *dev); | 231 | static struct pc87360_data *pc87360_update_device(struct device *dev); |
234 | 232 | ||
235 | /* | 233 | /* |
236 | * Driver data (common to all clients) | 234 | * Driver data |
237 | */ | 235 | */ |
238 | 236 | ||
239 | static struct i2c_driver pc87360_driver = { | 237 | static struct platform_driver pc87360_driver = { |
240 | .driver = { | 238 | .driver = { |
241 | .owner = THIS_MODULE, | 239 | .owner = THIS_MODULE, |
242 | .name = "pc87360", | 240 | .name = "pc87360", |
243 | }, | 241 | }, |
244 | .attach_adapter = pc87360_detect, | 242 | .probe = pc87360_probe, |
245 | .detach_client = pc87360_detach_client, | 243 | .remove = __devexit_p(pc87360_remove), |
246 | }; | 244 | }; |
247 | 245 | ||
248 | /* | 246 | /* |
@@ -281,8 +279,7 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr, | |||
281 | size_t count) | 279 | size_t count) |
282 | { | 280 | { |
283 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 281 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
284 | struct i2c_client *client = to_i2c_client(dev); | 282 | struct pc87360_data *data = dev_get_drvdata(dev); |
285 | struct pc87360_data *data = i2c_get_clientdata(client); | ||
286 | long fan_min = simple_strtol(buf, NULL, 10); | 283 | long fan_min = simple_strtol(buf, NULL, 10); |
287 | 284 | ||
288 | mutex_lock(&data->update_lock); | 285 | mutex_lock(&data->update_lock); |
@@ -347,8 +344,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, con | |||
347 | size_t count) | 344 | size_t count) |
348 | { | 345 | { |
349 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 346 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
350 | struct i2c_client *client = to_i2c_client(dev); | 347 | struct pc87360_data *data = dev_get_drvdata(dev); |
351 | struct pc87360_data *data = i2c_get_clientdata(client); | ||
352 | long val = simple_strtol(buf, NULL, 10); | 348 | long val = simple_strtol(buf, NULL, 10); |
353 | 349 | ||
354 | mutex_lock(&data->update_lock); | 350 | mutex_lock(&data->update_lock); |
@@ -410,8 +406,7 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr, | |||
410 | size_t count) | 406 | size_t count) |
411 | { | 407 | { |
412 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 408 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
413 | struct i2c_client *client = to_i2c_client(dev); | 409 | struct pc87360_data *data = dev_get_drvdata(dev); |
414 | struct pc87360_data *data = i2c_get_clientdata(client); | ||
415 | long val = simple_strtol(buf, NULL, 10); | 410 | long val = simple_strtol(buf, NULL, 10); |
416 | 411 | ||
417 | mutex_lock(&data->update_lock); | 412 | mutex_lock(&data->update_lock); |
@@ -425,8 +420,7 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr, | |||
425 | size_t count) | 420 | size_t count) |
426 | { | 421 | { |
427 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 422 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
428 | struct i2c_client *client = to_i2c_client(dev); | 423 | struct pc87360_data *data = dev_get_drvdata(dev); |
429 | struct pc87360_data *data = i2c_get_clientdata(client); | ||
430 | long val = simple_strtol(buf, NULL, 10); | 424 | long val = simple_strtol(buf, NULL, 10); |
431 | 425 | ||
432 | mutex_lock(&data->update_lock); | 426 | mutex_lock(&data->update_lock); |
@@ -511,8 +505,7 @@ static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char | |||
511 | } | 505 | } |
512 | static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 506 | static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
513 | { | 507 | { |
514 | struct i2c_client *client = to_i2c_client(dev); | 508 | struct pc87360_data *data = dev_get_drvdata(dev); |
515 | struct pc87360_data *data = i2c_get_clientdata(client); | ||
516 | data->vrm = simple_strtoul(buf, NULL, 10); | 509 | data->vrm = simple_strtoul(buf, NULL, 10); |
517 | return count; | 510 | return count; |
518 | } | 511 | } |
@@ -584,8 +577,7 @@ static ssize_t set_therm_min(struct device *dev, struct device_attribute *devatt | |||
584 | size_t count) | 577 | size_t count) |
585 | { | 578 | { |
586 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 579 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
587 | struct i2c_client *client = to_i2c_client(dev); | 580 | struct pc87360_data *data = dev_get_drvdata(dev); |
588 | struct pc87360_data *data = i2c_get_clientdata(client); | ||
589 | long val = simple_strtol(buf, NULL, 10); | 581 | long val = simple_strtol(buf, NULL, 10); |
590 | 582 | ||
591 | mutex_lock(&data->update_lock); | 583 | mutex_lock(&data->update_lock); |
@@ -599,8 +591,7 @@ static ssize_t set_therm_max(struct device *dev, struct device_attribute *devatt | |||
599 | size_t count) | 591 | size_t count) |
600 | { | 592 | { |
601 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 593 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
602 | struct i2c_client *client = to_i2c_client(dev); | 594 | struct pc87360_data *data = dev_get_drvdata(dev); |
603 | struct pc87360_data *data = i2c_get_clientdata(client); | ||
604 | long val = simple_strtol(buf, NULL, 10); | 595 | long val = simple_strtol(buf, NULL, 10); |
605 | 596 | ||
606 | mutex_lock(&data->update_lock); | 597 | mutex_lock(&data->update_lock); |
@@ -614,8 +605,7 @@ static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devat | |||
614 | size_t count) | 605 | size_t count) |
615 | { | 606 | { |
616 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 607 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
617 | struct i2c_client *client = to_i2c_client(dev); | 608 | struct pc87360_data *data = dev_get_drvdata(dev); |
618 | struct pc87360_data *data = i2c_get_clientdata(client); | ||
619 | long val = simple_strtol(buf, NULL, 10); | 609 | long val = simple_strtol(buf, NULL, 10); |
620 | 610 | ||
621 | mutex_lock(&data->update_lock); | 611 | mutex_lock(&data->update_lock); |
@@ -715,8 +705,7 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *devattr | |||
715 | size_t count) | 705 | size_t count) |
716 | { | 706 | { |
717 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 707 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
718 | struct i2c_client *client = to_i2c_client(dev); | 708 | struct pc87360_data *data = dev_get_drvdata(dev); |
719 | struct pc87360_data *data = i2c_get_clientdata(client); | ||
720 | long val = simple_strtol(buf, NULL, 10); | 709 | long val = simple_strtol(buf, NULL, 10); |
721 | 710 | ||
722 | mutex_lock(&data->update_lock); | 711 | mutex_lock(&data->update_lock); |
@@ -730,8 +719,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr | |||
730 | size_t count) | 719 | size_t count) |
731 | { | 720 | { |
732 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 721 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
733 | struct i2c_client *client = to_i2c_client(dev); | 722 | struct pc87360_data *data = dev_get_drvdata(dev); |
734 | struct pc87360_data *data = i2c_get_clientdata(client); | ||
735 | long val = simple_strtol(buf, NULL, 10); | 723 | long val = simple_strtol(buf, NULL, 10); |
736 | 724 | ||
737 | mutex_lock(&data->update_lock); | 725 | mutex_lock(&data->update_lock); |
@@ -745,8 +733,7 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *devatt | |||
745 | size_t count) | 733 | size_t count) |
746 | { | 734 | { |
747 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 735 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
748 | struct i2c_client *client = to_i2c_client(dev); | 736 | struct pc87360_data *data = dev_get_drvdata(dev); |
749 | struct pc87360_data *data = i2c_get_clientdata(client); | ||
750 | long val = simple_strtol(buf, NULL, 10); | 737 | long val = simple_strtol(buf, NULL, 10); |
751 | 738 | ||
752 | mutex_lock(&data->update_lock); | 739 | mutex_lock(&data->update_lock); |
@@ -818,6 +805,14 @@ static const struct attribute_group pc8736x_temp_group = { | |||
818 | .attrs = pc8736x_temp_attr_array, | 805 | .attrs = pc8736x_temp_attr_array, |
819 | }; | 806 | }; |
820 | 807 | ||
808 | static ssize_t show_name(struct device *dev, struct device_attribute | ||
809 | *devattr, char *buf) | ||
810 | { | ||
811 | struct pc87360_data *data = dev_get_drvdata(dev); | ||
812 | return sprintf(buf, "%s\n", data->name); | ||
813 | } | ||
814 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
815 | |||
821 | /* | 816 | /* |
822 | * Device detection, registration and update | 817 | * Device detection, registration and update |
823 | */ | 818 | */ |
@@ -912,28 +907,18 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses | |||
912 | return 0; | 907 | return 0; |
913 | } | 908 | } |
914 | 909 | ||
915 | static int pc87360_detect(struct i2c_adapter *adapter) | 910 | static int __devinit pc87360_probe(struct platform_device *pdev) |
916 | { | 911 | { |
917 | int i; | 912 | int i; |
918 | struct i2c_client *client; | ||
919 | struct pc87360_data *data; | 913 | struct pc87360_data *data; |
920 | int err = 0; | 914 | int err = 0; |
921 | const char *name = "pc87360"; | 915 | const char *name = "pc87360"; |
922 | int use_thermistors = 0; | 916 | int use_thermistors = 0; |
923 | struct device *dev; | 917 | struct device *dev = &pdev->dev; |
924 | 918 | ||
925 | if (!(data = kzalloc(sizeof(struct pc87360_data), GFP_KERNEL))) | 919 | if (!(data = kzalloc(sizeof(struct pc87360_data), GFP_KERNEL))) |
926 | return -ENOMEM; | 920 | return -ENOMEM; |
927 | 921 | ||
928 | client = &data->client; | ||
929 | dev = &client->dev; | ||
930 | i2c_set_clientdata(client, data); | ||
931 | client->addr = address; | ||
932 | mutex_init(&data->lock); | ||
933 | client->adapter = adapter; | ||
934 | client->driver = &pc87360_driver; | ||
935 | client->flags = 0; | ||
936 | |||
937 | data->fannr = 2; | 922 | data->fannr = 2; |
938 | data->innr = 0; | 923 | data->innr = 0; |
939 | data->tempnr = 0; | 924 | data->tempnr = 0; |
@@ -960,15 +945,17 @@ static int pc87360_detect(struct i2c_adapter *adapter) | |||
960 | break; | 945 | break; |
961 | } | 946 | } |
962 | 947 | ||
963 | strlcpy(client->name, name, sizeof(client->name)); | 948 | data->name = name; |
964 | data->valid = 0; | 949 | data->valid = 0; |
950 | mutex_init(&data->lock); | ||
965 | mutex_init(&data->update_lock); | 951 | mutex_init(&data->update_lock); |
952 | platform_set_drvdata(pdev, data); | ||
966 | 953 | ||
967 | for (i = 0; i < 3; i++) { | 954 | for (i = 0; i < 3; i++) { |
968 | if (((data->address[i] = extra_isa[i])) | 955 | if (((data->address[i] = extra_isa[i])) |
969 | && !request_region(extra_isa[i], PC87360_EXTENT, | 956 | && !request_region(extra_isa[i], PC87360_EXTENT, |
970 | pc87360_driver.driver.name)) { | 957 | pc87360_driver.driver.name)) { |
971 | dev_err(&client->dev, "Region 0x%x-0x%x already " | 958 | dev_err(dev, "Region 0x%x-0x%x already " |
972 | "in use!\n", extra_isa[i], | 959 | "in use!\n", extra_isa[i], |
973 | extra_isa[i]+PC87360_EXTENT-1); | 960 | extra_isa[i]+PC87360_EXTENT-1); |
974 | for (i--; i >= 0; i--) | 961 | for (i--; i >= 0; i--) |
@@ -982,9 +969,6 @@ static int pc87360_detect(struct i2c_adapter *adapter) | |||
982 | if (data->fannr) | 969 | if (data->fannr) |
983 | data->fan_conf = confreg[0] | (confreg[1] << 8); | 970 | data->fan_conf = confreg[0] | (confreg[1] << 8); |
984 | 971 | ||
985 | if ((err = i2c_attach_client(client))) | ||
986 | goto ERROR2; | ||
987 | |||
988 | /* Use the correct reference voltage | 972 | /* Use the correct reference voltage |
989 | Unless both the VLM and the TMS logical devices agree to | 973 | Unless both the VLM and the TMS logical devices agree to |
990 | use an external Vref, the internal one is used. */ | 974 | use an external Vref, the internal one is used. */ |
@@ -996,7 +980,7 @@ static int pc87360_detect(struct i2c_adapter *adapter) | |||
996 | PC87365_REG_TEMP_CONFIG); | 980 | PC87365_REG_TEMP_CONFIG); |
997 | } | 981 | } |
998 | data->in_vref = (i&0x02) ? 3025 : 2966; | 982 | data->in_vref = (i&0x02) ? 3025 : 2966; |
999 | dev_dbg(&client->dev, "Using %s reference voltage\n", | 983 | dev_dbg(dev, "Using %s reference voltage\n", |
1000 | (i&0x02) ? "external" : "internal"); | 984 | (i&0x02) ? "external" : "internal"); |
1001 | 985 | ||
1002 | data->vid_conf = confreg[3]; | 986 | data->vid_conf = confreg[3]; |
@@ -1015,18 +999,18 @@ static int pc87360_detect(struct i2c_adapter *adapter) | |||
1015 | if (devid == 0xe9 && data->address[1]) /* PC87366 */ | 999 | if (devid == 0xe9 && data->address[1]) /* PC87366 */ |
1016 | use_thermistors = confreg[2] & 0x40; | 1000 | use_thermistors = confreg[2] & 0x40; |
1017 | 1001 | ||
1018 | pc87360_init_client(client, use_thermistors); | 1002 | pc87360_init_device(pdev, use_thermistors); |
1019 | } | 1003 | } |
1020 | 1004 | ||
1021 | /* Register all-or-nothing sysfs groups */ | 1005 | /* Register all-or-nothing sysfs groups */ |
1022 | 1006 | ||
1023 | if (data->innr && | 1007 | if (data->innr && |
1024 | (err = sysfs_create_group(&client->dev.kobj, | 1008 | (err = sysfs_create_group(&dev->kobj, |
1025 | &pc8736x_vin_group))) | 1009 | &pc8736x_vin_group))) |
1026 | goto ERROR3; | 1010 | goto ERROR3; |
1027 | 1011 | ||
1028 | if (data->innr == 14 && | 1012 | if (data->innr == 14 && |
1029 | (err = sysfs_create_group(&client->dev.kobj, | 1013 | (err = sysfs_create_group(&dev->kobj, |
1030 | &pc8736x_therm_group))) | 1014 | &pc8736x_therm_group))) |
1031 | goto ERROR3; | 1015 | goto ERROR3; |
1032 | 1016 | ||
@@ -1067,7 +1051,10 @@ static int pc87360_detect(struct i2c_adapter *adapter) | |||
1067 | goto ERROR3; | 1051 | goto ERROR3; |
1068 | } | 1052 | } |
1069 | 1053 | ||
1070 | data->class_dev = hwmon_device_register(&client->dev); | 1054 | if ((err = device_create_file(dev, &dev_attr_name))) |
1055 | goto ERROR3; | ||
1056 | |||
1057 | data->class_dev = hwmon_device_register(dev); | ||
1071 | if (IS_ERR(data->class_dev)) { | 1058 | if (IS_ERR(data->class_dev)) { |
1072 | err = PTR_ERR(data->class_dev); | 1059 | err = PTR_ERR(data->class_dev); |
1073 | goto ERROR3; | 1060 | goto ERROR3; |
@@ -1075,14 +1062,12 @@ static int pc87360_detect(struct i2c_adapter *adapter) | |||
1075 | return 0; | 1062 | return 0; |
1076 | 1063 | ||
1077 | ERROR3: | 1064 | ERROR3: |
1065 | device_remove_file(dev, &dev_attr_name); | ||
1078 | /* can still remove groups whose members were added individually */ | 1066 | /* can still remove groups whose members were added individually */ |
1079 | sysfs_remove_group(&client->dev.kobj, &pc8736x_temp_group); | 1067 | sysfs_remove_group(&dev->kobj, &pc8736x_temp_group); |
1080 | sysfs_remove_group(&client->dev.kobj, &pc8736x_fan_group); | 1068 | sysfs_remove_group(&dev->kobj, &pc8736x_fan_group); |
1081 | sysfs_remove_group(&client->dev.kobj, &pc8736x_therm_group); | 1069 | sysfs_remove_group(&dev->kobj, &pc8736x_therm_group); |
1082 | sysfs_remove_group(&client->dev.kobj, &pc8736x_vin_group); | 1070 | sysfs_remove_group(&dev->kobj, &pc8736x_vin_group); |
1083 | |||
1084 | i2c_detach_client(client); | ||
1085 | ERROR2: | ||
1086 | for (i = 0; i < 3; i++) { | 1071 | for (i = 0; i < 3; i++) { |
1087 | if (data->address[i]) { | 1072 | if (data->address[i]) { |
1088 | release_region(data->address[i], PC87360_EXTENT); | 1073 | release_region(data->address[i], PC87360_EXTENT); |
@@ -1093,20 +1078,18 @@ ERROR1: | |||
1093 | return err; | 1078 | return err; |
1094 | } | 1079 | } |
1095 | 1080 | ||
1096 | static int pc87360_detach_client(struct i2c_client *client) | 1081 | static int __devexit pc87360_remove(struct platform_device *pdev) |
1097 | { | 1082 | { |
1098 | struct pc87360_data *data = i2c_get_clientdata(client); | 1083 | struct pc87360_data *data = platform_get_drvdata(pdev); |
1099 | int i; | 1084 | int i; |
1100 | 1085 | ||
1101 | hwmon_device_unregister(data->class_dev); | 1086 | hwmon_device_unregister(data->class_dev); |
1102 | 1087 | ||
1103 | sysfs_remove_group(&client->dev.kobj, &pc8736x_temp_group); | 1088 | device_remove_file(&pdev->dev, &dev_attr_name); |
1104 | sysfs_remove_group(&client->dev.kobj, &pc8736x_fan_group); | 1089 | sysfs_remove_group(&pdev->dev.kobj, &pc8736x_temp_group); |
1105 | sysfs_remove_group(&client->dev.kobj, &pc8736x_therm_group); | 1090 | sysfs_remove_group(&pdev->dev.kobj, &pc8736x_fan_group); |
1106 | sysfs_remove_group(&client->dev.kobj, &pc8736x_vin_group); | 1091 | sysfs_remove_group(&pdev->dev.kobj, &pc8736x_therm_group); |
1107 | 1092 | sysfs_remove_group(&pdev->dev.kobj, &pc8736x_vin_group); | |
1108 | if ((i = i2c_detach_client(client))) | ||
1109 | return i; | ||
1110 | 1093 | ||
1111 | for (i = 0; i < 3; i++) { | 1094 | for (i = 0; i < 3; i++) { |
1112 | if (data->address[i]) { | 1095 | if (data->address[i]) { |
@@ -1144,9 +1127,10 @@ static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank, | |||
1144 | mutex_unlock(&(data->lock)); | 1127 | mutex_unlock(&(data->lock)); |
1145 | } | 1128 | } |
1146 | 1129 | ||
1147 | static void pc87360_init_client(struct i2c_client *client, int use_thermistors) | 1130 | static void pc87360_init_device(struct platform_device *pdev, |
1131 | int use_thermistors) | ||
1148 | { | 1132 | { |
1149 | struct pc87360_data *data = i2c_get_clientdata(client); | 1133 | struct pc87360_data *data = platform_get_drvdata(pdev); |
1150 | int i, nr; | 1134 | int i, nr; |
1151 | const u8 init_in[14] = { 2, 2, 2, 2, 2, 2, 2, 1, 1, 3, 1, 2, 2, 2 }; | 1135 | const u8 init_in[14] = { 2, 2, 2, 2, 2, 2, 2, 1, 1, 3, 1, 2, 2, 2 }; |
1152 | const u8 init_temp[3] = { 2, 2, 1 }; | 1136 | const u8 init_temp[3] = { 2, 2, 1 }; |
@@ -1155,7 +1139,7 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors) | |||
1155 | if (init >= 2 && data->innr) { | 1139 | if (init >= 2 && data->innr) { |
1156 | reg = pc87360_read_value(data, LD_IN, NO_BANK, | 1140 | reg = pc87360_read_value(data, LD_IN, NO_BANK, |
1157 | PC87365_REG_IN_CONVRATE); | 1141 | PC87365_REG_IN_CONVRATE); |
1158 | dev_info(&client->dev, "VLM conversion set to " | 1142 | dev_info(&pdev->dev, "VLM conversion set to " |
1159 | "1s period, 160us delay\n"); | 1143 | "1s period, 160us delay\n"); |
1160 | pc87360_write_value(data, LD_IN, NO_BANK, | 1144 | pc87360_write_value(data, LD_IN, NO_BANK, |
1161 | PC87365_REG_IN_CONVRATE, | 1145 | PC87365_REG_IN_CONVRATE, |
@@ -1169,7 +1153,7 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors) | |||
1169 | reg = pc87360_read_value(data, LD_IN, i, | 1153 | reg = pc87360_read_value(data, LD_IN, i, |
1170 | PC87365_REG_IN_STATUS); | 1154 | PC87365_REG_IN_STATUS); |
1171 | if (!(reg & 0x01)) { | 1155 | if (!(reg & 0x01)) { |
1172 | dev_dbg(&client->dev, "Forcibly " | 1156 | dev_dbg(&pdev->dev, "Forcibly " |
1173 | "enabling in%d\n", i); | 1157 | "enabling in%d\n", i); |
1174 | pc87360_write_value(data, LD_IN, i, | 1158 | pc87360_write_value(data, LD_IN, i, |
1175 | PC87365_REG_IN_STATUS, | 1159 | PC87365_REG_IN_STATUS, |
@@ -1193,7 +1177,7 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors) | |||
1193 | reg = pc87360_read_value(data, LD_TEMP, i, | 1177 | reg = pc87360_read_value(data, LD_TEMP, i, |
1194 | PC87365_REG_TEMP_STATUS); | 1178 | PC87365_REG_TEMP_STATUS); |
1195 | if (!(reg & 0x01)) { | 1179 | if (!(reg & 0x01)) { |
1196 | dev_dbg(&client->dev, "Forcibly " | 1180 | dev_dbg(&pdev->dev, "Forcibly " |
1197 | "enabling temp%d\n", i+1); | 1181 | "enabling temp%d\n", i+1); |
1198 | pc87360_write_value(data, LD_TEMP, i, | 1182 | pc87360_write_value(data, LD_TEMP, i, |
1199 | PC87365_REG_TEMP_STATUS, | 1183 | PC87365_REG_TEMP_STATUS, |
@@ -1210,7 +1194,7 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors) | |||
1210 | reg = pc87360_read_value(data, LD_TEMP, | 1194 | reg = pc87360_read_value(data, LD_TEMP, |
1211 | (i-11)/2, PC87365_REG_TEMP_STATUS); | 1195 | (i-11)/2, PC87365_REG_TEMP_STATUS); |
1212 | if (reg & 0x01) { | 1196 | if (reg & 0x01) { |
1213 | dev_dbg(&client->dev, "Skipping " | 1197 | dev_dbg(&pdev->dev, "Skipping " |
1214 | "temp%d, pin already in use " | 1198 | "temp%d, pin already in use " |
1215 | "by temp%d\n", i-7, (i-11)/2); | 1199 | "by temp%d\n", i-7, (i-11)/2); |
1216 | continue; | 1200 | continue; |
@@ -1220,7 +1204,7 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors) | |||
1220 | reg = pc87360_read_value(data, LD_IN, i, | 1204 | reg = pc87360_read_value(data, LD_IN, i, |
1221 | PC87365_REG_IN_STATUS); | 1205 | PC87365_REG_IN_STATUS); |
1222 | if (!(reg & 0x01)) { | 1206 | if (!(reg & 0x01)) { |
1223 | dev_dbg(&client->dev, "Forcibly " | 1207 | dev_dbg(&pdev->dev, "Forcibly " |
1224 | "enabling temp%d\n", i-7); | 1208 | "enabling temp%d\n", i-7); |
1225 | pc87360_write_value(data, LD_IN, i, | 1209 | pc87360_write_value(data, LD_IN, i, |
1226 | PC87365_REG_TEMP_STATUS, | 1210 | PC87365_REG_TEMP_STATUS, |
@@ -1234,7 +1218,7 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors) | |||
1234 | reg = pc87360_read_value(data, LD_IN, NO_BANK, | 1218 | reg = pc87360_read_value(data, LD_IN, NO_BANK, |
1235 | PC87365_REG_IN_CONFIG); | 1219 | PC87365_REG_IN_CONFIG); |
1236 | if (reg & 0x01) { | 1220 | if (reg & 0x01) { |
1237 | dev_dbg(&client->dev, "Forcibly " | 1221 | dev_dbg(&pdev->dev, "Forcibly " |
1238 | "enabling monitoring (VLM)\n"); | 1222 | "enabling monitoring (VLM)\n"); |
1239 | pc87360_write_value(data, LD_IN, NO_BANK, | 1223 | pc87360_write_value(data, LD_IN, NO_BANK, |
1240 | PC87365_REG_IN_CONFIG, | 1224 | PC87365_REG_IN_CONFIG, |
@@ -1246,7 +1230,7 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors) | |||
1246 | reg = pc87360_read_value(data, LD_TEMP, NO_BANK, | 1230 | reg = pc87360_read_value(data, LD_TEMP, NO_BANK, |
1247 | PC87365_REG_TEMP_CONFIG); | 1231 | PC87365_REG_TEMP_CONFIG); |
1248 | if (reg & 0x01) { | 1232 | if (reg & 0x01) { |
1249 | dev_dbg(&client->dev, "Forcibly enabling " | 1233 | dev_dbg(&pdev->dev, "Forcibly enabling " |
1250 | "monitoring (TMS)\n"); | 1234 | "monitoring (TMS)\n"); |
1251 | pc87360_write_value(data, LD_TEMP, NO_BANK, | 1235 | pc87360_write_value(data, LD_TEMP, NO_BANK, |
1252 | PC87365_REG_TEMP_CONFIG, | 1236 | PC87365_REG_TEMP_CONFIG, |
@@ -1268,9 +1252,9 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors) | |||
1268 | } | 1252 | } |
1269 | } | 1253 | } |
1270 | 1254 | ||
1271 | static void pc87360_autodiv(struct i2c_client *client, int nr) | 1255 | static void pc87360_autodiv(struct device *dev, int nr) |
1272 | { | 1256 | { |
1273 | struct pc87360_data *data = i2c_get_clientdata(client); | 1257 | struct pc87360_data *data = dev_get_drvdata(dev); |
1274 | u8 old_min = data->fan_min[nr]; | 1258 | u8 old_min = data->fan_min[nr]; |
1275 | 1259 | ||
1276 | /* Increase clock divider if needed and possible */ | 1260 | /* Increase clock divider if needed and possible */ |
@@ -1280,7 +1264,7 @@ static void pc87360_autodiv(struct i2c_client *client, int nr) | |||
1280 | data->fan_status[nr] += 0x20; | 1264 | data->fan_status[nr] += 0x20; |
1281 | data->fan_min[nr] >>= 1; | 1265 | data->fan_min[nr] >>= 1; |
1282 | data->fan[nr] >>= 1; | 1266 | data->fan[nr] >>= 1; |
1283 | dev_dbg(&client->dev, "Increasing " | 1267 | dev_dbg(dev, "Increasing " |
1284 | "clock divider to %d for fan %d\n", | 1268 | "clock divider to %d for fan %d\n", |
1285 | FAN_DIV_FROM_REG(data->fan_status[nr]), nr+1); | 1269 | FAN_DIV_FROM_REG(data->fan_status[nr]), nr+1); |
1286 | } | 1270 | } |
@@ -1292,7 +1276,7 @@ static void pc87360_autodiv(struct i2c_client *client, int nr) | |||
1292 | data->fan_status[nr] -= 0x20; | 1276 | data->fan_status[nr] -= 0x20; |
1293 | data->fan_min[nr] <<= 1; | 1277 | data->fan_min[nr] <<= 1; |
1294 | data->fan[nr] <<= 1; | 1278 | data->fan[nr] <<= 1; |
1295 | dev_dbg(&client->dev, "Decreasing " | 1279 | dev_dbg(dev, "Decreasing " |
1296 | "clock divider to %d for fan %d\n", | 1280 | "clock divider to %d for fan %d\n", |
1297 | FAN_DIV_FROM_REG(data->fan_status[nr]), | 1281 | FAN_DIV_FROM_REG(data->fan_status[nr]), |
1298 | nr+1); | 1282 | nr+1); |
@@ -1309,14 +1293,13 @@ static void pc87360_autodiv(struct i2c_client *client, int nr) | |||
1309 | 1293 | ||
1310 | static struct pc87360_data *pc87360_update_device(struct device *dev) | 1294 | static struct pc87360_data *pc87360_update_device(struct device *dev) |
1311 | { | 1295 | { |
1312 | struct i2c_client *client = to_i2c_client(dev); | 1296 | struct pc87360_data *data = dev_get_drvdata(dev); |
1313 | struct pc87360_data *data = i2c_get_clientdata(client); | ||
1314 | u8 i; | 1297 | u8 i; |
1315 | 1298 | ||
1316 | mutex_lock(&data->update_lock); | 1299 | mutex_lock(&data->update_lock); |
1317 | 1300 | ||
1318 | if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { | 1301 | if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { |
1319 | dev_dbg(&client->dev, "Data update\n"); | 1302 | dev_dbg(dev, "Data update\n"); |
1320 | 1303 | ||
1321 | /* Fans */ | 1304 | /* Fans */ |
1322 | for (i = 0; i < data->fannr; i++) { | 1305 | for (i = 0; i < data->fannr; i++) { |
@@ -1330,7 +1313,7 @@ static struct pc87360_data *pc87360_update_device(struct device *dev) | |||
1330 | LD_FAN, NO_BANK, | 1313 | LD_FAN, NO_BANK, |
1331 | PC87360_REG_FAN_MIN(i)); | 1314 | PC87360_REG_FAN_MIN(i)); |
1332 | /* Change clock divider if needed */ | 1315 | /* Change clock divider if needed */ |
1333 | pc87360_autodiv(client, i); | 1316 | pc87360_autodiv(dev, i); |
1334 | /* Clear bits and write new divider */ | 1317 | /* Clear bits and write new divider */ |
1335 | pc87360_write_value(data, LD_FAN, NO_BANK, | 1318 | pc87360_write_value(data, LD_FAN, NO_BANK, |
1336 | PC87360_REG_FAN_STATUS(i), | 1319 | PC87360_REG_FAN_STATUS(i), |
@@ -1418,9 +1401,53 @@ static struct pc87360_data *pc87360_update_device(struct device *dev) | |||
1418 | return data; | 1401 | return data; |
1419 | } | 1402 | } |
1420 | 1403 | ||
1404 | static int __init pc87360_device_add(unsigned short address) | ||
1405 | { | ||
1406 | struct resource res = { | ||
1407 | .name = "pc87360", | ||
1408 | .flags = IORESOURCE_IO, | ||
1409 | }; | ||
1410 | int err, i; | ||
1411 | |||
1412 | pdev = platform_device_alloc("pc87360", address); | ||
1413 | if (!pdev) { | ||
1414 | err = -ENOMEM; | ||
1415 | printk(KERN_ERR "pc87360: Device allocation failed\n"); | ||
1416 | goto exit; | ||
1417 | } | ||
1418 | |||
1419 | for (i = 0; i < 3; i++) { | ||
1420 | if (!extra_isa[i]) | ||
1421 | continue; | ||
1422 | res.start = extra_isa[i]; | ||
1423 | res.end = extra_isa[i] + PC87360_EXTENT - 1; | ||
1424 | err = platform_device_add_resources(pdev, &res, 1); | ||
1425 | if (err) { | ||
1426 | printk(KERN_ERR "pc87360: Device resource[%d] " | ||
1427 | "addition failed (%d)\n", i, err); | ||
1428 | goto exit_device_put; | ||
1429 | } | ||
1430 | } | ||
1431 | |||
1432 | err = platform_device_add(pdev); | ||
1433 | if (err) { | ||
1434 | printk(KERN_ERR "pc87360: Device addition failed (%d)\n", | ||
1435 | err); | ||
1436 | goto exit_device_put; | ||
1437 | } | ||
1438 | |||
1439 | return 0; | ||
1440 | |||
1441 | exit_device_put: | ||
1442 | platform_device_put(pdev); | ||
1443 | exit: | ||
1444 | return err; | ||
1445 | } | ||
1446 | |||
1421 | static int __init pc87360_init(void) | 1447 | static int __init pc87360_init(void) |
1422 | { | 1448 | { |
1423 | int i; | 1449 | int err, i; |
1450 | unsigned short address = 0; | ||
1424 | 1451 | ||
1425 | if (pc87360_find(0x2e, &devid, extra_isa) | 1452 | if (pc87360_find(0x2e, &devid, extra_isa) |
1426 | && pc87360_find(0x4e, &devid, extra_isa)) { | 1453 | && pc87360_find(0x4e, &devid, extra_isa)) { |
@@ -1443,12 +1470,27 @@ static int __init pc87360_init(void) | |||
1443 | return -ENODEV; | 1470 | return -ENODEV; |
1444 | } | 1471 | } |
1445 | 1472 | ||
1446 | return i2c_isa_add_driver(&pc87360_driver); | 1473 | err = platform_driver_register(&pc87360_driver); |
1474 | if (err) | ||
1475 | goto exit; | ||
1476 | |||
1477 | /* Sets global pdev as a side effect */ | ||
1478 | err = pc87360_device_add(address); | ||
1479 | if (err) | ||
1480 | goto exit_driver; | ||
1481 | |||
1482 | return 0; | ||
1483 | |||
1484 | exit_driver: | ||
1485 | platform_driver_unregister(&pc87360_driver); | ||
1486 | exit: | ||
1487 | return err; | ||
1447 | } | 1488 | } |
1448 | 1489 | ||
1449 | static void __exit pc87360_exit(void) | 1490 | static void __exit pc87360_exit(void) |
1450 | { | 1491 | { |
1451 | i2c_isa_del_driver(&pc87360_driver); | 1492 | platform_device_unregister(pdev); |
1493 | platform_driver_unregister(&pc87360_driver); | ||
1452 | } | 1494 | } |
1453 | 1495 | ||
1454 | 1496 | ||
diff --git a/drivers/hwmon/pc87427.c b/drivers/hwmon/pc87427.c index 29354fa26f81..2915bc4ad0d5 100644 --- a/drivers/hwmon/pc87427.c +++ b/drivers/hwmon/pc87427.c | |||
@@ -484,7 +484,6 @@ static int __devexit pc87427_remove(struct platform_device *pdev) | |||
484 | struct resource *res; | 484 | struct resource *res; |
485 | int i; | 485 | int i; |
486 | 486 | ||
487 | platform_set_drvdata(pdev, NULL); | ||
488 | hwmon_device_unregister(data->class_dev); | 487 | hwmon_device_unregister(data->class_dev); |
489 | device_remove_file(&pdev->dev, &dev_attr_name); | 488 | device_remove_file(&pdev->dev, &dev_attr_name); |
490 | for (i = 0; i < 8; i++) { | 489 | for (i = 0; i < 8; i++) { |
@@ -492,6 +491,7 @@ static int __devexit pc87427_remove(struct platform_device *pdev) | |||
492 | continue; | 491 | continue; |
493 | sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_fan[i]); | 492 | sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_fan[i]); |
494 | } | 493 | } |
494 | platform_set_drvdata(pdev, NULL); | ||
495 | kfree(data); | 495 | kfree(data); |
496 | 496 | ||
497 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | 497 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c index 3f400263fc0f..83321b28cf0e 100644 --- a/drivers/hwmon/sis5595.c +++ b/drivers/hwmon/sis5595.c | |||
@@ -54,9 +54,9 @@ | |||
54 | #include <linux/slab.h> | 54 | #include <linux/slab.h> |
55 | #include <linux/ioport.h> | 55 | #include <linux/ioport.h> |
56 | #include <linux/pci.h> | 56 | #include <linux/pci.h> |
57 | #include <linux/i2c.h> | 57 | #include <linux/platform_device.h> |
58 | #include <linux/i2c-isa.h> | ||
59 | #include <linux/hwmon.h> | 58 | #include <linux/hwmon.h> |
59 | #include <linux/hwmon-sysfs.h> | ||
60 | #include <linux/err.h> | 60 | #include <linux/err.h> |
61 | #include <linux/init.h> | 61 | #include <linux/init.h> |
62 | #include <linux/jiffies.h> | 62 | #include <linux/jiffies.h> |
@@ -72,17 +72,13 @@ module_param(force_addr, ushort, 0); | |||
72 | MODULE_PARM_DESC(force_addr, | 72 | MODULE_PARM_DESC(force_addr, |
73 | "Initialize the base address of the sensors"); | 73 | "Initialize the base address of the sensors"); |
74 | 74 | ||
75 | /* Device address | 75 | static struct platform_device *pdev; |
76 | Note that we can't determine the ISA address until we have initialized | ||
77 | our module */ | ||
78 | static unsigned short address; | ||
79 | 76 | ||
80 | /* Many SIS5595 constants specified below */ | 77 | /* Many SIS5595 constants specified below */ |
81 | 78 | ||
82 | /* Length of ISA address segment */ | 79 | /* Length of ISA address segment */ |
83 | #define SIS5595_EXTENT 8 | 80 | #define SIS5595_EXTENT 8 |
84 | /* PCI Config Registers */ | 81 | /* PCI Config Registers */ |
85 | #define SIS5595_REVISION_REG 0x08 | ||
86 | #define SIS5595_BASE_REG 0x68 | 82 | #define SIS5595_BASE_REG 0x68 |
87 | #define SIS5595_PIN_REG 0x7A | 83 | #define SIS5595_PIN_REG 0x7A |
88 | #define SIS5595_ENABLE_REG 0x7B | 84 | #define SIS5595_ENABLE_REG 0x7B |
@@ -165,7 +161,8 @@ static inline u8 DIV_TO_REG(int val) | |||
165 | /* For each registered chip, we need to keep some data in memory. | 161 | /* For each registered chip, we need to keep some data in memory. |
166 | The structure is dynamically allocated. */ | 162 | The structure is dynamically allocated. */ |
167 | struct sis5595_data { | 163 | struct sis5595_data { |
168 | struct i2c_client client; | 164 | unsigned short addr; |
165 | const char *name; | ||
169 | struct class_device *class_dev; | 166 | struct class_device *class_dev; |
170 | struct mutex lock; | 167 | struct mutex lock; |
171 | 168 | ||
@@ -189,102 +186,88 @@ struct sis5595_data { | |||
189 | 186 | ||
190 | static struct pci_dev *s_bridge; /* pointer to the (only) sis5595 */ | 187 | static struct pci_dev *s_bridge; /* pointer to the (only) sis5595 */ |
191 | 188 | ||
192 | static int sis5595_detect(struct i2c_adapter *adapter); | 189 | static int sis5595_probe(struct platform_device *pdev); |
193 | static int sis5595_detach_client(struct i2c_client *client); | 190 | static int sis5595_remove(struct platform_device *pdev); |
194 | 191 | ||
195 | static int sis5595_read_value(struct i2c_client *client, u8 reg); | 192 | static int sis5595_read_value(struct sis5595_data *data, u8 reg); |
196 | static int sis5595_write_value(struct i2c_client *client, u8 reg, u8 value); | 193 | static void sis5595_write_value(struct sis5595_data *data, u8 reg, u8 value); |
197 | static struct sis5595_data *sis5595_update_device(struct device *dev); | 194 | static struct sis5595_data *sis5595_update_device(struct device *dev); |
198 | static void sis5595_init_client(struct i2c_client *client); | 195 | static void sis5595_init_device(struct sis5595_data *data); |
199 | 196 | ||
200 | static struct i2c_driver sis5595_driver = { | 197 | static struct platform_driver sis5595_driver = { |
201 | .driver = { | 198 | .driver = { |
202 | .owner = THIS_MODULE, | 199 | .owner = THIS_MODULE, |
203 | .name = "sis5595", | 200 | .name = "sis5595", |
204 | }, | 201 | }, |
205 | .attach_adapter = sis5595_detect, | 202 | .probe = sis5595_probe, |
206 | .detach_client = sis5595_detach_client, | 203 | .remove = __devexit_p(sis5595_remove), |
207 | }; | 204 | }; |
208 | 205 | ||
209 | /* 4 Voltages */ | 206 | /* 4 Voltages */ |
210 | static ssize_t show_in(struct device *dev, char *buf, int nr) | 207 | static ssize_t show_in(struct device *dev, struct device_attribute *da, |
208 | char *buf) | ||
211 | { | 209 | { |
212 | struct sis5595_data *data = sis5595_update_device(dev); | 210 | struct sis5595_data *data = sis5595_update_device(dev); |
211 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
212 | int nr = attr->index; | ||
213 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); | 213 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); |
214 | } | 214 | } |
215 | 215 | ||
216 | static ssize_t show_in_min(struct device *dev, char *buf, int nr) | 216 | static ssize_t show_in_min(struct device *dev, struct device_attribute *da, |
217 | char *buf) | ||
217 | { | 218 | { |
218 | struct sis5595_data *data = sis5595_update_device(dev); | 219 | struct sis5595_data *data = sis5595_update_device(dev); |
220 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
221 | int nr = attr->index; | ||
219 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); | 222 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); |
220 | } | 223 | } |
221 | 224 | ||
222 | static ssize_t show_in_max(struct device *dev, char *buf, int nr) | 225 | static ssize_t show_in_max(struct device *dev, struct device_attribute *da, |
226 | char *buf) | ||
223 | { | 227 | { |
224 | struct sis5595_data *data = sis5595_update_device(dev); | 228 | struct sis5595_data *data = sis5595_update_device(dev); |
229 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
230 | int nr = attr->index; | ||
225 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); | 231 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); |
226 | } | 232 | } |
227 | 233 | ||
228 | static ssize_t set_in_min(struct device *dev, const char *buf, | 234 | static ssize_t set_in_min(struct device *dev, struct device_attribute *da, |
229 | size_t count, int nr) | 235 | const char *buf, size_t count) |
230 | { | 236 | { |
231 | struct i2c_client *client = to_i2c_client(dev); | 237 | struct sis5595_data *data = dev_get_drvdata(dev); |
232 | struct sis5595_data *data = i2c_get_clientdata(client); | 238 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
239 | int nr = attr->index; | ||
233 | unsigned long val = simple_strtoul(buf, NULL, 10); | 240 | unsigned long val = simple_strtoul(buf, NULL, 10); |
234 | 241 | ||
235 | mutex_lock(&data->update_lock); | 242 | mutex_lock(&data->update_lock); |
236 | data->in_min[nr] = IN_TO_REG(val); | 243 | data->in_min[nr] = IN_TO_REG(val); |
237 | sis5595_write_value(client, SIS5595_REG_IN_MIN(nr), data->in_min[nr]); | 244 | sis5595_write_value(data, SIS5595_REG_IN_MIN(nr), data->in_min[nr]); |
238 | mutex_unlock(&data->update_lock); | 245 | mutex_unlock(&data->update_lock); |
239 | return count; | 246 | return count; |
240 | } | 247 | } |
241 | 248 | ||
242 | static ssize_t set_in_max(struct device *dev, const char *buf, | 249 | static ssize_t set_in_max(struct device *dev, struct device_attribute *da, |
243 | size_t count, int nr) | 250 | const char *buf, size_t count) |
244 | { | 251 | { |
245 | struct i2c_client *client = to_i2c_client(dev); | 252 | struct sis5595_data *data = dev_get_drvdata(dev); |
246 | struct sis5595_data *data = i2c_get_clientdata(client); | 253 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
254 | int nr = attr->index; | ||
247 | unsigned long val = simple_strtoul(buf, NULL, 10); | 255 | unsigned long val = simple_strtoul(buf, NULL, 10); |
248 | 256 | ||
249 | mutex_lock(&data->update_lock); | 257 | mutex_lock(&data->update_lock); |
250 | data->in_max[nr] = IN_TO_REG(val); | 258 | data->in_max[nr] = IN_TO_REG(val); |
251 | sis5595_write_value(client, SIS5595_REG_IN_MAX(nr), data->in_max[nr]); | 259 | sis5595_write_value(data, SIS5595_REG_IN_MAX(nr), data->in_max[nr]); |
252 | mutex_unlock(&data->update_lock); | 260 | mutex_unlock(&data->update_lock); |
253 | return count; | 261 | return count; |
254 | } | 262 | } |
255 | 263 | ||
256 | #define show_in_offset(offset) \ | 264 | #define show_in_offset(offset) \ |
257 | static ssize_t \ | 265 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
258 | show_in##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | 266 | show_in, NULL, offset); \ |
259 | { \ | 267 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ |
260 | return show_in(dev, buf, offset); \ | 268 | show_in_min, set_in_min, offset); \ |
261 | } \ | 269 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ |
262 | static DEVICE_ATTR(in##offset##_input, S_IRUGO, \ | 270 | show_in_max, set_in_max, offset); |
263 | show_in##offset, NULL); \ | ||
264 | static ssize_t \ | ||
265 | show_in##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
266 | { \ | ||
267 | return show_in_min(dev, buf, offset); \ | ||
268 | } \ | ||
269 | static ssize_t \ | ||
270 | show_in##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
271 | { \ | ||
272 | return show_in_max(dev, buf, offset); \ | ||
273 | } \ | ||
274 | static ssize_t set_in##offset##_min (struct device *dev, struct device_attribute *attr, \ | ||
275 | const char *buf, size_t count) \ | ||
276 | { \ | ||
277 | return set_in_min(dev, buf, count, offset); \ | ||
278 | } \ | ||
279 | static ssize_t set_in##offset##_max (struct device *dev, struct device_attribute *attr, \ | ||
280 | const char *buf, size_t count) \ | ||
281 | { \ | ||
282 | return set_in_max(dev, buf, count, offset); \ | ||
283 | } \ | ||
284 | static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ | ||
285 | show_in##offset##_min, set_in##offset##_min); \ | ||
286 | static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ | ||
287 | show_in##offset##_max, set_in##offset##_max); | ||
288 | 271 | ||
289 | show_in_offset(0); | 272 | show_in_offset(0); |
290 | show_in_offset(1); | 273 | show_in_offset(1); |
@@ -307,13 +290,12 @@ static ssize_t show_temp_over(struct device *dev, struct device_attribute *attr, | |||
307 | 290 | ||
308 | static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 291 | static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
309 | { | 292 | { |
310 | struct i2c_client *client = to_i2c_client(dev); | 293 | struct sis5595_data *data = dev_get_drvdata(dev); |
311 | struct sis5595_data *data = i2c_get_clientdata(client); | ||
312 | long val = simple_strtol(buf, NULL, 10); | 294 | long val = simple_strtol(buf, NULL, 10); |
313 | 295 | ||
314 | mutex_lock(&data->update_lock); | 296 | mutex_lock(&data->update_lock); |
315 | data->temp_over = TEMP_TO_REG(val); | 297 | data->temp_over = TEMP_TO_REG(val); |
316 | sis5595_write_value(client, SIS5595_REG_TEMP_OVER, data->temp_over); | 298 | sis5595_write_value(data, SIS5595_REG_TEMP_OVER, data->temp_over); |
317 | mutex_unlock(&data->update_lock); | 299 | mutex_unlock(&data->update_lock); |
318 | return count; | 300 | return count; |
319 | } | 301 | } |
@@ -326,13 +308,12 @@ static ssize_t show_temp_hyst(struct device *dev, struct device_attribute *attr, | |||
326 | 308 | ||
327 | static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 309 | static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
328 | { | 310 | { |
329 | struct i2c_client *client = to_i2c_client(dev); | 311 | struct sis5595_data *data = dev_get_drvdata(dev); |
330 | struct sis5595_data *data = i2c_get_clientdata(client); | ||
331 | long val = simple_strtol(buf, NULL, 10); | 312 | long val = simple_strtol(buf, NULL, 10); |
332 | 313 | ||
333 | mutex_lock(&data->update_lock); | 314 | mutex_lock(&data->update_lock); |
334 | data->temp_hyst = TEMP_TO_REG(val); | 315 | data->temp_hyst = TEMP_TO_REG(val); |
335 | sis5595_write_value(client, SIS5595_REG_TEMP_HYST, data->temp_hyst); | 316 | sis5595_write_value(data, SIS5595_REG_TEMP_HYST, data->temp_hyst); |
336 | mutex_unlock(&data->update_lock); | 317 | mutex_unlock(&data->update_lock); |
337 | return count; | 318 | return count; |
338 | } | 319 | } |
@@ -344,37 +325,47 @@ static DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, | |||
344 | show_temp_hyst, set_temp_hyst); | 325 | show_temp_hyst, set_temp_hyst); |
345 | 326 | ||
346 | /* 2 Fans */ | 327 | /* 2 Fans */ |
347 | static ssize_t show_fan(struct device *dev, char *buf, int nr) | 328 | static ssize_t show_fan(struct device *dev, struct device_attribute *da, |
329 | char *buf) | ||
348 | { | 330 | { |
349 | struct sis5595_data *data = sis5595_update_device(dev); | 331 | struct sis5595_data *data = sis5595_update_device(dev); |
332 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
333 | int nr = attr->index; | ||
350 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], | 334 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], |
351 | DIV_FROM_REG(data->fan_div[nr])) ); | 335 | DIV_FROM_REG(data->fan_div[nr])) ); |
352 | } | 336 | } |
353 | 337 | ||
354 | static ssize_t show_fan_min(struct device *dev, char *buf, int nr) | 338 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *da, |
339 | char *buf) | ||
355 | { | 340 | { |
356 | struct sis5595_data *data = sis5595_update_device(dev); | 341 | struct sis5595_data *data = sis5595_update_device(dev); |
342 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
343 | int nr = attr->index; | ||
357 | return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr], | 344 | return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr], |
358 | DIV_FROM_REG(data->fan_div[nr])) ); | 345 | DIV_FROM_REG(data->fan_div[nr])) ); |
359 | } | 346 | } |
360 | 347 | ||
361 | static ssize_t set_fan_min(struct device *dev, const char *buf, | 348 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *da, |
362 | size_t count, int nr) | 349 | const char *buf, size_t count) |
363 | { | 350 | { |
364 | struct i2c_client *client = to_i2c_client(dev); | 351 | struct sis5595_data *data = dev_get_drvdata(dev); |
365 | struct sis5595_data *data = i2c_get_clientdata(client); | 352 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
353 | int nr = attr->index; | ||
366 | unsigned long val = simple_strtoul(buf, NULL, 10); | 354 | unsigned long val = simple_strtoul(buf, NULL, 10); |
367 | 355 | ||
368 | mutex_lock(&data->update_lock); | 356 | mutex_lock(&data->update_lock); |
369 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); | 357 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
370 | sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); | 358 | sis5595_write_value(data, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); |
371 | mutex_unlock(&data->update_lock); | 359 | mutex_unlock(&data->update_lock); |
372 | return count; | 360 | return count; |
373 | } | 361 | } |
374 | 362 | ||
375 | static ssize_t show_fan_div(struct device *dev, char *buf, int nr) | 363 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *da, |
364 | char *buf) | ||
376 | { | 365 | { |
377 | struct sis5595_data *data = sis5595_update_device(dev); | 366 | struct sis5595_data *data = sis5595_update_device(dev); |
367 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
368 | int nr = attr->index; | ||
378 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); | 369 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); |
379 | } | 370 | } |
380 | 371 | ||
@@ -382,11 +373,12 @@ static ssize_t show_fan_div(struct device *dev, char *buf, int nr) | |||
382 | determined in part by the fan divisor. This follows the principle of | 373 | determined in part by the fan divisor. This follows the principle of |
383 | least surprise; the user doesn't expect the fan minimum to change just | 374 | least surprise; the user doesn't expect the fan minimum to change just |
384 | because the divisor changed. */ | 375 | because the divisor changed. */ |
385 | static ssize_t set_fan_div(struct device *dev, const char *buf, | 376 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *da, |
386 | size_t count, int nr) | 377 | const char *buf, size_t count) |
387 | { | 378 | { |
388 | struct i2c_client *client = to_i2c_client(dev); | 379 | struct sis5595_data *data = dev_get_drvdata(dev); |
389 | struct sis5595_data *data = i2c_get_clientdata(client); | 380 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
381 | int nr = attr->index; | ||
390 | unsigned long min; | 382 | unsigned long min; |
391 | unsigned long val = simple_strtoul(buf, NULL, 10); | 383 | unsigned long val = simple_strtoul(buf, NULL, 10); |
392 | int reg; | 384 | int reg; |
@@ -394,7 +386,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, | |||
394 | mutex_lock(&data->update_lock); | 386 | mutex_lock(&data->update_lock); |
395 | min = FAN_FROM_REG(data->fan_min[nr], | 387 | min = FAN_FROM_REG(data->fan_min[nr], |
396 | DIV_FROM_REG(data->fan_div[nr])); | 388 | DIV_FROM_REG(data->fan_div[nr])); |
397 | reg = sis5595_read_value(client, SIS5595_REG_FANDIV); | 389 | reg = sis5595_read_value(data, SIS5595_REG_FANDIV); |
398 | 390 | ||
399 | switch (val) { | 391 | switch (val) { |
400 | case 1: data->fan_div[nr] = 0; break; | 392 | case 1: data->fan_div[nr] = 0; break; |
@@ -402,7 +394,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, | |||
402 | case 4: data->fan_div[nr] = 2; break; | 394 | case 4: data->fan_div[nr] = 2; break; |
403 | case 8: data->fan_div[nr] = 3; break; | 395 | case 8: data->fan_div[nr] = 3; break; |
404 | default: | 396 | default: |
405 | dev_err(&client->dev, "fan_div value %ld not " | 397 | dev_err(dev, "fan_div value %ld not " |
406 | "supported. Choose one of 1, 2, 4 or 8!\n", val); | 398 | "supported. Choose one of 1, 2, 4 or 8!\n", val); |
407 | mutex_unlock(&data->update_lock); | 399 | mutex_unlock(&data->update_lock); |
408 | return -EINVAL; | 400 | return -EINVAL; |
@@ -416,55 +408,25 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, | |||
416 | reg = (reg & 0x3f) | (data->fan_div[nr] << 6); | 408 | reg = (reg & 0x3f) | (data->fan_div[nr] << 6); |
417 | break; | 409 | break; |
418 | } | 410 | } |
419 | sis5595_write_value(client, SIS5595_REG_FANDIV, reg); | 411 | sis5595_write_value(data, SIS5595_REG_FANDIV, reg); |
420 | data->fan_min[nr] = | 412 | data->fan_min[nr] = |
421 | FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); | 413 | FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); |
422 | sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); | 414 | sis5595_write_value(data, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]); |
423 | mutex_unlock(&data->update_lock); | 415 | mutex_unlock(&data->update_lock); |
424 | return count; | 416 | return count; |
425 | } | 417 | } |
426 | 418 | ||
427 | #define show_fan_offset(offset) \ | 419 | #define show_fan_offset(offset) \ |
428 | static ssize_t show_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | 420 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ |
429 | { \ | 421 | show_fan, NULL, offset - 1); \ |
430 | return show_fan(dev, buf, offset - 1); \ | 422 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
431 | } \ | 423 | show_fan_min, set_fan_min, offset - 1); \ |
432 | static ssize_t show_fan_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ | 424 | static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ |
433 | { \ | 425 | show_fan_div, set_fan_div, offset - 1); |
434 | return show_fan_min(dev, buf, offset - 1); \ | ||
435 | } \ | ||
436 | static ssize_t show_fan_##offset##_div (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
437 | { \ | ||
438 | return show_fan_div(dev, buf, offset - 1); \ | ||
439 | } \ | ||
440 | static ssize_t set_fan_##offset##_min (struct device *dev, struct device_attribute *attr, \ | ||
441 | const char *buf, size_t count) \ | ||
442 | { \ | ||
443 | return set_fan_min(dev, buf, count, offset - 1); \ | ||
444 | } \ | ||
445 | static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL);\ | ||
446 | static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ | ||
447 | show_fan_##offset##_min, set_fan_##offset##_min); | ||
448 | 426 | ||
449 | show_fan_offset(1); | 427 | show_fan_offset(1); |
450 | show_fan_offset(2); | 428 | show_fan_offset(2); |
451 | 429 | ||
452 | static ssize_t set_fan_1_div(struct device *dev, struct device_attribute *attr, const char *buf, | ||
453 | size_t count) | ||
454 | { | ||
455 | return set_fan_div(dev, buf, count, 0) ; | ||
456 | } | ||
457 | |||
458 | static ssize_t set_fan_2_div(struct device *dev, struct device_attribute *attr, const char *buf, | ||
459 | size_t count) | ||
460 | { | ||
461 | return set_fan_div(dev, buf, count, 1) ; | ||
462 | } | ||
463 | static DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, | ||
464 | show_fan_1_div, set_fan_1_div); | ||
465 | static DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, | ||
466 | show_fan_2_div, set_fan_2_div); | ||
467 | |||
468 | /* Alarms */ | 430 | /* Alarms */ |
469 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) | 431 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) |
470 | { | 432 | { |
@@ -473,28 +435,37 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch | |||
473 | } | 435 | } |
474 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 436 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
475 | 437 | ||
438 | static ssize_t show_name(struct device *dev, struct device_attribute *attr, | ||
439 | char *buf) | ||
440 | { | ||
441 | struct sis5595_data *data = dev_get_drvdata(dev); | ||
442 | return sprintf(buf, "%s\n", data->name); | ||
443 | } | ||
444 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
445 | |||
476 | static struct attribute *sis5595_attributes[] = { | 446 | static struct attribute *sis5595_attributes[] = { |
477 | &dev_attr_in0_input.attr, | 447 | &sensor_dev_attr_in0_input.dev_attr.attr, |
478 | &dev_attr_in0_min.attr, | 448 | &sensor_dev_attr_in0_min.dev_attr.attr, |
479 | &dev_attr_in0_max.attr, | 449 | &sensor_dev_attr_in0_max.dev_attr.attr, |
480 | &dev_attr_in1_input.attr, | 450 | &sensor_dev_attr_in1_input.dev_attr.attr, |
481 | &dev_attr_in1_min.attr, | 451 | &sensor_dev_attr_in1_min.dev_attr.attr, |
482 | &dev_attr_in1_max.attr, | 452 | &sensor_dev_attr_in1_max.dev_attr.attr, |
483 | &dev_attr_in2_input.attr, | 453 | &sensor_dev_attr_in2_input.dev_attr.attr, |
484 | &dev_attr_in2_min.attr, | 454 | &sensor_dev_attr_in2_min.dev_attr.attr, |
485 | &dev_attr_in2_max.attr, | 455 | &sensor_dev_attr_in2_max.dev_attr.attr, |
486 | &dev_attr_in3_input.attr, | 456 | &sensor_dev_attr_in3_input.dev_attr.attr, |
487 | &dev_attr_in3_min.attr, | 457 | &sensor_dev_attr_in3_min.dev_attr.attr, |
488 | &dev_attr_in3_max.attr, | 458 | &sensor_dev_attr_in3_max.dev_attr.attr, |
489 | 459 | ||
490 | &dev_attr_fan1_input.attr, | 460 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
491 | &dev_attr_fan1_min.attr, | 461 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
492 | &dev_attr_fan1_div.attr, | 462 | &sensor_dev_attr_fan1_div.dev_attr.attr, |
493 | &dev_attr_fan2_input.attr, | 463 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
494 | &dev_attr_fan2_min.attr, | 464 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
495 | &dev_attr_fan2_div.attr, | 465 | &sensor_dev_attr_fan2_div.dev_attr.attr, |
496 | 466 | ||
497 | &dev_attr_alarms.attr, | 467 | &dev_attr_alarms.attr, |
468 | &dev_attr_name.attr, | ||
498 | NULL | 469 | NULL |
499 | }; | 470 | }; |
500 | 471 | ||
@@ -503,9 +474,9 @@ static const struct attribute_group sis5595_group = { | |||
503 | }; | 474 | }; |
504 | 475 | ||
505 | static struct attribute *sis5595_attributes_opt[] = { | 476 | static struct attribute *sis5595_attributes_opt[] = { |
506 | &dev_attr_in4_input.attr, | 477 | &sensor_dev_attr_in4_input.dev_attr.attr, |
507 | &dev_attr_in4_min.attr, | 478 | &sensor_dev_attr_in4_min.dev_attr.attr, |
508 | &dev_attr_in4_max.attr, | 479 | &sensor_dev_attr_in4_max.dev_attr.attr, |
509 | 480 | ||
510 | &dev_attr_temp1_input.attr, | 481 | &dev_attr_temp1_input.attr, |
511 | &dev_attr_temp1_max.attr, | 482 | &dev_attr_temp1_max.attr, |
@@ -518,68 +489,35 @@ static const struct attribute_group sis5595_group_opt = { | |||
518 | }; | 489 | }; |
519 | 490 | ||
520 | /* This is called when the module is loaded */ | 491 | /* This is called when the module is loaded */ |
521 | static int sis5595_detect(struct i2c_adapter *adapter) | 492 | static int __devinit sis5595_probe(struct platform_device *pdev) |
522 | { | 493 | { |
523 | int err = 0; | 494 | int err = 0; |
524 | int i; | 495 | int i; |
525 | struct i2c_client *new_client; | ||
526 | struct sis5595_data *data; | 496 | struct sis5595_data *data; |
497 | struct resource *res; | ||
527 | char val; | 498 | char val; |
528 | u16 a; | ||
529 | 499 | ||
530 | if (force_addr) | ||
531 | address = force_addr & ~(SIS5595_EXTENT - 1); | ||
532 | /* Reserve the ISA region */ | 500 | /* Reserve the ISA region */ |
533 | if (!request_region(address, SIS5595_EXTENT, | 501 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
502 | if (!request_region(res->start, SIS5595_EXTENT, | ||
534 | sis5595_driver.driver.name)) { | 503 | sis5595_driver.driver.name)) { |
535 | err = -EBUSY; | 504 | err = -EBUSY; |
536 | goto exit; | 505 | goto exit; |
537 | } | 506 | } |
538 | if (force_addr) { | ||
539 | dev_warn(&adapter->dev, "forcing ISA address 0x%04X\n", address); | ||
540 | if (PCIBIOS_SUCCESSFUL != | ||
541 | pci_write_config_word(s_bridge, SIS5595_BASE_REG, address)) | ||
542 | goto exit_release; | ||
543 | if (PCIBIOS_SUCCESSFUL != | ||
544 | pci_read_config_word(s_bridge, SIS5595_BASE_REG, &a)) | ||
545 | goto exit_release; | ||
546 | if ((a & ~(SIS5595_EXTENT - 1)) != address) | ||
547 | /* doesn't work for some chips? */ | ||
548 | goto exit_release; | ||
549 | } | ||
550 | |||
551 | if (PCIBIOS_SUCCESSFUL != | ||
552 | pci_read_config_byte(s_bridge, SIS5595_ENABLE_REG, &val)) { | ||
553 | goto exit_release; | ||
554 | } | ||
555 | if ((val & 0x80) == 0) { | ||
556 | if (PCIBIOS_SUCCESSFUL != | ||
557 | pci_write_config_byte(s_bridge, SIS5595_ENABLE_REG, | ||
558 | val | 0x80)) | ||
559 | goto exit_release; | ||
560 | if (PCIBIOS_SUCCESSFUL != | ||
561 | pci_read_config_byte(s_bridge, SIS5595_ENABLE_REG, &val)) | ||
562 | goto exit_release; | ||
563 | if ((val & 0x80) == 0) | ||
564 | /* doesn't work for some chips! */ | ||
565 | goto exit_release; | ||
566 | } | ||
567 | 507 | ||
568 | if (!(data = kzalloc(sizeof(struct sis5595_data), GFP_KERNEL))) { | 508 | if (!(data = kzalloc(sizeof(struct sis5595_data), GFP_KERNEL))) { |
569 | err = -ENOMEM; | 509 | err = -ENOMEM; |
570 | goto exit_release; | 510 | goto exit_release; |
571 | } | 511 | } |
572 | 512 | ||
573 | new_client = &data->client; | ||
574 | new_client->addr = address; | ||
575 | mutex_init(&data->lock); | 513 | mutex_init(&data->lock); |
576 | i2c_set_clientdata(new_client, data); | 514 | mutex_init(&data->update_lock); |
577 | new_client->adapter = adapter; | 515 | data->addr = res->start; |
578 | new_client->driver = &sis5595_driver; | 516 | data->name = "sis5595"; |
579 | new_client->flags = 0; | 517 | platform_set_drvdata(pdev, data); |
580 | 518 | ||
581 | /* Check revision and pin registers to determine whether 4 or 5 voltages */ | 519 | /* Check revision and pin registers to determine whether 4 or 5 voltages */ |
582 | pci_read_config_byte(s_bridge, SIS5595_REVISION_REG, &(data->revision)); | 520 | pci_read_config_byte(s_bridge, PCI_REVISION_ID, &data->revision); |
583 | /* 4 voltages, 1 temp */ | 521 | /* 4 voltages, 1 temp */ |
584 | data->maxins = 3; | 522 | data->maxins = 3; |
585 | if (data->revision >= REV2MIN) { | 523 | if (data->revision >= REV2MIN) { |
@@ -589,47 +527,37 @@ static int sis5595_detect(struct i2c_adapter *adapter) | |||
589 | data->maxins = 4; | 527 | data->maxins = 4; |
590 | } | 528 | } |
591 | 529 | ||
592 | /* Fill in the remaining client fields and put it into the global list */ | ||
593 | strlcpy(new_client->name, "sis5595", I2C_NAME_SIZE); | ||
594 | |||
595 | data->valid = 0; | ||
596 | mutex_init(&data->update_lock); | ||
597 | |||
598 | /* Tell the I2C layer a new client has arrived */ | ||
599 | if ((err = i2c_attach_client(new_client))) | ||
600 | goto exit_free; | ||
601 | |||
602 | /* Initialize the SIS5595 chip */ | 530 | /* Initialize the SIS5595 chip */ |
603 | sis5595_init_client(new_client); | 531 | sis5595_init_device(data); |
604 | 532 | ||
605 | /* A few vars need to be filled upon startup */ | 533 | /* A few vars need to be filled upon startup */ |
606 | for (i = 0; i < 2; i++) { | 534 | for (i = 0; i < 2; i++) { |
607 | data->fan_min[i] = sis5595_read_value(new_client, | 535 | data->fan_min[i] = sis5595_read_value(data, |
608 | SIS5595_REG_FAN_MIN(i)); | 536 | SIS5595_REG_FAN_MIN(i)); |
609 | } | 537 | } |
610 | 538 | ||
611 | /* Register sysfs hooks */ | 539 | /* Register sysfs hooks */ |
612 | if ((err = sysfs_create_group(&new_client->dev.kobj, &sis5595_group))) | 540 | if ((err = sysfs_create_group(&pdev->dev.kobj, &sis5595_group))) |
613 | goto exit_detach; | 541 | goto exit_free; |
614 | if (data->maxins == 4) { | 542 | if (data->maxins == 4) { |
615 | if ((err = device_create_file(&new_client->dev, | 543 | if ((err = device_create_file(&pdev->dev, |
616 | &dev_attr_in4_input)) | 544 | &sensor_dev_attr_in4_input.dev_attr)) |
617 | || (err = device_create_file(&new_client->dev, | 545 | || (err = device_create_file(&pdev->dev, |
618 | &dev_attr_in4_min)) | 546 | &sensor_dev_attr_in4_min.dev_attr)) |
619 | || (err = device_create_file(&new_client->dev, | 547 | || (err = device_create_file(&pdev->dev, |
620 | &dev_attr_in4_max))) | 548 | &sensor_dev_attr_in4_max.dev_attr))) |
621 | goto exit_remove_files; | 549 | goto exit_remove_files; |
622 | } else { | 550 | } else { |
623 | if ((err = device_create_file(&new_client->dev, | 551 | if ((err = device_create_file(&pdev->dev, |
624 | &dev_attr_temp1_input)) | 552 | &dev_attr_temp1_input)) |
625 | || (err = device_create_file(&new_client->dev, | 553 | || (err = device_create_file(&pdev->dev, |
626 | &dev_attr_temp1_max)) | 554 | &dev_attr_temp1_max)) |
627 | || (err = device_create_file(&new_client->dev, | 555 | || (err = device_create_file(&pdev->dev, |
628 | &dev_attr_temp1_max_hyst))) | 556 | &dev_attr_temp1_max_hyst))) |
629 | goto exit_remove_files; | 557 | goto exit_remove_files; |
630 | } | 558 | } |
631 | 559 | ||
632 | data->class_dev = hwmon_device_register(&new_client->dev); | 560 | data->class_dev = hwmon_device_register(&pdev->dev); |
633 | if (IS_ERR(data->class_dev)) { | 561 | if (IS_ERR(data->class_dev)) { |
634 | err = PTR_ERR(data->class_dev); | 562 | err = PTR_ERR(data->class_dev); |
635 | goto exit_remove_files; | 563 | goto exit_remove_files; |
@@ -638,32 +566,26 @@ static int sis5595_detect(struct i2c_adapter *adapter) | |||
638 | return 0; | 566 | return 0; |
639 | 567 | ||
640 | exit_remove_files: | 568 | exit_remove_files: |
641 | sysfs_remove_group(&new_client->dev.kobj, &sis5595_group); | 569 | sysfs_remove_group(&pdev->dev.kobj, &sis5595_group); |
642 | sysfs_remove_group(&new_client->dev.kobj, &sis5595_group_opt); | 570 | sysfs_remove_group(&pdev->dev.kobj, &sis5595_group_opt); |
643 | exit_detach: | ||
644 | i2c_detach_client(new_client); | ||
645 | exit_free: | 571 | exit_free: |
646 | kfree(data); | 572 | kfree(data); |
647 | exit_release: | 573 | exit_release: |
648 | release_region(address, SIS5595_EXTENT); | 574 | release_region(res->start, SIS5595_EXTENT); |
649 | exit: | 575 | exit: |
650 | return err; | 576 | return err; |
651 | } | 577 | } |
652 | 578 | ||
653 | static int sis5595_detach_client(struct i2c_client *client) | 579 | static int __devexit sis5595_remove(struct platform_device *pdev) |
654 | { | 580 | { |
655 | struct sis5595_data *data = i2c_get_clientdata(client); | 581 | struct sis5595_data *data = platform_get_drvdata(pdev); |
656 | int err; | ||
657 | 582 | ||
658 | hwmon_device_unregister(data->class_dev); | 583 | hwmon_device_unregister(data->class_dev); |
659 | sysfs_remove_group(&client->dev.kobj, &sis5595_group); | 584 | sysfs_remove_group(&pdev->dev.kobj, &sis5595_group); |
660 | sysfs_remove_group(&client->dev.kobj, &sis5595_group_opt); | 585 | sysfs_remove_group(&pdev->dev.kobj, &sis5595_group_opt); |
661 | |||
662 | if ((err = i2c_detach_client(client))) | ||
663 | return err; | ||
664 | |||
665 | release_region(client->addr, SIS5595_EXTENT); | ||
666 | 586 | ||
587 | release_region(data->addr, SIS5595_EXTENT); | ||
588 | platform_set_drvdata(pdev, NULL); | ||
667 | kfree(data); | 589 | kfree(data); |
668 | 590 | ||
669 | return 0; | 591 | return 0; |
@@ -671,41 +593,37 @@ static int sis5595_detach_client(struct i2c_client *client) | |||
671 | 593 | ||
672 | 594 | ||
673 | /* ISA access must be locked explicitly. */ | 595 | /* ISA access must be locked explicitly. */ |
674 | static int sis5595_read_value(struct i2c_client *client, u8 reg) | 596 | static int sis5595_read_value(struct sis5595_data *data, u8 reg) |
675 | { | 597 | { |
676 | int res; | 598 | int res; |
677 | 599 | ||
678 | struct sis5595_data *data = i2c_get_clientdata(client); | ||
679 | mutex_lock(&data->lock); | 600 | mutex_lock(&data->lock); |
680 | outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET); | 601 | outb_p(reg, data->addr + SIS5595_ADDR_REG_OFFSET); |
681 | res = inb_p(client->addr + SIS5595_DATA_REG_OFFSET); | 602 | res = inb_p(data->addr + SIS5595_DATA_REG_OFFSET); |
682 | mutex_unlock(&data->lock); | 603 | mutex_unlock(&data->lock); |
683 | return res; | 604 | return res; |
684 | } | 605 | } |
685 | 606 | ||
686 | static int sis5595_write_value(struct i2c_client *client, u8 reg, u8 value) | 607 | static void sis5595_write_value(struct sis5595_data *data, u8 reg, u8 value) |
687 | { | 608 | { |
688 | struct sis5595_data *data = i2c_get_clientdata(client); | ||
689 | mutex_lock(&data->lock); | 609 | mutex_lock(&data->lock); |
690 | outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET); | 610 | outb_p(reg, data->addr + SIS5595_ADDR_REG_OFFSET); |
691 | outb_p(value, client->addr + SIS5595_DATA_REG_OFFSET); | 611 | outb_p(value, data->addr + SIS5595_DATA_REG_OFFSET); |
692 | mutex_unlock(&data->lock); | 612 | mutex_unlock(&data->lock); |
693 | return 0; | ||
694 | } | 613 | } |
695 | 614 | ||
696 | /* Called when we have found a new SIS5595. */ | 615 | /* Called when we have found a new SIS5595. */ |
697 | static void sis5595_init_client(struct i2c_client *client) | 616 | static void __devinit sis5595_init_device(struct sis5595_data *data) |
698 | { | 617 | { |
699 | u8 config = sis5595_read_value(client, SIS5595_REG_CONFIG); | 618 | u8 config = sis5595_read_value(data, SIS5595_REG_CONFIG); |
700 | if (!(config & 0x01)) | 619 | if (!(config & 0x01)) |
701 | sis5595_write_value(client, SIS5595_REG_CONFIG, | 620 | sis5595_write_value(data, SIS5595_REG_CONFIG, |
702 | (config & 0xf7) | 0x01); | 621 | (config & 0xf7) | 0x01); |
703 | } | 622 | } |
704 | 623 | ||
705 | static struct sis5595_data *sis5595_update_device(struct device *dev) | 624 | static struct sis5595_data *sis5595_update_device(struct device *dev) |
706 | { | 625 | { |
707 | struct i2c_client *client = to_i2c_client(dev); | 626 | struct sis5595_data *data = dev_get_drvdata(dev); |
708 | struct sis5595_data *data = i2c_get_clientdata(client); | ||
709 | int i; | 627 | int i; |
710 | 628 | ||
711 | mutex_lock(&data->update_lock); | 629 | mutex_lock(&data->update_lock); |
@@ -715,35 +633,35 @@ static struct sis5595_data *sis5595_update_device(struct device *dev) | |||
715 | 633 | ||
716 | for (i = 0; i <= data->maxins; i++) { | 634 | for (i = 0; i <= data->maxins; i++) { |
717 | data->in[i] = | 635 | data->in[i] = |
718 | sis5595_read_value(client, SIS5595_REG_IN(i)); | 636 | sis5595_read_value(data, SIS5595_REG_IN(i)); |
719 | data->in_min[i] = | 637 | data->in_min[i] = |
720 | sis5595_read_value(client, | 638 | sis5595_read_value(data, |
721 | SIS5595_REG_IN_MIN(i)); | 639 | SIS5595_REG_IN_MIN(i)); |
722 | data->in_max[i] = | 640 | data->in_max[i] = |
723 | sis5595_read_value(client, | 641 | sis5595_read_value(data, |
724 | SIS5595_REG_IN_MAX(i)); | 642 | SIS5595_REG_IN_MAX(i)); |
725 | } | 643 | } |
726 | for (i = 0; i < 2; i++) { | 644 | for (i = 0; i < 2; i++) { |
727 | data->fan[i] = | 645 | data->fan[i] = |
728 | sis5595_read_value(client, SIS5595_REG_FAN(i)); | 646 | sis5595_read_value(data, SIS5595_REG_FAN(i)); |
729 | data->fan_min[i] = | 647 | data->fan_min[i] = |
730 | sis5595_read_value(client, | 648 | sis5595_read_value(data, |
731 | SIS5595_REG_FAN_MIN(i)); | 649 | SIS5595_REG_FAN_MIN(i)); |
732 | } | 650 | } |
733 | if (data->maxins == 3) { | 651 | if (data->maxins == 3) { |
734 | data->temp = | 652 | data->temp = |
735 | sis5595_read_value(client, SIS5595_REG_TEMP); | 653 | sis5595_read_value(data, SIS5595_REG_TEMP); |
736 | data->temp_over = | 654 | data->temp_over = |
737 | sis5595_read_value(client, SIS5595_REG_TEMP_OVER); | 655 | sis5595_read_value(data, SIS5595_REG_TEMP_OVER); |
738 | data->temp_hyst = | 656 | data->temp_hyst = |
739 | sis5595_read_value(client, SIS5595_REG_TEMP_HYST); | 657 | sis5595_read_value(data, SIS5595_REG_TEMP_HYST); |
740 | } | 658 | } |
741 | i = sis5595_read_value(client, SIS5595_REG_FANDIV); | 659 | i = sis5595_read_value(data, SIS5595_REG_FANDIV); |
742 | data->fan_div[0] = (i >> 4) & 0x03; | 660 | data->fan_div[0] = (i >> 4) & 0x03; |
743 | data->fan_div[1] = i >> 6; | 661 | data->fan_div[1] = i >> 6; |
744 | data->alarms = | 662 | data->alarms = |
745 | sis5595_read_value(client, SIS5595_REG_ALARM1) | | 663 | sis5595_read_value(data, SIS5595_REG_ALARM1) | |
746 | (sis5595_read_value(client, SIS5595_REG_ALARM2) << 8); | 664 | (sis5595_read_value(data, SIS5595_REG_ALARM2) << 8); |
747 | data->last_updated = jiffies; | 665 | data->last_updated = jiffies; |
748 | data->valid = 1; | 666 | data->valid = 1; |
749 | } | 667 | } |
@@ -774,10 +692,50 @@ static int blacklist[] __devinitdata = { | |||
774 | PCI_DEVICE_ID_SI_5598, | 692 | PCI_DEVICE_ID_SI_5598, |
775 | 0 }; | 693 | 0 }; |
776 | 694 | ||
695 | static int __devinit sis5595_device_add(unsigned short address) | ||
696 | { | ||
697 | struct resource res = { | ||
698 | .start = address, | ||
699 | .end = address + SIS5595_EXTENT - 1, | ||
700 | .name = "sis5595", | ||
701 | .flags = IORESOURCE_IO, | ||
702 | }; | ||
703 | int err; | ||
704 | |||
705 | pdev = platform_device_alloc("sis5595", address); | ||
706 | if (!pdev) { | ||
707 | err = -ENOMEM; | ||
708 | printk(KERN_ERR "sis5595: Device allocation failed\n"); | ||
709 | goto exit; | ||
710 | } | ||
711 | |||
712 | err = platform_device_add_resources(pdev, &res, 1); | ||
713 | if (err) { | ||
714 | printk(KERN_ERR "sis5595: Device resource addition failed " | ||
715 | "(%d)\n", err); | ||
716 | goto exit_device_put; | ||
717 | } | ||
718 | |||
719 | err = platform_device_add(pdev); | ||
720 | if (err) { | ||
721 | printk(KERN_ERR "sis5595: Device addition failed (%d)\n", | ||
722 | err); | ||
723 | goto exit_device_put; | ||
724 | } | ||
725 | |||
726 | return 0; | ||
727 | |||
728 | exit_device_put: | ||
729 | platform_device_put(pdev); | ||
730 | exit: | ||
731 | return err; | ||
732 | } | ||
733 | |||
777 | static int __devinit sis5595_pci_probe(struct pci_dev *dev, | 734 | static int __devinit sis5595_pci_probe(struct pci_dev *dev, |
778 | const struct pci_device_id *id) | 735 | const struct pci_device_id *id) |
779 | { | 736 | { |
780 | u16 val; | 737 | u16 address; |
738 | u8 enable; | ||
781 | int *i; | 739 | int *i; |
782 | 740 | ||
783 | for (i = blacklist; *i != 0; i++) { | 741 | for (i = blacklist; *i != 0; i++) { |
@@ -790,27 +748,68 @@ static int __devinit sis5595_pci_probe(struct pci_dev *dev, | |||
790 | } | 748 | } |
791 | } | 749 | } |
792 | 750 | ||
751 | force_addr &= ~(SIS5595_EXTENT - 1); | ||
752 | if (force_addr) { | ||
753 | dev_warn(&dev->dev, "Forcing ISA address 0x%x\n", force_addr); | ||
754 | pci_write_config_word(dev, SIS5595_BASE_REG, force_addr); | ||
755 | } | ||
756 | |||
793 | if (PCIBIOS_SUCCESSFUL != | 757 | if (PCIBIOS_SUCCESSFUL != |
794 | pci_read_config_word(dev, SIS5595_BASE_REG, &val)) | 758 | pci_read_config_word(dev, SIS5595_BASE_REG, &address)) { |
759 | dev_err(&dev->dev, "Failed to read ISA address\n"); | ||
795 | return -ENODEV; | 760 | return -ENODEV; |
761 | } | ||
796 | 762 | ||
797 | address = val & ~(SIS5595_EXTENT - 1); | 763 | address &= ~(SIS5595_EXTENT - 1); |
798 | if (address == 0 && force_addr == 0) { | 764 | if (!address) { |
799 | dev_err(&dev->dev, "Base address not set - upgrade BIOS or use force_addr=0xaddr\n"); | 765 | dev_err(&dev->dev, "Base address not set - upgrade BIOS or use force_addr=0xaddr\n"); |
800 | return -ENODEV; | 766 | return -ENODEV; |
801 | } | 767 | } |
768 | if (force_addr && address != force_addr) { | ||
769 | /* doesn't work for some chips? */ | ||
770 | dev_err(&dev->dev, "Failed to force ISA address\n"); | ||
771 | return -ENODEV; | ||
772 | } | ||
802 | 773 | ||
803 | s_bridge = pci_dev_get(dev); | 774 | if (PCIBIOS_SUCCESSFUL != |
804 | if (i2c_isa_add_driver(&sis5595_driver)) { | 775 | pci_read_config_byte(dev, SIS5595_ENABLE_REG, &enable)) { |
805 | pci_dev_put(s_bridge); | 776 | dev_err(&dev->dev, "Failed to read enable register\n"); |
806 | s_bridge = NULL; | 777 | return -ENODEV; |
778 | } | ||
779 | if (!(enable & 0x80)) { | ||
780 | if ((PCIBIOS_SUCCESSFUL != | ||
781 | pci_write_config_byte(dev, SIS5595_ENABLE_REG, | ||
782 | enable | 0x80)) | ||
783 | || (PCIBIOS_SUCCESSFUL != | ||
784 | pci_read_config_byte(dev, SIS5595_ENABLE_REG, &enable)) | ||
785 | || (!(enable & 0x80))) { | ||
786 | /* doesn't work for some chips! */ | ||
787 | dev_err(&dev->dev, "Failed to enable HWM device\n"); | ||
788 | return -ENODEV; | ||
789 | } | ||
807 | } | 790 | } |
808 | 791 | ||
792 | if (platform_driver_register(&sis5595_driver)) { | ||
793 | dev_dbg(&dev->dev, "Failed to register sis5595 driver\n"); | ||
794 | goto exit; | ||
795 | } | ||
796 | |||
797 | s_bridge = pci_dev_get(dev); | ||
798 | /* Sets global pdev as a side effect */ | ||
799 | if (sis5595_device_add(address)) | ||
800 | goto exit_unregister; | ||
801 | |||
809 | /* Always return failure here. This is to allow other drivers to bind | 802 | /* Always return failure here. This is to allow other drivers to bind |
810 | * to this pci device. We don't really want to have control over the | 803 | * to this pci device. We don't really want to have control over the |
811 | * pci device, we only wanted to read as few register values from it. | 804 | * pci device, we only wanted to read as few register values from it. |
812 | */ | 805 | */ |
813 | return -ENODEV; | 806 | return -ENODEV; |
807 | |||
808 | exit_unregister: | ||
809 | pci_dev_put(dev); | ||
810 | platform_driver_unregister(&sis5595_driver); | ||
811 | exit: | ||
812 | return -ENODEV; | ||
814 | } | 813 | } |
815 | 814 | ||
816 | static struct pci_driver sis5595_pci_driver = { | 815 | static struct pci_driver sis5595_pci_driver = { |
@@ -828,7 +827,8 @@ static void __exit sm_sis5595_exit(void) | |||
828 | { | 827 | { |
829 | pci_unregister_driver(&sis5595_pci_driver); | 828 | pci_unregister_driver(&sis5595_pci_driver); |
830 | if (s_bridge != NULL) { | 829 | if (s_bridge != NULL) { |
831 | i2c_isa_del_driver(&sis5595_driver); | 830 | platform_device_unregister(pdev); |
831 | platform_driver_unregister(&sis5595_driver); | ||
832 | pci_dev_put(s_bridge); | 832 | pci_dev_put(s_bridge); |
833 | s_bridge = NULL; | 833 | s_bridge = NULL; |
834 | } | 834 | } |
diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c index 943abbd95ab5..45266b30ce1d 100644 --- a/drivers/hwmon/smsc47b397.c +++ b/drivers/hwmon/smsc47b397.c | |||
@@ -174,6 +174,8 @@ static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3); | |||
174 | REG: count of 90kHz pulses / revolution */ | 174 | REG: count of 90kHz pulses / revolution */ |
175 | static int fan_from_reg(u16 reg) | 175 | static int fan_from_reg(u16 reg) |
176 | { | 176 | { |
177 | if (reg == 0 || reg == 0xffff) | ||
178 | return 0; | ||
177 | return 90000 * 60 / reg; | 179 | return 90000 * 60 / reg; |
178 | } | 180 | } |
179 | 181 | ||
@@ -333,7 +335,7 @@ static int __init smsc47b397_find(unsigned short *addr) | |||
333 | superio_enter(); | 335 | superio_enter(); |
334 | id = superio_inb(SUPERIO_REG_DEVID); | 336 | id = superio_inb(SUPERIO_REG_DEVID); |
335 | 337 | ||
336 | if ((id != 0x6f) && (id != 0x81)) { | 338 | if ((id != 0x6f) && (id != 0x81) && (id != 0x85)) { |
337 | superio_exit(); | 339 | superio_exit(); |
338 | return -ENODEV; | 340 | return -ENODEV; |
339 | } | 341 | } |
@@ -346,7 +348,8 @@ static int __init smsc47b397_find(unsigned short *addr) | |||
346 | 348 | ||
347 | printk(KERN_INFO DRVNAME ": found SMSC %s " | 349 | printk(KERN_INFO DRVNAME ": found SMSC %s " |
348 | "(base address 0x%04x, revision %u)\n", | 350 | "(base address 0x%04x, revision %u)\n", |
349 | id == 0x81 ? "SCH5307-NS" : "LPC47B397-NC", *addr, rev); | 351 | id == 0x81 ? "SCH5307-NS" : id == 0x85 ? "SCH5317" : |
352 | "LPC47B397-NC", *addr, rev); | ||
350 | 353 | ||
351 | superio_exit(); | 354 | superio_exit(); |
352 | return 0; | 355 | return 0; |
diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c index 1e21c8cc948f..1de2f2be8708 100644 --- a/drivers/hwmon/smsc47m1.c +++ b/drivers/hwmon/smsc47m1.c | |||
@@ -597,6 +597,7 @@ static int __devinit smsc47m1_probe(struct platform_device *pdev) | |||
597 | error_remove_files: | 597 | error_remove_files: |
598 | sysfs_remove_group(&dev->kobj, &smsc47m1_group); | 598 | sysfs_remove_group(&dev->kobj, &smsc47m1_group); |
599 | error_free: | 599 | error_free: |
600 | platform_set_drvdata(pdev, NULL); | ||
600 | kfree(data); | 601 | kfree(data); |
601 | error_release: | 602 | error_release: |
602 | release_region(res->start, SMSC_EXTENT); | 603 | release_region(res->start, SMSC_EXTENT); |
@@ -608,12 +609,12 @@ static int __devexit smsc47m1_remove(struct platform_device *pdev) | |||
608 | struct smsc47m1_data *data = platform_get_drvdata(pdev); | 609 | struct smsc47m1_data *data = platform_get_drvdata(pdev); |
609 | struct resource *res; | 610 | struct resource *res; |
610 | 611 | ||
611 | platform_set_drvdata(pdev, NULL); | ||
612 | hwmon_device_unregister(data->class_dev); | 612 | hwmon_device_unregister(data->class_dev); |
613 | sysfs_remove_group(&pdev->dev.kobj, &smsc47m1_group); | 613 | sysfs_remove_group(&pdev->dev.kobj, &smsc47m1_group); |
614 | 614 | ||
615 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | 615 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
616 | release_region(res->start, SMSC_EXTENT); | 616 | release_region(res->start, SMSC_EXTENT); |
617 | platform_set_drvdata(pdev, NULL); | ||
617 | kfree(data); | 618 | kfree(data); |
618 | 619 | ||
619 | return 0; | 620 | return 0; |
@@ -693,15 +694,12 @@ static int __init smsc47m1_device_add(unsigned short address, | |||
693 | goto exit_device_put; | 694 | goto exit_device_put; |
694 | } | 695 | } |
695 | 696 | ||
696 | pdev->dev.platform_data = kmalloc(sizeof(struct smsc47m1_sio_data), | 697 | err = platform_device_add_data(pdev, sio_data, |
697 | GFP_KERNEL); | 698 | sizeof(struct smsc47m1_sio_data)); |
698 | if (!pdev->dev.platform_data) { | 699 | if (err) { |
699 | err = -ENOMEM; | ||
700 | printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); | 700 | printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); |
701 | goto exit_device_put; | 701 | goto exit_device_put; |
702 | } | 702 | } |
703 | memcpy(pdev->dev.platform_data, sio_data, | ||
704 | sizeof(struct smsc47m1_sio_data)); | ||
705 | 703 | ||
706 | err = platform_device_add(pdev); | 704 | err = platform_device_add(pdev); |
707 | if (err) { | 705 | if (err) { |
diff --git a/drivers/hwmon/smsc47m192.c b/drivers/hwmon/smsc47m192.c index a012f396f354..d3a3ba04cb0f 100644 --- a/drivers/hwmon/smsc47m192.c +++ b/drivers/hwmon/smsc47m192.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/hwmon-vid.h> | 31 | #include <linux/hwmon-vid.h> |
32 | #include <linux/err.h> | 32 | #include <linux/err.h> |
33 | #include <linux/sysfs.h> | 33 | #include <linux/sysfs.h> |
34 | #include <linux/mutex.h> | ||
34 | 35 | ||
35 | /* Addresses to scan */ | 36 | /* Addresses to scan */ |
36 | static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; | 37 | static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; |
@@ -97,7 +98,7 @@ static inline int TEMP_FROM_REG(s8 val) | |||
97 | struct smsc47m192_data { | 98 | struct smsc47m192_data { |
98 | struct i2c_client client; | 99 | struct i2c_client client; |
99 | struct class_device *class_dev; | 100 | struct class_device *class_dev; |
100 | struct semaphore update_lock; | 101 | struct mutex update_lock; |
101 | char valid; /* !=0 if following fields are valid */ | 102 | char valid; /* !=0 if following fields are valid */ |
102 | unsigned long last_updated; /* In jiffies */ | 103 | unsigned long last_updated; /* In jiffies */ |
103 | 104 | ||
@@ -164,11 +165,11 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | |||
164 | struct smsc47m192_data *data = i2c_get_clientdata(client); | 165 | struct smsc47m192_data *data = i2c_get_clientdata(client); |
165 | unsigned long val = simple_strtoul(buf, NULL, 10); | 166 | unsigned long val = simple_strtoul(buf, NULL, 10); |
166 | 167 | ||
167 | down(&data->update_lock); | 168 | mutex_lock(&data->update_lock); |
168 | data->in_min[nr] = IN_TO_REG(val, nr); | 169 | data->in_min[nr] = IN_TO_REG(val, nr); |
169 | i2c_smbus_write_byte_data(client, SMSC47M192_REG_IN_MIN(nr), | 170 | i2c_smbus_write_byte_data(client, SMSC47M192_REG_IN_MIN(nr), |
170 | data->in_min[nr]); | 171 | data->in_min[nr]); |
171 | up(&data->update_lock); | 172 | mutex_unlock(&data->update_lock); |
172 | return count; | 173 | return count; |
173 | } | 174 | } |
174 | 175 | ||
@@ -181,11 +182,11 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | |||
181 | struct smsc47m192_data *data = i2c_get_clientdata(client); | 182 | struct smsc47m192_data *data = i2c_get_clientdata(client); |
182 | unsigned long val = simple_strtoul(buf, NULL, 10); | 183 | unsigned long val = simple_strtoul(buf, NULL, 10); |
183 | 184 | ||
184 | down(&data->update_lock); | 185 | mutex_lock(&data->update_lock); |
185 | data->in_max[nr] = IN_TO_REG(val, nr); | 186 | data->in_max[nr] = IN_TO_REG(val, nr); |
186 | i2c_smbus_write_byte_data(client, SMSC47M192_REG_IN_MAX(nr), | 187 | i2c_smbus_write_byte_data(client, SMSC47M192_REG_IN_MAX(nr), |
187 | data->in_max[nr]); | 188 | data->in_max[nr]); |
188 | up(&data->update_lock); | 189 | mutex_unlock(&data->update_lock); |
189 | return count; | 190 | return count; |
190 | } | 191 | } |
191 | 192 | ||
@@ -243,11 +244,11 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
243 | struct smsc47m192_data *data = i2c_get_clientdata(client); | 244 | struct smsc47m192_data *data = i2c_get_clientdata(client); |
244 | long val = simple_strtol(buf, NULL, 10); | 245 | long val = simple_strtol(buf, NULL, 10); |
245 | 246 | ||
246 | down(&data->update_lock); | 247 | mutex_lock(&data->update_lock); |
247 | data->temp_min[nr] = TEMP_TO_REG(val); | 248 | data->temp_min[nr] = TEMP_TO_REG(val); |
248 | i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_MIN[nr], | 249 | i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_MIN[nr], |
249 | data->temp_min[nr]); | 250 | data->temp_min[nr]); |
250 | up(&data->update_lock); | 251 | mutex_unlock(&data->update_lock); |
251 | return count; | 252 | return count; |
252 | } | 253 | } |
253 | 254 | ||
@@ -260,11 +261,11 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
260 | struct smsc47m192_data *data = i2c_get_clientdata(client); | 261 | struct smsc47m192_data *data = i2c_get_clientdata(client); |
261 | long val = simple_strtol(buf, NULL, 10); | 262 | long val = simple_strtol(buf, NULL, 10); |
262 | 263 | ||
263 | down(&data->update_lock); | 264 | mutex_lock(&data->update_lock); |
264 | data->temp_max[nr] = TEMP_TO_REG(val); | 265 | data->temp_max[nr] = TEMP_TO_REG(val); |
265 | i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_MAX[nr], | 266 | i2c_smbus_write_byte_data(client, SMSC47M192_REG_TEMP_MAX[nr], |
266 | data->temp_max[nr]); | 267 | data->temp_max[nr]); |
267 | up(&data->update_lock); | 268 | mutex_unlock(&data->update_lock); |
268 | return count; | 269 | return count; |
269 | } | 270 | } |
270 | 271 | ||
@@ -287,7 +288,7 @@ static ssize_t set_temp_offset(struct device *dev, struct device_attribute | |||
287 | u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR); | 288 | u8 sfr = i2c_smbus_read_byte_data(client, SMSC47M192_REG_SFR); |
288 | long val = simple_strtol(buf, NULL, 10); | 289 | long val = simple_strtol(buf, NULL, 10); |
289 | 290 | ||
290 | down(&data->update_lock); | 291 | mutex_lock(&data->update_lock); |
291 | data->temp_offset[nr] = TEMP_TO_REG(val); | 292 | data->temp_offset[nr] = TEMP_TO_REG(val); |
292 | if (nr>1) | 293 | if (nr>1) |
293 | i2c_smbus_write_byte_data(client, | 294 | i2c_smbus_write_byte_data(client, |
@@ -303,7 +304,7 @@ static ssize_t set_temp_offset(struct device *dev, struct device_attribute | |||
303 | } else if ((sfr & 0x10) == (nr==0 ? 0x10 : 0)) | 304 | } else if ((sfr & 0x10) == (nr==0 ? 0x10 : 0)) |
304 | i2c_smbus_write_byte_data(client, | 305 | i2c_smbus_write_byte_data(client, |
305 | SMSC47M192_REG_TEMP_OFFSET(nr), 0); | 306 | SMSC47M192_REG_TEMP_OFFSET(nr), 0); |
306 | up(&data->update_lock); | 307 | mutex_unlock(&data->update_lock); |
307 | return count; | 308 | return count; |
308 | } | 309 | } |
309 | 310 | ||
@@ -360,8 +361,8 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, | |||
360 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 0x0010); | 361 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 0x0010); |
361 | static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 0x0020); | 362 | static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 0x0020); |
362 | static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 0x0040); | 363 | static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 0x0040); |
363 | static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 0x4000); | 364 | static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 0x4000); |
364 | static SENSOR_DEVICE_ATTR(temp3_input_fault, S_IRUGO, show_alarm, NULL, 0x8000); | 365 | static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 0x8000); |
365 | static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0x0001); | 366 | static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0x0001); |
366 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 0x0002); | 367 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 0x0002); |
367 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 0x0004); | 368 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 0x0004); |
@@ -411,13 +412,13 @@ static struct attribute *smsc47m192_attributes[] = { | |||
411 | &sensor_dev_attr_temp2_min.dev_attr.attr, | 412 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
412 | &sensor_dev_attr_temp2_offset.dev_attr.attr, | 413 | &sensor_dev_attr_temp2_offset.dev_attr.attr, |
413 | &sensor_dev_attr_temp2_alarm.dev_attr.attr, | 414 | &sensor_dev_attr_temp2_alarm.dev_attr.attr, |
414 | &sensor_dev_attr_temp2_input_fault.dev_attr.attr, | 415 | &sensor_dev_attr_temp2_fault.dev_attr.attr, |
415 | &sensor_dev_attr_temp3_input.dev_attr.attr, | 416 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
416 | &sensor_dev_attr_temp3_max.dev_attr.attr, | 417 | &sensor_dev_attr_temp3_max.dev_attr.attr, |
417 | &sensor_dev_attr_temp3_min.dev_attr.attr, | 418 | &sensor_dev_attr_temp3_min.dev_attr.attr, |
418 | &sensor_dev_attr_temp3_offset.dev_attr.attr, | 419 | &sensor_dev_attr_temp3_offset.dev_attr.attr, |
419 | &sensor_dev_attr_temp3_alarm.dev_attr.attr, | 420 | &sensor_dev_attr_temp3_alarm.dev_attr.attr, |
420 | &sensor_dev_attr_temp3_input_fault.dev_attr.attr, | 421 | &sensor_dev_attr_temp3_fault.dev_attr.attr, |
421 | 422 | ||
422 | &dev_attr_cpu0_vid.attr, | 423 | &dev_attr_cpu0_vid.attr, |
423 | &dev_attr_vrm.attr, | 424 | &dev_attr_vrm.attr, |
@@ -531,7 +532,7 @@ static int smsc47m192_detect(struct i2c_adapter *adapter, int address, | |||
531 | /* Fill in the remaining client fields and put into the global list */ | 532 | /* Fill in the remaining client fields and put into the global list */ |
532 | strlcpy(client->name, "smsc47m192", I2C_NAME_SIZE); | 533 | strlcpy(client->name, "smsc47m192", I2C_NAME_SIZE); |
533 | data->vrm = vid_which_vrm(); | 534 | data->vrm = vid_which_vrm(); |
534 | init_MUTEX(&data->update_lock); | 535 | mutex_init(&data->update_lock); |
535 | 536 | ||
536 | /* Tell the I2C layer a new client has arrived */ | 537 | /* Tell the I2C layer a new client has arrived */ |
537 | if ((err = i2c_attach_client(client))) | 538 | if ((err = i2c_attach_client(client))) |
@@ -594,7 +595,7 @@ static struct smsc47m192_data *smsc47m192_update_device(struct device *dev) | |||
594 | struct smsc47m192_data *data = i2c_get_clientdata(client); | 595 | struct smsc47m192_data *data = i2c_get_clientdata(client); |
595 | int i, config; | 596 | int i, config; |
596 | 597 | ||
597 | down(&data->update_lock); | 598 | mutex_lock(&data->update_lock); |
598 | 599 | ||
599 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | 600 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
600 | || !data->valid) { | 601 | || !data->valid) { |
@@ -645,7 +646,7 @@ static struct smsc47m192_data *smsc47m192_update_device(struct device *dev) | |||
645 | data->valid = 1; | 646 | data->valid = 1; |
646 | } | 647 | } |
647 | 648 | ||
648 | up(&data->update_lock); | 649 | mutex_unlock(&data->update_lock); |
649 | 650 | ||
650 | return data; | 651 | return data; |
651 | } | 652 | } |
diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c index 9a440c8cc520..24a6851491d0 100644 --- a/drivers/hwmon/via686a.c +++ b/drivers/hwmon/via686a.c | |||
@@ -34,9 +34,9 @@ | |||
34 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
35 | #include <linux/pci.h> | 35 | #include <linux/pci.h> |
36 | #include <linux/jiffies.h> | 36 | #include <linux/jiffies.h> |
37 | #include <linux/i2c.h> | 37 | #include <linux/platform_device.h> |
38 | #include <linux/i2c-isa.h> | ||
39 | #include <linux/hwmon.h> | 38 | #include <linux/hwmon.h> |
39 | #include <linux/hwmon-sysfs.h> | ||
40 | #include <linux/err.h> | 40 | #include <linux/err.h> |
41 | #include <linux/init.h> | 41 | #include <linux/init.h> |
42 | #include <linux/mutex.h> | 42 | #include <linux/mutex.h> |
@@ -51,10 +51,7 @@ module_param(force_addr, ushort, 0); | |||
51 | MODULE_PARM_DESC(force_addr, | 51 | MODULE_PARM_DESC(force_addr, |
52 | "Initialize the base address of the sensors"); | 52 | "Initialize the base address of the sensors"); |
53 | 53 | ||
54 | /* Device address | 54 | static struct platform_device *pdev; |
55 | Note that we can't determine the ISA address until we have initialized | ||
56 | our module */ | ||
57 | static unsigned short address; | ||
58 | 55 | ||
59 | /* | 56 | /* |
60 | The Via 686a southbridge has a LM78-like chip integrated on the same IC. | 57 | The Via 686a southbridge has a LM78-like chip integrated on the same IC. |
@@ -295,7 +292,8 @@ static inline long TEMP_FROM_REG10(u16 val) | |||
295 | /* For each registered chip, we need to keep some data in memory. | 292 | /* For each registered chip, we need to keep some data in memory. |
296 | The structure is dynamically allocated. */ | 293 | The structure is dynamically allocated. */ |
297 | struct via686a_data { | 294 | struct via686a_data { |
298 | struct i2c_client client; | 295 | unsigned short addr; |
296 | const char *name; | ||
299 | struct class_device *class_dev; | 297 | struct class_device *class_dev; |
300 | struct mutex update_lock; | 298 | struct mutex update_lock; |
301 | char valid; /* !=0 if following fields are valid */ | 299 | char valid; /* !=0 if following fields are valid */ |
@@ -315,98 +313,85 @@ struct via686a_data { | |||
315 | 313 | ||
316 | static struct pci_dev *s_bridge; /* pointer to the (only) via686a */ | 314 | static struct pci_dev *s_bridge; /* pointer to the (only) via686a */ |
317 | 315 | ||
318 | static int via686a_detect(struct i2c_adapter *adapter); | 316 | static int via686a_probe(struct platform_device *pdev); |
319 | static int via686a_detach_client(struct i2c_client *client); | 317 | static int via686a_remove(struct platform_device *pdev); |
320 | 318 | ||
321 | static inline int via686a_read_value(struct i2c_client *client, u8 reg) | 319 | static inline int via686a_read_value(struct via686a_data *data, u8 reg) |
322 | { | 320 | { |
323 | return (inb_p(client->addr + reg)); | 321 | return inb_p(data->addr + reg); |
324 | } | 322 | } |
325 | 323 | ||
326 | static inline void via686a_write_value(struct i2c_client *client, u8 reg, | 324 | static inline void via686a_write_value(struct via686a_data *data, u8 reg, |
327 | u8 value) | 325 | u8 value) |
328 | { | 326 | { |
329 | outb_p(value, client->addr + reg); | 327 | outb_p(value, data->addr + reg); |
330 | } | 328 | } |
331 | 329 | ||
332 | static struct via686a_data *via686a_update_device(struct device *dev); | 330 | static struct via686a_data *via686a_update_device(struct device *dev); |
333 | static void via686a_init_client(struct i2c_client *client); | 331 | static void via686a_init_device(struct via686a_data *data); |
334 | 332 | ||
335 | /* following are the sysfs callback functions */ | 333 | /* following are the sysfs callback functions */ |
336 | 334 | ||
337 | /* 7 voltage sensors */ | 335 | /* 7 voltage sensors */ |
338 | static ssize_t show_in(struct device *dev, char *buf, int nr) { | 336 | static ssize_t show_in(struct device *dev, struct device_attribute *da, |
337 | char *buf) { | ||
339 | struct via686a_data *data = via686a_update_device(dev); | 338 | struct via686a_data *data = via686a_update_device(dev); |
339 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
340 | int nr = attr->index; | ||
340 | return sprintf(buf, "%ld\n", IN_FROM_REG(data->in[nr], nr)); | 341 | return sprintf(buf, "%ld\n", IN_FROM_REG(data->in[nr], nr)); |
341 | } | 342 | } |
342 | 343 | ||
343 | static ssize_t show_in_min(struct device *dev, char *buf, int nr) { | 344 | static ssize_t show_in_min(struct device *dev, struct device_attribute *da, |
345 | char *buf) { | ||
344 | struct via686a_data *data = via686a_update_device(dev); | 346 | struct via686a_data *data = via686a_update_device(dev); |
347 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
348 | int nr = attr->index; | ||
345 | return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_min[nr], nr)); | 349 | return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_min[nr], nr)); |
346 | } | 350 | } |
347 | 351 | ||
348 | static ssize_t show_in_max(struct device *dev, char *buf, int nr) { | 352 | static ssize_t show_in_max(struct device *dev, struct device_attribute *da, |
353 | char *buf) { | ||
349 | struct via686a_data *data = via686a_update_device(dev); | 354 | struct via686a_data *data = via686a_update_device(dev); |
355 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
356 | int nr = attr->index; | ||
350 | return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_max[nr], nr)); | 357 | return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_max[nr], nr)); |
351 | } | 358 | } |
352 | 359 | ||
353 | static ssize_t set_in_min(struct device *dev, const char *buf, | 360 | static ssize_t set_in_min(struct device *dev, struct device_attribute *da, |
354 | size_t count, int nr) { | 361 | const char *buf, size_t count) { |
355 | struct i2c_client *client = to_i2c_client(dev); | 362 | struct via686a_data *data = dev_get_drvdata(dev); |
356 | struct via686a_data *data = i2c_get_clientdata(client); | 363 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
364 | int nr = attr->index; | ||
357 | unsigned long val = simple_strtoul(buf, NULL, 10); | 365 | unsigned long val = simple_strtoul(buf, NULL, 10); |
358 | 366 | ||
359 | mutex_lock(&data->update_lock); | 367 | mutex_lock(&data->update_lock); |
360 | data->in_min[nr] = IN_TO_REG(val, nr); | 368 | data->in_min[nr] = IN_TO_REG(val, nr); |
361 | via686a_write_value(client, VIA686A_REG_IN_MIN(nr), | 369 | via686a_write_value(data, VIA686A_REG_IN_MIN(nr), |
362 | data->in_min[nr]); | 370 | data->in_min[nr]); |
363 | mutex_unlock(&data->update_lock); | 371 | mutex_unlock(&data->update_lock); |
364 | return count; | 372 | return count; |
365 | } | 373 | } |
366 | static ssize_t set_in_max(struct device *dev, const char *buf, | 374 | static ssize_t set_in_max(struct device *dev, struct device_attribute *da, |
367 | size_t count, int nr) { | 375 | const char *buf, size_t count) { |
368 | struct i2c_client *client = to_i2c_client(dev); | 376 | struct via686a_data *data = dev_get_drvdata(dev); |
369 | struct via686a_data *data = i2c_get_clientdata(client); | 377 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
378 | int nr = attr->index; | ||
370 | unsigned long val = simple_strtoul(buf, NULL, 10); | 379 | unsigned long val = simple_strtoul(buf, NULL, 10); |
371 | 380 | ||
372 | mutex_lock(&data->update_lock); | 381 | mutex_lock(&data->update_lock); |
373 | data->in_max[nr] = IN_TO_REG(val, nr); | 382 | data->in_max[nr] = IN_TO_REG(val, nr); |
374 | via686a_write_value(client, VIA686A_REG_IN_MAX(nr), | 383 | via686a_write_value(data, VIA686A_REG_IN_MAX(nr), |
375 | data->in_max[nr]); | 384 | data->in_max[nr]); |
376 | mutex_unlock(&data->update_lock); | 385 | mutex_unlock(&data->update_lock); |
377 | return count; | 386 | return count; |
378 | } | 387 | } |
379 | #define show_in_offset(offset) \ | 388 | #define show_in_offset(offset) \ |
380 | static ssize_t \ | 389 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
381 | show_in##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | 390 | show_in, NULL, offset); \ |
382 | { \ | 391 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ |
383 | return show_in(dev, buf, offset); \ | 392 | show_in_min, set_in_min, offset); \ |
384 | } \ | 393 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ |
385 | static ssize_t \ | 394 | show_in_max, set_in_max, offset); |
386 | show_in##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
387 | { \ | ||
388 | return show_in_min(dev, buf, offset); \ | ||
389 | } \ | ||
390 | static ssize_t \ | ||
391 | show_in##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
392 | { \ | ||
393 | return show_in_max(dev, buf, offset); \ | ||
394 | } \ | ||
395 | static ssize_t set_in##offset##_min (struct device *dev, struct device_attribute *attr, \ | ||
396 | const char *buf, size_t count) \ | ||
397 | { \ | ||
398 | return set_in_min(dev, buf, count, offset); \ | ||
399 | } \ | ||
400 | static ssize_t set_in##offset##_max (struct device *dev, struct device_attribute *attr, \ | ||
401 | const char *buf, size_t count) \ | ||
402 | { \ | ||
403 | return set_in_max(dev, buf, count, offset); \ | ||
404 | } \ | ||
405 | static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL);\ | ||
406 | static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ | ||
407 | show_in##offset##_min, set_in##offset##_min); \ | ||
408 | static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ | ||
409 | show_in##offset##_max, set_in##offset##_max); | ||
410 | 395 | ||
411 | show_in_offset(0); | 396 | show_in_offset(0); |
412 | show_in_offset(1); | 397 | show_in_offset(1); |
@@ -415,150 +400,128 @@ show_in_offset(3); | |||
415 | show_in_offset(4); | 400 | show_in_offset(4); |
416 | 401 | ||
417 | /* 3 temperatures */ | 402 | /* 3 temperatures */ |
418 | static ssize_t show_temp(struct device *dev, char *buf, int nr) { | 403 | static ssize_t show_temp(struct device *dev, struct device_attribute *da, |
404 | char *buf) { | ||
419 | struct via686a_data *data = via686a_update_device(dev); | 405 | struct via686a_data *data = via686a_update_device(dev); |
406 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
407 | int nr = attr->index; | ||
420 | return sprintf(buf, "%ld\n", TEMP_FROM_REG10(data->temp[nr])); | 408 | return sprintf(buf, "%ld\n", TEMP_FROM_REG10(data->temp[nr])); |
421 | } | 409 | } |
422 | static ssize_t show_temp_over(struct device *dev, char *buf, int nr) { | 410 | static ssize_t show_temp_over(struct device *dev, struct device_attribute *da, |
411 | char *buf) { | ||
423 | struct via686a_data *data = via686a_update_device(dev); | 412 | struct via686a_data *data = via686a_update_device(dev); |
413 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
414 | int nr = attr->index; | ||
424 | return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_over[nr])); | 415 | return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_over[nr])); |
425 | } | 416 | } |
426 | static ssize_t show_temp_hyst(struct device *dev, char *buf, int nr) { | 417 | static ssize_t show_temp_hyst(struct device *dev, struct device_attribute *da, |
418 | char *buf) { | ||
427 | struct via686a_data *data = via686a_update_device(dev); | 419 | struct via686a_data *data = via686a_update_device(dev); |
420 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
421 | int nr = attr->index; | ||
428 | return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_hyst[nr])); | 422 | return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_hyst[nr])); |
429 | } | 423 | } |
430 | static ssize_t set_temp_over(struct device *dev, const char *buf, | 424 | static ssize_t set_temp_over(struct device *dev, struct device_attribute *da, |
431 | size_t count, int nr) { | 425 | const char *buf, size_t count) { |
432 | struct i2c_client *client = to_i2c_client(dev); | 426 | struct via686a_data *data = dev_get_drvdata(dev); |
433 | struct via686a_data *data = i2c_get_clientdata(client); | 427 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
428 | int nr = attr->index; | ||
434 | int val = simple_strtol(buf, NULL, 10); | 429 | int val = simple_strtol(buf, NULL, 10); |
435 | 430 | ||
436 | mutex_lock(&data->update_lock); | 431 | mutex_lock(&data->update_lock); |
437 | data->temp_over[nr] = TEMP_TO_REG(val); | 432 | data->temp_over[nr] = TEMP_TO_REG(val); |
438 | via686a_write_value(client, VIA686A_REG_TEMP_OVER[nr], | 433 | via686a_write_value(data, VIA686A_REG_TEMP_OVER[nr], |
439 | data->temp_over[nr]); | 434 | data->temp_over[nr]); |
440 | mutex_unlock(&data->update_lock); | 435 | mutex_unlock(&data->update_lock); |
441 | return count; | 436 | return count; |
442 | } | 437 | } |
443 | static ssize_t set_temp_hyst(struct device *dev, const char *buf, | 438 | static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *da, |
444 | size_t count, int nr) { | 439 | const char *buf, size_t count) { |
445 | struct i2c_client *client = to_i2c_client(dev); | 440 | struct via686a_data *data = dev_get_drvdata(dev); |
446 | struct via686a_data *data = i2c_get_clientdata(client); | 441 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
442 | int nr = attr->index; | ||
447 | int val = simple_strtol(buf, NULL, 10); | 443 | int val = simple_strtol(buf, NULL, 10); |
448 | 444 | ||
449 | mutex_lock(&data->update_lock); | 445 | mutex_lock(&data->update_lock); |
450 | data->temp_hyst[nr] = TEMP_TO_REG(val); | 446 | data->temp_hyst[nr] = TEMP_TO_REG(val); |
451 | via686a_write_value(client, VIA686A_REG_TEMP_HYST[nr], | 447 | via686a_write_value(data, VIA686A_REG_TEMP_HYST[nr], |
452 | data->temp_hyst[nr]); | 448 | data->temp_hyst[nr]); |
453 | mutex_unlock(&data->update_lock); | 449 | mutex_unlock(&data->update_lock); |
454 | return count; | 450 | return count; |
455 | } | 451 | } |
456 | #define show_temp_offset(offset) \ | 452 | #define show_temp_offset(offset) \ |
457 | static ssize_t show_temp_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | 453 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ |
458 | { \ | 454 | show_temp, NULL, offset - 1); \ |
459 | return show_temp(dev, buf, offset - 1); \ | 455 | static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ |
460 | } \ | 456 | show_temp_over, set_temp_over, offset - 1); \ |
461 | static ssize_t \ | 457 | static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \ |
462 | show_temp_##offset##_over (struct device *dev, struct device_attribute *attr, char *buf) \ | 458 | show_temp_hyst, set_temp_hyst, offset - 1); |
463 | { \ | ||
464 | return show_temp_over(dev, buf, offset - 1); \ | ||
465 | } \ | ||
466 | static ssize_t \ | ||
467 | show_temp_##offset##_hyst (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
468 | { \ | ||
469 | return show_temp_hyst(dev, buf, offset - 1); \ | ||
470 | } \ | ||
471 | static ssize_t set_temp_##offset##_over (struct device *dev, struct device_attribute *attr, \ | ||
472 | const char *buf, size_t count) \ | ||
473 | { \ | ||
474 | return set_temp_over(dev, buf, count, offset - 1); \ | ||
475 | } \ | ||
476 | static ssize_t set_temp_##offset##_hyst (struct device *dev, struct device_attribute *attr, \ | ||
477 | const char *buf, size_t count) \ | ||
478 | { \ | ||
479 | return set_temp_hyst(dev, buf, count, offset - 1); \ | ||
480 | } \ | ||
481 | static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL);\ | ||
482 | static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ | ||
483 | show_temp_##offset##_over, set_temp_##offset##_over); \ | ||
484 | static DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \ | ||
485 | show_temp_##offset##_hyst, set_temp_##offset##_hyst); | ||
486 | 459 | ||
487 | show_temp_offset(1); | 460 | show_temp_offset(1); |
488 | show_temp_offset(2); | 461 | show_temp_offset(2); |
489 | show_temp_offset(3); | 462 | show_temp_offset(3); |
490 | 463 | ||
491 | /* 2 Fans */ | 464 | /* 2 Fans */ |
492 | static ssize_t show_fan(struct device *dev, char *buf, int nr) { | 465 | static ssize_t show_fan(struct device *dev, struct device_attribute *da, |
466 | char *buf) { | ||
493 | struct via686a_data *data = via686a_update_device(dev); | 467 | struct via686a_data *data = via686a_update_device(dev); |
468 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
469 | int nr = attr->index; | ||
494 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], | 470 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], |
495 | DIV_FROM_REG(data->fan_div[nr])) ); | 471 | DIV_FROM_REG(data->fan_div[nr])) ); |
496 | } | 472 | } |
497 | static ssize_t show_fan_min(struct device *dev, char *buf, int nr) { | 473 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *da, |
474 | char *buf) { | ||
498 | struct via686a_data *data = via686a_update_device(dev); | 475 | struct via686a_data *data = via686a_update_device(dev); |
476 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
477 | int nr = attr->index; | ||
499 | return sprintf(buf, "%d\n", | 478 | return sprintf(buf, "%d\n", |
500 | FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])) ); | 479 | FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])) ); |
501 | } | 480 | } |
502 | static ssize_t show_fan_div(struct device *dev, char *buf, int nr) { | 481 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *da, |
482 | char *buf) { | ||
503 | struct via686a_data *data = via686a_update_device(dev); | 483 | struct via686a_data *data = via686a_update_device(dev); |
484 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | ||
485 | int nr = attr->index; | ||
504 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); | 486 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); |
505 | } | 487 | } |
506 | static ssize_t set_fan_min(struct device *dev, const char *buf, | 488 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *da, |
507 | size_t count, int nr) { | 489 | const char *buf, size_t count) { |
508 | struct i2c_client *client = to_i2c_client(dev); | 490 | struct via686a_data *data = dev_get_drvdata(dev); |
509 | struct via686a_data *data = i2c_get_clientdata(client); | 491 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
492 | int nr = attr->index; | ||
510 | int val = simple_strtol(buf, NULL, 10); | 493 | int val = simple_strtol(buf, NULL, 10); |
511 | 494 | ||
512 | mutex_lock(&data->update_lock); | 495 | mutex_lock(&data->update_lock); |
513 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); | 496 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
514 | via686a_write_value(client, VIA686A_REG_FAN_MIN(nr+1), data->fan_min[nr]); | 497 | via686a_write_value(data, VIA686A_REG_FAN_MIN(nr+1), data->fan_min[nr]); |
515 | mutex_unlock(&data->update_lock); | 498 | mutex_unlock(&data->update_lock); |
516 | return count; | 499 | return count; |
517 | } | 500 | } |
518 | static ssize_t set_fan_div(struct device *dev, const char *buf, | 501 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *da, |
519 | size_t count, int nr) { | 502 | const char *buf, size_t count) { |
520 | struct i2c_client *client = to_i2c_client(dev); | 503 | struct via686a_data *data = dev_get_drvdata(dev); |
521 | struct via686a_data *data = i2c_get_clientdata(client); | 504 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
505 | int nr = attr->index; | ||
522 | int val = simple_strtol(buf, NULL, 10); | 506 | int val = simple_strtol(buf, NULL, 10); |
523 | int old; | 507 | int old; |
524 | 508 | ||
525 | mutex_lock(&data->update_lock); | 509 | mutex_lock(&data->update_lock); |
526 | old = via686a_read_value(client, VIA686A_REG_FANDIV); | 510 | old = via686a_read_value(data, VIA686A_REG_FANDIV); |
527 | data->fan_div[nr] = DIV_TO_REG(val); | 511 | data->fan_div[nr] = DIV_TO_REG(val); |
528 | old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4); | 512 | old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4); |
529 | via686a_write_value(client, VIA686A_REG_FANDIV, old); | 513 | via686a_write_value(data, VIA686A_REG_FANDIV, old); |
530 | mutex_unlock(&data->update_lock); | 514 | mutex_unlock(&data->update_lock); |
531 | return count; | 515 | return count; |
532 | } | 516 | } |
533 | 517 | ||
534 | #define show_fan_offset(offset) \ | 518 | #define show_fan_offset(offset) \ |
535 | static ssize_t show_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ | 519 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ |
536 | { \ | 520 | show_fan, NULL, offset - 1); \ |
537 | return show_fan(dev, buf, offset - 1); \ | 521 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
538 | } \ | 522 | show_fan_min, set_fan_min, offset - 1); \ |
539 | static ssize_t show_fan_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ | 523 | static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ |
540 | { \ | 524 | show_fan_div, set_fan_div, offset - 1); |
541 | return show_fan_min(dev, buf, offset - 1); \ | ||
542 | } \ | ||
543 | static ssize_t show_fan_##offset##_div (struct device *dev, struct device_attribute *attr, char *buf) \ | ||
544 | { \ | ||
545 | return show_fan_div(dev, buf, offset - 1); \ | ||
546 | } \ | ||
547 | static ssize_t set_fan_##offset##_min (struct device *dev, struct device_attribute *attr, \ | ||
548 | const char *buf, size_t count) \ | ||
549 | { \ | ||
550 | return set_fan_min(dev, buf, count, offset - 1); \ | ||
551 | } \ | ||
552 | static ssize_t set_fan_##offset##_div (struct device *dev, struct device_attribute *attr, \ | ||
553 | const char *buf, size_t count) \ | ||
554 | { \ | ||
555 | return set_fan_div(dev, buf, count, offset - 1); \ | ||
556 | } \ | ||
557 | static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL);\ | ||
558 | static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ | ||
559 | show_fan_##offset##_min, set_fan_##offset##_min); \ | ||
560 | static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ | ||
561 | show_fan_##offset##_div, set_fan_##offset##_div); | ||
562 | 525 | ||
563 | show_fan_offset(1); | 526 | show_fan_offset(1); |
564 | show_fan_offset(2); | 527 | show_fan_offset(2); |
@@ -570,41 +533,50 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch | |||
570 | } | 533 | } |
571 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 534 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
572 | 535 | ||
536 | static ssize_t show_name(struct device *dev, struct device_attribute | ||
537 | *devattr, char *buf) | ||
538 | { | ||
539 | struct via686a_data *data = dev_get_drvdata(dev); | ||
540 | return sprintf(buf, "%s\n", data->name); | ||
541 | } | ||
542 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
543 | |||
573 | static struct attribute *via686a_attributes[] = { | 544 | static struct attribute *via686a_attributes[] = { |
574 | &dev_attr_in0_input.attr, | 545 | &sensor_dev_attr_in0_input.dev_attr.attr, |
575 | &dev_attr_in1_input.attr, | 546 | &sensor_dev_attr_in1_input.dev_attr.attr, |
576 | &dev_attr_in2_input.attr, | 547 | &sensor_dev_attr_in2_input.dev_attr.attr, |
577 | &dev_attr_in3_input.attr, | 548 | &sensor_dev_attr_in3_input.dev_attr.attr, |
578 | &dev_attr_in4_input.attr, | 549 | &sensor_dev_attr_in4_input.dev_attr.attr, |
579 | &dev_attr_in0_min.attr, | 550 | &sensor_dev_attr_in0_min.dev_attr.attr, |
580 | &dev_attr_in1_min.attr, | 551 | &sensor_dev_attr_in1_min.dev_attr.attr, |
581 | &dev_attr_in2_min.attr, | 552 | &sensor_dev_attr_in2_min.dev_attr.attr, |
582 | &dev_attr_in3_min.attr, | 553 | &sensor_dev_attr_in3_min.dev_attr.attr, |
583 | &dev_attr_in4_min.attr, | 554 | &sensor_dev_attr_in4_min.dev_attr.attr, |
584 | &dev_attr_in0_max.attr, | 555 | &sensor_dev_attr_in0_max.dev_attr.attr, |
585 | &dev_attr_in1_max.attr, | 556 | &sensor_dev_attr_in1_max.dev_attr.attr, |
586 | &dev_attr_in2_max.attr, | 557 | &sensor_dev_attr_in2_max.dev_attr.attr, |
587 | &dev_attr_in3_max.attr, | 558 | &sensor_dev_attr_in3_max.dev_attr.attr, |
588 | &dev_attr_in4_max.attr, | 559 | &sensor_dev_attr_in4_max.dev_attr.attr, |
589 | 560 | ||
590 | &dev_attr_temp1_input.attr, | 561 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
591 | &dev_attr_temp2_input.attr, | 562 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
592 | &dev_attr_temp3_input.attr, | 563 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
593 | &dev_attr_temp1_max.attr, | 564 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
594 | &dev_attr_temp2_max.attr, | 565 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
595 | &dev_attr_temp3_max.attr, | 566 | &sensor_dev_attr_temp3_max.dev_attr.attr, |
596 | &dev_attr_temp1_max_hyst.attr, | 567 | &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, |
597 | &dev_attr_temp2_max_hyst.attr, | 568 | &sensor_dev_attr_temp2_max_hyst.dev_attr.attr, |
598 | &dev_attr_temp3_max_hyst.attr, | 569 | &sensor_dev_attr_temp3_max_hyst.dev_attr.attr, |
599 | 570 | ||
600 | &dev_attr_fan1_input.attr, | 571 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
601 | &dev_attr_fan2_input.attr, | 572 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
602 | &dev_attr_fan1_min.attr, | 573 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
603 | &dev_attr_fan2_min.attr, | 574 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
604 | &dev_attr_fan1_div.attr, | 575 | &sensor_dev_attr_fan1_div.dev_attr.attr, |
605 | &dev_attr_fan2_div.attr, | 576 | &sensor_dev_attr_fan2_div.dev_attr.attr, |
606 | 577 | ||
607 | &dev_attr_alarms.attr, | 578 | &dev_attr_alarms.attr, |
579 | &dev_attr_name.attr, | ||
608 | NULL | 580 | NULL |
609 | }; | 581 | }; |
610 | 582 | ||
@@ -612,58 +584,29 @@ static const struct attribute_group via686a_group = { | |||
612 | .attrs = via686a_attributes, | 584 | .attrs = via686a_attributes, |
613 | }; | 585 | }; |
614 | 586 | ||
615 | /* The driver. I choose to use type i2c_driver, as at is identical to both | 587 | static struct platform_driver via686a_driver = { |
616 | smbus_driver and isa_driver, and clients could be of either kind */ | ||
617 | static struct i2c_driver via686a_driver = { | ||
618 | .driver = { | 588 | .driver = { |
619 | .owner = THIS_MODULE, | 589 | .owner = THIS_MODULE, |
620 | .name = "via686a", | 590 | .name = "via686a", |
621 | }, | 591 | }, |
622 | .attach_adapter = via686a_detect, | 592 | .probe = via686a_probe, |
623 | .detach_client = via686a_detach_client, | 593 | .remove = __devexit_p(via686a_remove), |
624 | }; | 594 | }; |
625 | 595 | ||
626 | 596 | ||
627 | /* This is called when the module is loaded */ | 597 | /* This is called when the module is loaded */ |
628 | static int via686a_detect(struct i2c_adapter *adapter) | 598 | static int __devinit via686a_probe(struct platform_device *pdev) |
629 | { | 599 | { |
630 | struct i2c_client *new_client; | ||
631 | struct via686a_data *data; | 600 | struct via686a_data *data; |
632 | int err = 0; | 601 | struct resource *res; |
633 | const char client_name[] = "via686a"; | 602 | int err; |
634 | u16 val; | ||
635 | |||
636 | /* 8231 requires multiple of 256, we enforce that on 686 as well */ | ||
637 | if (force_addr) { | ||
638 | address = force_addr & 0xFF00; | ||
639 | dev_warn(&adapter->dev, "forcing ISA address 0x%04X\n", | ||
640 | address); | ||
641 | if (PCIBIOS_SUCCESSFUL != | ||
642 | pci_write_config_word(s_bridge, VIA686A_BASE_REG, address)) | ||
643 | return -ENODEV; | ||
644 | } | ||
645 | if (PCIBIOS_SUCCESSFUL != | ||
646 | pci_read_config_word(s_bridge, VIA686A_ENABLE_REG, &val)) | ||
647 | return -ENODEV; | ||
648 | if (!(val & 0x0001)) { | ||
649 | if (force_addr) { | ||
650 | dev_info(&adapter->dev, "enabling sensors\n"); | ||
651 | if (PCIBIOS_SUCCESSFUL != | ||
652 | pci_write_config_word(s_bridge, VIA686A_ENABLE_REG, | ||
653 | val | 0x0001)) | ||
654 | return -ENODEV; | ||
655 | } else { | ||
656 | dev_warn(&adapter->dev, "sensors disabled - enable " | ||
657 | "with force_addr=0x%x\n", address); | ||
658 | return -ENODEV; | ||
659 | } | ||
660 | } | ||
661 | 603 | ||
662 | /* Reserve the ISA region */ | 604 | /* Reserve the ISA region */ |
663 | if (!request_region(address, VIA686A_EXTENT, | 605 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
606 | if (!request_region(res->start, VIA686A_EXTENT, | ||
664 | via686a_driver.driver.name)) { | 607 | via686a_driver.driver.name)) { |
665 | dev_err(&adapter->dev, "region 0x%x already in use!\n", | 608 | dev_err(&pdev->dev, "Region 0x%lx-0x%lx already in use!\n", |
666 | address); | 609 | (unsigned long)res->start, (unsigned long)res->end); |
667 | return -ENODEV; | 610 | return -ENODEV; |
668 | } | 611 | } |
669 | 612 | ||
@@ -672,30 +615,19 @@ static int via686a_detect(struct i2c_adapter *adapter) | |||
672 | goto exit_release; | 615 | goto exit_release; |
673 | } | 616 | } |
674 | 617 | ||
675 | new_client = &data->client; | 618 | platform_set_drvdata(pdev, data); |
676 | i2c_set_clientdata(new_client, data); | 619 | data->addr = res->start; |
677 | new_client->addr = address; | 620 | data->name = "via686a"; |
678 | new_client->adapter = adapter; | ||
679 | new_client->driver = &via686a_driver; | ||
680 | new_client->flags = 0; | ||
681 | |||
682 | /* Fill in the remaining client fields and put into the global list */ | ||
683 | strlcpy(new_client->name, client_name, I2C_NAME_SIZE); | ||
684 | |||
685 | data->valid = 0; | ||
686 | mutex_init(&data->update_lock); | 621 | mutex_init(&data->update_lock); |
687 | /* Tell the I2C layer a new client has arrived */ | ||
688 | if ((err = i2c_attach_client(new_client))) | ||
689 | goto exit_free; | ||
690 | 622 | ||
691 | /* Initialize the VIA686A chip */ | 623 | /* Initialize the VIA686A chip */ |
692 | via686a_init_client(new_client); | 624 | via686a_init_device(data); |
693 | 625 | ||
694 | /* Register sysfs hooks */ | 626 | /* Register sysfs hooks */ |
695 | if ((err = sysfs_create_group(&new_client->dev.kobj, &via686a_group))) | 627 | if ((err = sysfs_create_group(&pdev->dev.kobj, &via686a_group))) |
696 | goto exit_detach; | 628 | goto exit_free; |
697 | 629 | ||
698 | data->class_dev = hwmon_device_register(&new_client->dev); | 630 | data->class_dev = hwmon_device_register(&pdev->dev); |
699 | if (IS_ERR(data->class_dev)) { | 631 | if (IS_ERR(data->class_dev)) { |
700 | err = PTR_ERR(data->class_dev); | 632 | err = PTR_ERR(data->class_dev); |
701 | goto exit_remove_files; | 633 | goto exit_remove_files; |
@@ -704,51 +636,46 @@ static int via686a_detect(struct i2c_adapter *adapter) | |||
704 | return 0; | 636 | return 0; |
705 | 637 | ||
706 | exit_remove_files: | 638 | exit_remove_files: |
707 | sysfs_remove_group(&new_client->dev.kobj, &via686a_group); | 639 | sysfs_remove_group(&pdev->dev.kobj, &via686a_group); |
708 | exit_detach: | ||
709 | i2c_detach_client(new_client); | ||
710 | exit_free: | 640 | exit_free: |
711 | kfree(data); | 641 | kfree(data); |
712 | exit_release: | 642 | exit_release: |
713 | release_region(address, VIA686A_EXTENT); | 643 | release_region(res->start, VIA686A_EXTENT); |
714 | return err; | 644 | return err; |
715 | } | 645 | } |
716 | 646 | ||
717 | static int via686a_detach_client(struct i2c_client *client) | 647 | static int __devexit via686a_remove(struct platform_device *pdev) |
718 | { | 648 | { |
719 | struct via686a_data *data = i2c_get_clientdata(client); | 649 | struct via686a_data *data = platform_get_drvdata(pdev); |
720 | int err; | ||
721 | 650 | ||
722 | hwmon_device_unregister(data->class_dev); | 651 | hwmon_device_unregister(data->class_dev); |
723 | sysfs_remove_group(&client->dev.kobj, &via686a_group); | 652 | sysfs_remove_group(&pdev->dev.kobj, &via686a_group); |
724 | 653 | ||
725 | if ((err = i2c_detach_client(client))) | 654 | release_region(data->addr, VIA686A_EXTENT); |
726 | return err; | 655 | platform_set_drvdata(pdev, NULL); |
727 | |||
728 | release_region(client->addr, VIA686A_EXTENT); | ||
729 | kfree(data); | 656 | kfree(data); |
730 | 657 | ||
731 | return 0; | 658 | return 0; |
732 | } | 659 | } |
733 | 660 | ||
734 | static void via686a_init_client(struct i2c_client *client) | 661 | static void __devinit via686a_init_device(struct via686a_data *data) |
735 | { | 662 | { |
736 | u8 reg; | 663 | u8 reg; |
737 | 664 | ||
738 | /* Start monitoring */ | 665 | /* Start monitoring */ |
739 | reg = via686a_read_value(client, VIA686A_REG_CONFIG); | 666 | reg = via686a_read_value(data, VIA686A_REG_CONFIG); |
740 | via686a_write_value(client, VIA686A_REG_CONFIG, (reg|0x01)&0x7F); | 667 | via686a_write_value(data, VIA686A_REG_CONFIG, (reg | 0x01) & 0x7F); |
741 | 668 | ||
742 | /* Configure temp interrupt mode for continuous-interrupt operation */ | 669 | /* Configure temp interrupt mode for continuous-interrupt operation */ |
743 | via686a_write_value(client, VIA686A_REG_TEMP_MODE, | 670 | reg = via686a_read_value(data, VIA686A_REG_TEMP_MODE); |
744 | via686a_read_value(client, VIA686A_REG_TEMP_MODE) & | 671 | via686a_write_value(data, VIA686A_REG_TEMP_MODE, |
745 | !(VIA686A_TEMP_MODE_MASK | VIA686A_TEMP_MODE_CONTINUOUS)); | 672 | (reg & ~VIA686A_TEMP_MODE_MASK) |
673 | | VIA686A_TEMP_MODE_CONTINUOUS); | ||
746 | } | 674 | } |
747 | 675 | ||
748 | static struct via686a_data *via686a_update_device(struct device *dev) | 676 | static struct via686a_data *via686a_update_device(struct device *dev) |
749 | { | 677 | { |
750 | struct i2c_client *client = to_i2c_client(dev); | 678 | struct via686a_data *data = dev_get_drvdata(dev); |
751 | struct via686a_data *data = i2c_get_clientdata(client); | ||
752 | int i; | 679 | int i; |
753 | 680 | ||
754 | mutex_lock(&data->update_lock); | 681 | mutex_lock(&data->update_lock); |
@@ -757,27 +684,27 @@ static struct via686a_data *via686a_update_device(struct device *dev) | |||
757 | || !data->valid) { | 684 | || !data->valid) { |
758 | for (i = 0; i <= 4; i++) { | 685 | for (i = 0; i <= 4; i++) { |
759 | data->in[i] = | 686 | data->in[i] = |
760 | via686a_read_value(client, VIA686A_REG_IN(i)); | 687 | via686a_read_value(data, VIA686A_REG_IN(i)); |
761 | data->in_min[i] = via686a_read_value(client, | 688 | data->in_min[i] = via686a_read_value(data, |
762 | VIA686A_REG_IN_MIN | 689 | VIA686A_REG_IN_MIN |
763 | (i)); | 690 | (i)); |
764 | data->in_max[i] = | 691 | data->in_max[i] = |
765 | via686a_read_value(client, VIA686A_REG_IN_MAX(i)); | 692 | via686a_read_value(data, VIA686A_REG_IN_MAX(i)); |
766 | } | 693 | } |
767 | for (i = 1; i <= 2; i++) { | 694 | for (i = 1; i <= 2; i++) { |
768 | data->fan[i - 1] = | 695 | data->fan[i - 1] = |
769 | via686a_read_value(client, VIA686A_REG_FAN(i)); | 696 | via686a_read_value(data, VIA686A_REG_FAN(i)); |
770 | data->fan_min[i - 1] = via686a_read_value(client, | 697 | data->fan_min[i - 1] = via686a_read_value(data, |
771 | VIA686A_REG_FAN_MIN(i)); | 698 | VIA686A_REG_FAN_MIN(i)); |
772 | } | 699 | } |
773 | for (i = 0; i <= 2; i++) { | 700 | for (i = 0; i <= 2; i++) { |
774 | data->temp[i] = via686a_read_value(client, | 701 | data->temp[i] = via686a_read_value(data, |
775 | VIA686A_REG_TEMP[i]) << 2; | 702 | VIA686A_REG_TEMP[i]) << 2; |
776 | data->temp_over[i] = | 703 | data->temp_over[i] = |
777 | via686a_read_value(client, | 704 | via686a_read_value(data, |
778 | VIA686A_REG_TEMP_OVER[i]); | 705 | VIA686A_REG_TEMP_OVER[i]); |
779 | data->temp_hyst[i] = | 706 | data->temp_hyst[i] = |
780 | via686a_read_value(client, | 707 | via686a_read_value(data, |
781 | VIA686A_REG_TEMP_HYST[i]); | 708 | VIA686A_REG_TEMP_HYST[i]); |
782 | } | 709 | } |
783 | /* add in lower 2 bits | 710 | /* add in lower 2 bits |
@@ -785,23 +712,23 @@ static struct via686a_data *via686a_update_device(struct device *dev) | |||
785 | temp2 uses bits 5-4 of VIA686A_REG_TEMP_LOW23 | 712 | temp2 uses bits 5-4 of VIA686A_REG_TEMP_LOW23 |
786 | temp3 uses bits 7-6 of VIA686A_REG_TEMP_LOW23 | 713 | temp3 uses bits 7-6 of VIA686A_REG_TEMP_LOW23 |
787 | */ | 714 | */ |
788 | data->temp[0] |= (via686a_read_value(client, | 715 | data->temp[0] |= (via686a_read_value(data, |
789 | VIA686A_REG_TEMP_LOW1) | 716 | VIA686A_REG_TEMP_LOW1) |
790 | & 0xc0) >> 6; | 717 | & 0xc0) >> 6; |
791 | data->temp[1] |= | 718 | data->temp[1] |= |
792 | (via686a_read_value(client, VIA686A_REG_TEMP_LOW23) & | 719 | (via686a_read_value(data, VIA686A_REG_TEMP_LOW23) & |
793 | 0x30) >> 4; | 720 | 0x30) >> 4; |
794 | data->temp[2] |= | 721 | data->temp[2] |= |
795 | (via686a_read_value(client, VIA686A_REG_TEMP_LOW23) & | 722 | (via686a_read_value(data, VIA686A_REG_TEMP_LOW23) & |
796 | 0xc0) >> 6; | 723 | 0xc0) >> 6; |
797 | 724 | ||
798 | i = via686a_read_value(client, VIA686A_REG_FANDIV); | 725 | i = via686a_read_value(data, VIA686A_REG_FANDIV); |
799 | data->fan_div[0] = (i >> 4) & 0x03; | 726 | data->fan_div[0] = (i >> 4) & 0x03; |
800 | data->fan_div[1] = i >> 6; | 727 | data->fan_div[1] = i >> 6; |
801 | data->alarms = | 728 | data->alarms = |
802 | via686a_read_value(client, | 729 | via686a_read_value(data, |
803 | VIA686A_REG_ALARM1) | | 730 | VIA686A_REG_ALARM1) | |
804 | (via686a_read_value(client, VIA686A_REG_ALARM2) << 8); | 731 | (via686a_read_value(data, VIA686A_REG_ALARM2) << 8); |
805 | data->last_updated = jiffies; | 732 | data->last_updated = jiffies; |
806 | data->valid = 1; | 733 | data->valid = 1; |
807 | } | 734 | } |
@@ -818,32 +745,102 @@ static struct pci_device_id via686a_pci_ids[] = { | |||
818 | 745 | ||
819 | MODULE_DEVICE_TABLE(pci, via686a_pci_ids); | 746 | MODULE_DEVICE_TABLE(pci, via686a_pci_ids); |
820 | 747 | ||
748 | static int __devinit via686a_device_add(unsigned short address) | ||
749 | { | ||
750 | struct resource res = { | ||
751 | .start = address, | ||
752 | .end = address + VIA686A_EXTENT - 1, | ||
753 | .name = "via686a", | ||
754 | .flags = IORESOURCE_IO, | ||
755 | }; | ||
756 | int err; | ||
757 | |||
758 | pdev = platform_device_alloc("via686a", address); | ||
759 | if (!pdev) { | ||
760 | err = -ENOMEM; | ||
761 | printk(KERN_ERR "via686a: Device allocation failed\n"); | ||
762 | goto exit; | ||
763 | } | ||
764 | |||
765 | err = platform_device_add_resources(pdev, &res, 1); | ||
766 | if (err) { | ||
767 | printk(KERN_ERR "via686a: Device resource addition failed " | ||
768 | "(%d)\n", err); | ||
769 | goto exit_device_put; | ||
770 | } | ||
771 | |||
772 | err = platform_device_add(pdev); | ||
773 | if (err) { | ||
774 | printk(KERN_ERR "via686a: Device addition failed (%d)\n", | ||
775 | err); | ||
776 | goto exit_device_put; | ||
777 | } | ||
778 | |||
779 | return 0; | ||
780 | |||
781 | exit_device_put: | ||
782 | platform_device_put(pdev); | ||
783 | exit: | ||
784 | return err; | ||
785 | } | ||
786 | |||
821 | static int __devinit via686a_pci_probe(struct pci_dev *dev, | 787 | static int __devinit via686a_pci_probe(struct pci_dev *dev, |
822 | const struct pci_device_id *id) | 788 | const struct pci_device_id *id) |
823 | { | 789 | { |
824 | u16 val; | 790 | u16 address, val; |
825 | 791 | ||
792 | if (force_addr) { | ||
793 | address = force_addr & ~(VIA686A_EXTENT - 1); | ||
794 | dev_warn(&dev->dev, "Forcing ISA address 0x%x\n", address); | ||
795 | if (PCIBIOS_SUCCESSFUL != | ||
796 | pci_write_config_word(dev, VIA686A_BASE_REG, address | 1)) | ||
797 | return -ENODEV; | ||
798 | } | ||
826 | if (PCIBIOS_SUCCESSFUL != | 799 | if (PCIBIOS_SUCCESSFUL != |
827 | pci_read_config_word(dev, VIA686A_BASE_REG, &val)) | 800 | pci_read_config_word(dev, VIA686A_BASE_REG, &val)) |
828 | return -ENODEV; | 801 | return -ENODEV; |
829 | 802 | ||
830 | address = val & ~(VIA686A_EXTENT - 1); | 803 | address = val & ~(VIA686A_EXTENT - 1); |
831 | if (address == 0 && force_addr == 0) { | 804 | if (address == 0) { |
832 | dev_err(&dev->dev, "base address not set - upgrade BIOS " | 805 | dev_err(&dev->dev, "base address not set - upgrade BIOS " |
833 | "or use force_addr=0xaddr\n"); | 806 | "or use force_addr=0xaddr\n"); |
834 | return -ENODEV; | 807 | return -ENODEV; |
835 | } | 808 | } |
836 | 809 | ||
837 | s_bridge = pci_dev_get(dev); | 810 | if (PCIBIOS_SUCCESSFUL != |
838 | if (i2c_isa_add_driver(&via686a_driver)) { | 811 | pci_read_config_word(dev, VIA686A_ENABLE_REG, &val)) |
839 | pci_dev_put(s_bridge); | 812 | return -ENODEV; |
840 | s_bridge = NULL; | 813 | if (!(val & 0x0001)) { |
814 | if (!force_addr) { | ||
815 | dev_warn(&dev->dev, "Sensors disabled, enable " | ||
816 | "with force_addr=0x%x\n", address); | ||
817 | return -ENODEV; | ||
818 | } | ||
819 | |||
820 | dev_warn(&dev->dev, "Enabling sensors\n"); | ||
821 | if (PCIBIOS_SUCCESSFUL != | ||
822 | pci_write_config_word(dev, VIA686A_ENABLE_REG, | ||
823 | val | 0x0001)) | ||
824 | return -ENODEV; | ||
841 | } | 825 | } |
842 | 826 | ||
827 | if (platform_driver_register(&via686a_driver)) | ||
828 | goto exit; | ||
829 | |||
830 | /* Sets global pdev as a side effect */ | ||
831 | if (via686a_device_add(address)) | ||
832 | goto exit_unregister; | ||
833 | |||
843 | /* Always return failure here. This is to allow other drivers to bind | 834 | /* Always return failure here. This is to allow other drivers to bind |
844 | * to this pci device. We don't really want to have control over the | 835 | * to this pci device. We don't really want to have control over the |
845 | * pci device, we only wanted to read as few register values from it. | 836 | * pci device, we only wanted to read as few register values from it. |
846 | */ | 837 | */ |
838 | s_bridge = pci_dev_get(dev); | ||
839 | return -ENODEV; | ||
840 | |||
841 | exit_unregister: | ||
842 | platform_driver_unregister(&via686a_driver); | ||
843 | exit: | ||
847 | return -ENODEV; | 844 | return -ENODEV; |
848 | } | 845 | } |
849 | 846 | ||
@@ -862,7 +859,8 @@ static void __exit sm_via686a_exit(void) | |||
862 | { | 859 | { |
863 | pci_unregister_driver(&via686a_pci_driver); | 860 | pci_unregister_driver(&via686a_pci_driver); |
864 | if (s_bridge != NULL) { | 861 | if (s_bridge != NULL) { |
865 | i2c_isa_del_driver(&via686a_driver); | 862 | platform_device_unregister(pdev); |
863 | platform_driver_unregister(&via686a_driver); | ||
866 | pci_dev_put(s_bridge); | 864 | pci_dev_put(s_bridge); |
867 | s_bridge = NULL; | 865 | s_bridge = NULL; |
868 | } | 866 | } |
diff --git a/drivers/hwmon/vt8231.c b/drivers/hwmon/vt8231.c index a6a4aa0eee16..c604972f0186 100644 --- a/drivers/hwmon/vt8231.c +++ b/drivers/hwmon/vt8231.c | |||
@@ -29,8 +29,7 @@ | |||
29 | #include <linux/slab.h> | 29 | #include <linux/slab.h> |
30 | #include <linux/pci.h> | 30 | #include <linux/pci.h> |
31 | #include <linux/jiffies.h> | 31 | #include <linux/jiffies.h> |
32 | #include <linux/i2c.h> | 32 | #include <linux/platform_device.h> |
33 | #include <linux/i2c-isa.h> | ||
34 | #include <linux/hwmon.h> | 33 | #include <linux/hwmon.h> |
35 | #include <linux/hwmon-sysfs.h> | 34 | #include <linux/hwmon-sysfs.h> |
36 | #include <linux/hwmon-vid.h> | 35 | #include <linux/hwmon-vid.h> |
@@ -42,10 +41,7 @@ static int force_addr; | |||
42 | module_param(force_addr, int, 0); | 41 | module_param(force_addr, int, 0); |
43 | MODULE_PARM_DESC(force_addr, "Initialize the base address of the sensors"); | 42 | MODULE_PARM_DESC(force_addr, "Initialize the base address of the sensors"); |
44 | 43 | ||
45 | /* Device address | 44 | static struct platform_device *pdev; |
46 | Note that we can't determine the ISA address until we have initialized | ||
47 | our module */ | ||
48 | static unsigned short isa_address; | ||
49 | 45 | ||
50 | #define VT8231_EXTENT 0x80 | 46 | #define VT8231_EXTENT 0x80 |
51 | #define VT8231_BASE_REG 0x70 | 47 | #define VT8231_BASE_REG 0x70 |
@@ -148,7 +144,9 @@ static inline u8 FAN_TO_REG(long rpm, int div) | |||
148 | #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : 1310720 / ((val) * (div))) | 144 | #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : 1310720 / ((val) * (div))) |
149 | 145 | ||
150 | struct vt8231_data { | 146 | struct vt8231_data { |
151 | struct i2c_client client; | 147 | unsigned short addr; |
148 | const char *name; | ||
149 | |||
152 | struct mutex update_lock; | 150 | struct mutex update_lock; |
153 | struct class_device *class_dev; | 151 | struct class_device *class_dev; |
154 | char valid; /* !=0 if following fields are valid */ | 152 | char valid; /* !=0 if following fields are valid */ |
@@ -168,20 +166,20 @@ struct vt8231_data { | |||
168 | }; | 166 | }; |
169 | 167 | ||
170 | static struct pci_dev *s_bridge; | 168 | static struct pci_dev *s_bridge; |
171 | static int vt8231_detect(struct i2c_adapter *adapter); | 169 | static int vt8231_probe(struct platform_device *pdev); |
172 | static int vt8231_detach_client(struct i2c_client *client); | 170 | static int vt8231_remove(struct platform_device *pdev); |
173 | static struct vt8231_data *vt8231_update_device(struct device *dev); | 171 | static struct vt8231_data *vt8231_update_device(struct device *dev); |
174 | static void vt8231_init_client(struct i2c_client *client); | 172 | static void vt8231_init_device(struct vt8231_data *data); |
175 | 173 | ||
176 | static inline int vt8231_read_value(struct i2c_client *client, u8 reg) | 174 | static inline int vt8231_read_value(struct vt8231_data *data, u8 reg) |
177 | { | 175 | { |
178 | return inb_p(client->addr + reg); | 176 | return inb_p(data->addr + reg); |
179 | } | 177 | } |
180 | 178 | ||
181 | static inline void vt8231_write_value(struct i2c_client *client, u8 reg, | 179 | static inline void vt8231_write_value(struct vt8231_data *data, u8 reg, |
182 | u8 value) | 180 | u8 value) |
183 | { | 181 | { |
184 | outb_p(value, client->addr + reg); | 182 | outb_p(value, data->addr + reg); |
185 | } | 183 | } |
186 | 184 | ||
187 | /* following are the sysfs callback functions */ | 185 | /* following are the sysfs callback functions */ |
@@ -220,13 +218,12 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | |||
220 | { | 218 | { |
221 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 219 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
222 | int nr = sensor_attr->index; | 220 | int nr = sensor_attr->index; |
223 | struct i2c_client *client = to_i2c_client(dev); | 221 | struct vt8231_data *data = dev_get_drvdata(dev); |
224 | struct vt8231_data *data = i2c_get_clientdata(client); | ||
225 | unsigned long val = simple_strtoul(buf, NULL, 10); | 222 | unsigned long val = simple_strtoul(buf, NULL, 10); |
226 | 223 | ||
227 | mutex_lock(&data->update_lock); | 224 | mutex_lock(&data->update_lock); |
228 | data->in_min[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); | 225 | data->in_min[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); |
229 | vt8231_write_value(client, regvoltmin[nr], data->in_min[nr]); | 226 | vt8231_write_value(data, regvoltmin[nr], data->in_min[nr]); |
230 | mutex_unlock(&data->update_lock); | 227 | mutex_unlock(&data->update_lock); |
231 | return count; | 228 | return count; |
232 | } | 229 | } |
@@ -236,13 +233,12 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | |||
236 | { | 233 | { |
237 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 234 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
238 | int nr = sensor_attr->index; | 235 | int nr = sensor_attr->index; |
239 | struct i2c_client *client = to_i2c_client(dev); | 236 | struct vt8231_data *data = dev_get_drvdata(dev); |
240 | struct vt8231_data *data = i2c_get_clientdata(client); | ||
241 | unsigned long val = simple_strtoul(buf, NULL, 10); | 237 | unsigned long val = simple_strtoul(buf, NULL, 10); |
242 | 238 | ||
243 | mutex_lock(&data->update_lock); | 239 | mutex_lock(&data->update_lock); |
244 | data->in_max[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); | 240 | data->in_max[nr] = SENSORS_LIMIT(((val * 958) / 10000) + 3, 0, 255); |
245 | vt8231_write_value(client, regvoltmax[nr], data->in_max[nr]); | 241 | vt8231_write_value(data, regvoltmax[nr], data->in_max[nr]); |
246 | mutex_unlock(&data->update_lock); | 242 | mutex_unlock(&data->update_lock); |
247 | return count; | 243 | return count; |
248 | } | 244 | } |
@@ -278,14 +274,13 @@ static ssize_t show_in5_max(struct device *dev, struct device_attribute *attr, | |||
278 | static ssize_t set_in5_min(struct device *dev, struct device_attribute *attr, | 274 | static ssize_t set_in5_min(struct device *dev, struct device_attribute *attr, |
279 | const char *buf, size_t count) | 275 | const char *buf, size_t count) |
280 | { | 276 | { |
281 | struct i2c_client *client = to_i2c_client(dev); | 277 | struct vt8231_data *data = dev_get_drvdata(dev); |
282 | struct vt8231_data *data = i2c_get_clientdata(client); | ||
283 | unsigned long val = simple_strtoul(buf, NULL, 10); | 278 | unsigned long val = simple_strtoul(buf, NULL, 10); |
284 | 279 | ||
285 | mutex_lock(&data->update_lock); | 280 | mutex_lock(&data->update_lock); |
286 | data->in_min[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, | 281 | data->in_min[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, |
287 | 0, 255); | 282 | 0, 255); |
288 | vt8231_write_value(client, regvoltmin[5], data->in_min[5]); | 283 | vt8231_write_value(data, regvoltmin[5], data->in_min[5]); |
289 | mutex_unlock(&data->update_lock); | 284 | mutex_unlock(&data->update_lock); |
290 | return count; | 285 | return count; |
291 | } | 286 | } |
@@ -293,14 +288,13 @@ static ssize_t set_in5_min(struct device *dev, struct device_attribute *attr, | |||
293 | static ssize_t set_in5_max(struct device *dev, struct device_attribute *attr, | 288 | static ssize_t set_in5_max(struct device *dev, struct device_attribute *attr, |
294 | const char *buf, size_t count) | 289 | const char *buf, size_t count) |
295 | { | 290 | { |
296 | struct i2c_client *client = to_i2c_client(dev); | 291 | struct vt8231_data *data = dev_get_drvdata(dev); |
297 | struct vt8231_data *data = i2c_get_clientdata(client); | ||
298 | unsigned long val = simple_strtoul(buf, NULL, 10); | 292 | unsigned long val = simple_strtoul(buf, NULL, 10); |
299 | 293 | ||
300 | mutex_lock(&data->update_lock); | 294 | mutex_lock(&data->update_lock); |
301 | data->in_max[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, | 295 | data->in_max[5] = SENSORS_LIMIT(((val * 958 * 34) / (10000 * 54)) + 3, |
302 | 0, 255); | 296 | 0, 255); |
303 | vt8231_write_value(client, regvoltmax[5], data->in_max[5]); | 297 | vt8231_write_value(data, regvoltmax[5], data->in_max[5]); |
304 | mutex_unlock(&data->update_lock); | 298 | mutex_unlock(&data->update_lock); |
305 | return count; | 299 | return count; |
306 | } | 300 | } |
@@ -348,26 +342,24 @@ static ssize_t show_temp0_min(struct device *dev, struct device_attribute *attr, | |||
348 | static ssize_t set_temp0_max(struct device *dev, struct device_attribute *attr, | 342 | static ssize_t set_temp0_max(struct device *dev, struct device_attribute *attr, |
349 | const char *buf, size_t count) | 343 | const char *buf, size_t count) |
350 | { | 344 | { |
351 | struct i2c_client *client = to_i2c_client(dev); | 345 | struct vt8231_data *data = dev_get_drvdata(dev); |
352 | struct vt8231_data *data = i2c_get_clientdata(client); | ||
353 | int val = simple_strtol(buf, NULL, 10); | 346 | int val = simple_strtol(buf, NULL, 10); |
354 | 347 | ||
355 | mutex_lock(&data->update_lock); | 348 | mutex_lock(&data->update_lock); |
356 | data->temp_max[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); | 349 | data->temp_max[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); |
357 | vt8231_write_value(client, regtempmax[0], data->temp_max[0]); | 350 | vt8231_write_value(data, regtempmax[0], data->temp_max[0]); |
358 | mutex_unlock(&data->update_lock); | 351 | mutex_unlock(&data->update_lock); |
359 | return count; | 352 | return count; |
360 | } | 353 | } |
361 | static ssize_t set_temp0_min(struct device *dev, struct device_attribute *attr, | 354 | static ssize_t set_temp0_min(struct device *dev, struct device_attribute *attr, |
362 | const char *buf, size_t count) | 355 | const char *buf, size_t count) |
363 | { | 356 | { |
364 | struct i2c_client *client = to_i2c_client(dev); | 357 | struct vt8231_data *data = dev_get_drvdata(dev); |
365 | struct vt8231_data *data = i2c_get_clientdata(client); | ||
366 | int val = simple_strtol(buf, NULL, 10); | 358 | int val = simple_strtol(buf, NULL, 10); |
367 | 359 | ||
368 | mutex_lock(&data->update_lock); | 360 | mutex_lock(&data->update_lock); |
369 | data->temp_min[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); | 361 | data->temp_min[0] = SENSORS_LIMIT((val + 500) / 1000, 0, 255); |
370 | vt8231_write_value(client, regtempmin[0], data->temp_min[0]); | 362 | vt8231_write_value(data, regtempmin[0], data->temp_min[0]); |
371 | mutex_unlock(&data->update_lock); | 363 | mutex_unlock(&data->update_lock); |
372 | return count; | 364 | return count; |
373 | } | 365 | } |
@@ -404,13 +396,12 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
404 | { | 396 | { |
405 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 397 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
406 | int nr = sensor_attr->index; | 398 | int nr = sensor_attr->index; |
407 | struct i2c_client *client = to_i2c_client(dev); | 399 | struct vt8231_data *data = dev_get_drvdata(dev); |
408 | struct vt8231_data *data = i2c_get_clientdata(client); | ||
409 | int val = simple_strtol(buf, NULL, 10); | 400 | int val = simple_strtol(buf, NULL, 10); |
410 | 401 | ||
411 | mutex_lock(&data->update_lock); | 402 | mutex_lock(&data->update_lock); |
412 | data->temp_max[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); | 403 | data->temp_max[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); |
413 | vt8231_write_value(client, regtempmax[nr], data->temp_max[nr]); | 404 | vt8231_write_value(data, regtempmax[nr], data->temp_max[nr]); |
414 | mutex_unlock(&data->update_lock); | 405 | mutex_unlock(&data->update_lock); |
415 | return count; | 406 | return count; |
416 | } | 407 | } |
@@ -419,13 +410,12 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
419 | { | 410 | { |
420 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 411 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
421 | int nr = sensor_attr->index; | 412 | int nr = sensor_attr->index; |
422 | struct i2c_client *client = to_i2c_client(dev); | 413 | struct vt8231_data *data = dev_get_drvdata(dev); |
423 | struct vt8231_data *data = i2c_get_clientdata(client); | ||
424 | int val = simple_strtol(buf, NULL, 10); | 414 | int val = simple_strtol(buf, NULL, 10); |
425 | 415 | ||
426 | mutex_lock(&data->update_lock); | 416 | mutex_lock(&data->update_lock); |
427 | data->temp_min[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); | 417 | data->temp_min[nr] = SENSORS_LIMIT(TEMP_MAXMIN_TO_REG(val), 0, 255); |
428 | vt8231_write_value(client, regtempmin[nr], data->temp_min[nr]); | 418 | vt8231_write_value(data, regtempmin[nr], data->temp_min[nr]); |
429 | mutex_unlock(&data->update_lock); | 419 | mutex_unlock(&data->update_lock); |
430 | return count; | 420 | return count; |
431 | } | 421 | } |
@@ -486,13 +476,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
486 | { | 476 | { |
487 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 477 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
488 | int nr = sensor_attr->index; | 478 | int nr = sensor_attr->index; |
489 | struct i2c_client *client = to_i2c_client(dev); | 479 | struct vt8231_data *data = dev_get_drvdata(dev); |
490 | struct vt8231_data *data = i2c_get_clientdata(client); | ||
491 | int val = simple_strtoul(buf, NULL, 10); | 480 | int val = simple_strtoul(buf, NULL, 10); |
492 | 481 | ||
493 | mutex_lock(&data->update_lock); | 482 | mutex_lock(&data->update_lock); |
494 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); | 483 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
495 | vt8231_write_value(client, VT8231_REG_FAN_MIN(nr), data->fan_min[nr]); | 484 | vt8231_write_value(data, VT8231_REG_FAN_MIN(nr), data->fan_min[nr]); |
496 | mutex_unlock(&data->update_lock); | 485 | mutex_unlock(&data->update_lock); |
497 | return count; | 486 | return count; |
498 | } | 487 | } |
@@ -500,12 +489,11 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
500 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | 489 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
501 | const char *buf, size_t count) | 490 | const char *buf, size_t count) |
502 | { | 491 | { |
503 | struct i2c_client *client = to_i2c_client(dev); | 492 | struct vt8231_data *data = dev_get_drvdata(dev); |
504 | struct vt8231_data *data = i2c_get_clientdata(client); | ||
505 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 493 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
506 | unsigned long val = simple_strtoul(buf, NULL, 10); | 494 | unsigned long val = simple_strtoul(buf, NULL, 10); |
507 | int nr = sensor_attr->index; | 495 | int nr = sensor_attr->index; |
508 | int old = vt8231_read_value(client, VT8231_REG_FANDIV); | 496 | int old = vt8231_read_value(data, VT8231_REG_FANDIV); |
509 | long min = FAN_FROM_REG(data->fan_min[nr], | 497 | long min = FAN_FROM_REG(data->fan_min[nr], |
510 | DIV_FROM_REG(data->fan_div[nr])); | 498 | DIV_FROM_REG(data->fan_div[nr])); |
511 | 499 | ||
@@ -516,7 +504,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | |||
516 | case 4: data->fan_div[nr] = 2; break; | 504 | case 4: data->fan_div[nr] = 2; break; |
517 | case 8: data->fan_div[nr] = 3; break; | 505 | case 8: data->fan_div[nr] = 3; break; |
518 | default: | 506 | default: |
519 | dev_err(&client->dev, "fan_div value %ld not supported." | 507 | dev_err(dev, "fan_div value %ld not supported." |
520 | "Choose one of 1, 2, 4 or 8!\n", val); | 508 | "Choose one of 1, 2, 4 or 8!\n", val); |
521 | mutex_unlock(&data->update_lock); | 509 | mutex_unlock(&data->update_lock); |
522 | return -EINVAL; | 510 | return -EINVAL; |
@@ -524,10 +512,10 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | |||
524 | 512 | ||
525 | /* Correct the fan minimum speed */ | 513 | /* Correct the fan minimum speed */ |
526 | data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); | 514 | data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); |
527 | vt8231_write_value(client, VT8231_REG_FAN_MIN(nr), data->fan_min[nr]); | 515 | vt8231_write_value(data, VT8231_REG_FAN_MIN(nr), data->fan_min[nr]); |
528 | 516 | ||
529 | old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4); | 517 | old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4); |
530 | vt8231_write_value(client, VT8231_REG_FANDIV, old); | 518 | vt8231_write_value(data, VT8231_REG_FANDIV, old); |
531 | mutex_unlock(&data->update_lock); | 519 | mutex_unlock(&data->update_lock); |
532 | return count; | 520 | return count; |
533 | } | 521 | } |
@@ -551,9 +539,16 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, | |||
551 | struct vt8231_data *data = vt8231_update_device(dev); | 539 | struct vt8231_data *data = vt8231_update_device(dev); |
552 | return sprintf(buf, "%d\n", data->alarms); | 540 | return sprintf(buf, "%d\n", data->alarms); |
553 | } | 541 | } |
554 | |||
555 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 542 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
556 | 543 | ||
544 | static ssize_t show_name(struct device *dev, struct device_attribute | ||
545 | *devattr, char *buf) | ||
546 | { | ||
547 | struct vt8231_data *data = dev_get_drvdata(dev); | ||
548 | return sprintf(buf, "%s\n", data->name); | ||
549 | } | ||
550 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
551 | |||
557 | static struct attribute *vt8231_attributes_temps[6][4] = { | 552 | static struct attribute *vt8231_attributes_temps[6][4] = { |
558 | { | 553 | { |
559 | &dev_attr_temp1_input.attr, | 554 | &dev_attr_temp1_input.attr, |
@@ -648,6 +643,7 @@ static struct attribute *vt8231_attributes[] = { | |||
648 | &sensor_dev_attr_fan1_div.dev_attr.attr, | 643 | &sensor_dev_attr_fan1_div.dev_attr.attr, |
649 | &sensor_dev_attr_fan2_div.dev_attr.attr, | 644 | &sensor_dev_attr_fan2_div.dev_attr.attr, |
650 | &dev_attr_alarms.attr, | 645 | &dev_attr_alarms.attr, |
646 | &dev_attr_name.attr, | ||
651 | NULL | 647 | NULL |
652 | }; | 648 | }; |
653 | 649 | ||
@@ -655,13 +651,13 @@ static const struct attribute_group vt8231_group = { | |||
655 | .attrs = vt8231_attributes, | 651 | .attrs = vt8231_attributes, |
656 | }; | 652 | }; |
657 | 653 | ||
658 | static struct i2c_driver vt8231_driver = { | 654 | static struct platform_driver vt8231_driver = { |
659 | .driver = { | 655 | .driver = { |
660 | .owner = THIS_MODULE, | 656 | .owner = THIS_MODULE, |
661 | .name = "vt8231", | 657 | .name = "vt8231", |
662 | }, | 658 | }, |
663 | .attach_adapter = vt8231_detect, | 659 | .probe = vt8231_probe, |
664 | .detach_client = vt8231_detach_client, | 660 | .remove = __devexit_p(vt8231_remove), |
665 | }; | 661 | }; |
666 | 662 | ||
667 | static struct pci_device_id vt8231_pci_ids[] = { | 663 | static struct pci_device_id vt8231_pci_ids[] = { |
@@ -680,40 +676,18 @@ static struct pci_driver vt8231_pci_driver = { | |||
680 | .probe = vt8231_pci_probe, | 676 | .probe = vt8231_pci_probe, |
681 | }; | 677 | }; |
682 | 678 | ||
683 | int vt8231_detect(struct i2c_adapter *adapter) | 679 | int vt8231_probe(struct platform_device *pdev) |
684 | { | 680 | { |
685 | struct i2c_client *client; | 681 | struct resource *res; |
686 | struct vt8231_data *data; | 682 | struct vt8231_data *data; |
687 | int err = 0, i; | 683 | int err = 0, i; |
688 | u16 val; | ||
689 | |||
690 | /* 8231 requires multiple of 256 */ | ||
691 | if (force_addr) { | ||
692 | isa_address = force_addr & 0xFF00; | ||
693 | dev_warn(&adapter->dev, "forcing ISA address 0x%04X\n", | ||
694 | isa_address); | ||
695 | if (PCIBIOS_SUCCESSFUL != pci_write_config_word(s_bridge, | ||
696 | VT8231_BASE_REG, isa_address)) | ||
697 | return -ENODEV; | ||
698 | } | ||
699 | |||
700 | if (PCIBIOS_SUCCESSFUL != | ||
701 | pci_read_config_word(s_bridge, VT8231_ENABLE_REG, &val)) | ||
702 | return -ENODEV; | ||
703 | |||
704 | if (!(val & 0x0001)) { | ||
705 | dev_warn(&adapter->dev, "enabling sensors\n"); | ||
706 | if (PCIBIOS_SUCCESSFUL != | ||
707 | pci_write_config_word(s_bridge, VT8231_ENABLE_REG, | ||
708 | val | 0x0001)) | ||
709 | return -ENODEV; | ||
710 | } | ||
711 | 684 | ||
712 | /* Reserve the ISA region */ | 685 | /* Reserve the ISA region */ |
713 | if (!request_region(isa_address, VT8231_EXTENT, | 686 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
714 | vt8231_pci_driver.name)) { | 687 | if (!request_region(res->start, VT8231_EXTENT, |
715 | dev_err(&adapter->dev, "region 0x%x already in use!\n", | 688 | vt8231_driver.driver.name)) { |
716 | isa_address); | 689 | dev_err(&pdev->dev, "Region 0x%lx-0x%lx already in use!\n", |
690 | (unsigned long)res->start, (unsigned long)res->end); | ||
717 | return -ENODEV; | 691 | return -ENODEV; |
718 | } | 692 | } |
719 | 693 | ||
@@ -722,33 +696,23 @@ int vt8231_detect(struct i2c_adapter *adapter) | |||
722 | goto exit_release; | 696 | goto exit_release; |
723 | } | 697 | } |
724 | 698 | ||
725 | client = &data->client; | 699 | platform_set_drvdata(pdev, data); |
726 | i2c_set_clientdata(client, data); | 700 | data->addr = res->start; |
727 | client->addr = isa_address; | 701 | data->name = "vt8231"; |
728 | client->adapter = adapter; | ||
729 | client->driver = &vt8231_driver; | ||
730 | |||
731 | /* Fill in the remaining client fields and put into the global list */ | ||
732 | strlcpy(client->name, "vt8231", I2C_NAME_SIZE); | ||
733 | 702 | ||
734 | mutex_init(&data->update_lock); | 703 | mutex_init(&data->update_lock); |
735 | 704 | vt8231_init_device(data); | |
736 | /* Tell the I2C layer a new client has arrived */ | ||
737 | if ((err = i2c_attach_client(client))) | ||
738 | goto exit_free; | ||
739 | |||
740 | vt8231_init_client(client); | ||
741 | 705 | ||
742 | /* Register sysfs hooks */ | 706 | /* Register sysfs hooks */ |
743 | if ((err = sysfs_create_group(&client->dev.kobj, &vt8231_group))) | 707 | if ((err = sysfs_create_group(&pdev->dev.kobj, &vt8231_group))) |
744 | goto exit_detach; | 708 | goto exit_free; |
745 | 709 | ||
746 | /* Must update device information to find out the config field */ | 710 | /* Must update device information to find out the config field */ |
747 | data->uch_config = vt8231_read_value(client, VT8231_REG_UCH_CONFIG); | 711 | data->uch_config = vt8231_read_value(data, VT8231_REG_UCH_CONFIG); |
748 | 712 | ||
749 | for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) { | 713 | for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) { |
750 | if (ISTEMP(i, data->uch_config)) { | 714 | if (ISTEMP(i, data->uch_config)) { |
751 | if ((err = sysfs_create_group(&client->dev.kobj, | 715 | if ((err = sysfs_create_group(&pdev->dev.kobj, |
752 | &vt8231_group_temps[i]))) | 716 | &vt8231_group_temps[i]))) |
753 | goto exit_remove_files; | 717 | goto exit_remove_files; |
754 | } | 718 | } |
@@ -756,13 +720,13 @@ int vt8231_detect(struct i2c_adapter *adapter) | |||
756 | 720 | ||
757 | for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) { | 721 | for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) { |
758 | if (ISVOLT(i, data->uch_config)) { | 722 | if (ISVOLT(i, data->uch_config)) { |
759 | if ((err = sysfs_create_group(&client->dev.kobj, | 723 | if ((err = sysfs_create_group(&pdev->dev.kobj, |
760 | &vt8231_group_volts[i]))) | 724 | &vt8231_group_volts[i]))) |
761 | goto exit_remove_files; | 725 | goto exit_remove_files; |
762 | } | 726 | } |
763 | } | 727 | } |
764 | 728 | ||
765 | data->class_dev = hwmon_device_register(&client->dev); | 729 | data->class_dev = hwmon_device_register(&pdev->dev); |
766 | if (IS_ERR(data->class_dev)) { | 730 | if (IS_ERR(data->class_dev)) { |
767 | err = PTR_ERR(data->class_dev); | 731 | err = PTR_ERR(data->class_dev); |
768 | goto exit_remove_files; | 732 | goto exit_remove_files; |
@@ -771,56 +735,52 @@ int vt8231_detect(struct i2c_adapter *adapter) | |||
771 | 735 | ||
772 | exit_remove_files: | 736 | exit_remove_files: |
773 | for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) | 737 | for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) |
774 | sysfs_remove_group(&client->dev.kobj, &vt8231_group_volts[i]); | 738 | sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_volts[i]); |
775 | 739 | ||
776 | for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) | 740 | for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) |
777 | sysfs_remove_group(&client->dev.kobj, &vt8231_group_temps[i]); | 741 | sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_temps[i]); |
742 | |||
743 | sysfs_remove_group(&pdev->dev.kobj, &vt8231_group); | ||
778 | 744 | ||
779 | sysfs_remove_group(&client->dev.kobj, &vt8231_group); | ||
780 | exit_detach: | ||
781 | i2c_detach_client(client); | ||
782 | exit_free: | 745 | exit_free: |
746 | platform_set_drvdata(pdev, NULL); | ||
783 | kfree(data); | 747 | kfree(data); |
748 | |||
784 | exit_release: | 749 | exit_release: |
785 | release_region(isa_address, VT8231_EXTENT); | 750 | release_region(res->start, VT8231_EXTENT); |
786 | return err; | 751 | return err; |
787 | } | 752 | } |
788 | 753 | ||
789 | static int vt8231_detach_client(struct i2c_client *client) | 754 | static int vt8231_remove(struct platform_device *pdev) |
790 | { | 755 | { |
791 | struct vt8231_data *data = i2c_get_clientdata(client); | 756 | struct vt8231_data *data = platform_get_drvdata(pdev); |
792 | int err, i; | 757 | int i; |
793 | 758 | ||
794 | hwmon_device_unregister(data->class_dev); | 759 | hwmon_device_unregister(data->class_dev); |
795 | 760 | ||
796 | for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) | 761 | for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) |
797 | sysfs_remove_group(&client->dev.kobj, &vt8231_group_volts[i]); | 762 | sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_volts[i]); |
798 | 763 | ||
799 | for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) | 764 | for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) |
800 | sysfs_remove_group(&client->dev.kobj, &vt8231_group_temps[i]); | 765 | sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_temps[i]); |
801 | 766 | ||
802 | sysfs_remove_group(&client->dev.kobj, &vt8231_group); | 767 | sysfs_remove_group(&pdev->dev.kobj, &vt8231_group); |
803 | 768 | ||
804 | if ((err = i2c_detach_client(client))) { | 769 | release_region(data->addr, VT8231_EXTENT); |
805 | return err; | 770 | platform_set_drvdata(pdev, NULL); |
806 | } | ||
807 | |||
808 | release_region(client->addr, VT8231_EXTENT); | ||
809 | kfree(data); | 771 | kfree(data); |
810 | |||
811 | return 0; | 772 | return 0; |
812 | } | 773 | } |
813 | 774 | ||
814 | static void vt8231_init_client(struct i2c_client *client) | 775 | static void vt8231_init_device(struct vt8231_data *data) |
815 | { | 776 | { |
816 | vt8231_write_value(client, VT8231_REG_TEMP1_CONFIG, 0); | 777 | vt8231_write_value(data, VT8231_REG_TEMP1_CONFIG, 0); |
817 | vt8231_write_value(client, VT8231_REG_TEMP2_CONFIG, 0); | 778 | vt8231_write_value(data, VT8231_REG_TEMP2_CONFIG, 0); |
818 | } | 779 | } |
819 | 780 | ||
820 | static struct vt8231_data *vt8231_update_device(struct device *dev) | 781 | static struct vt8231_data *vt8231_update_device(struct device *dev) |
821 | { | 782 | { |
822 | struct i2c_client *client = to_i2c_client(dev); | 783 | struct vt8231_data *data = dev_get_drvdata(dev); |
823 | struct vt8231_data *data = i2c_get_clientdata(client); | ||
824 | int i; | 784 | int i; |
825 | u16 low; | 785 | u16 low; |
826 | 786 | ||
@@ -830,41 +790,41 @@ static struct vt8231_data *vt8231_update_device(struct device *dev) | |||
830 | || !data->valid) { | 790 | || !data->valid) { |
831 | for (i = 0; i < 6; i++) { | 791 | for (i = 0; i < 6; i++) { |
832 | if (ISVOLT(i, data->uch_config)) { | 792 | if (ISVOLT(i, data->uch_config)) { |
833 | data->in[i] = vt8231_read_value(client, | 793 | data->in[i] = vt8231_read_value(data, |
834 | regvolt[i]); | 794 | regvolt[i]); |
835 | data->in_min[i] = vt8231_read_value(client, | 795 | data->in_min[i] = vt8231_read_value(data, |
836 | regvoltmin[i]); | 796 | regvoltmin[i]); |
837 | data->in_max[i] = vt8231_read_value(client, | 797 | data->in_max[i] = vt8231_read_value(data, |
838 | regvoltmax[i]); | 798 | regvoltmax[i]); |
839 | } | 799 | } |
840 | } | 800 | } |
841 | for (i = 0; i < 2; i++) { | 801 | for (i = 0; i < 2; i++) { |
842 | data->fan[i] = vt8231_read_value(client, | 802 | data->fan[i] = vt8231_read_value(data, |
843 | VT8231_REG_FAN(i)); | 803 | VT8231_REG_FAN(i)); |
844 | data->fan_min[i] = vt8231_read_value(client, | 804 | data->fan_min[i] = vt8231_read_value(data, |
845 | VT8231_REG_FAN_MIN(i)); | 805 | VT8231_REG_FAN_MIN(i)); |
846 | } | 806 | } |
847 | 807 | ||
848 | low = vt8231_read_value(client, VT8231_REG_TEMP_LOW01); | 808 | low = vt8231_read_value(data, VT8231_REG_TEMP_LOW01); |
849 | low = (low >> 6) | ((low & 0x30) >> 2) | 809 | low = (low >> 6) | ((low & 0x30) >> 2) |
850 | | (vt8231_read_value(client, VT8231_REG_TEMP_LOW25) << 4); | 810 | | (vt8231_read_value(data, VT8231_REG_TEMP_LOW25) << 4); |
851 | for (i = 0; i < 6; i++) { | 811 | for (i = 0; i < 6; i++) { |
852 | if (ISTEMP(i, data->uch_config)) { | 812 | if (ISTEMP(i, data->uch_config)) { |
853 | data->temp[i] = (vt8231_read_value(client, | 813 | data->temp[i] = (vt8231_read_value(data, |
854 | regtemp[i]) << 2) | 814 | regtemp[i]) << 2) |
855 | | ((low >> (2 * i)) & 0x03); | 815 | | ((low >> (2 * i)) & 0x03); |
856 | data->temp_max[i] = vt8231_read_value(client, | 816 | data->temp_max[i] = vt8231_read_value(data, |
857 | regtempmax[i]); | 817 | regtempmax[i]); |
858 | data->temp_min[i] = vt8231_read_value(client, | 818 | data->temp_min[i] = vt8231_read_value(data, |
859 | regtempmin[i]); | 819 | regtempmin[i]); |
860 | } | 820 | } |
861 | } | 821 | } |
862 | 822 | ||
863 | i = vt8231_read_value(client, VT8231_REG_FANDIV); | 823 | i = vt8231_read_value(data, VT8231_REG_FANDIV); |
864 | data->fan_div[0] = (i >> 4) & 0x03; | 824 | data->fan_div[0] = (i >> 4) & 0x03; |
865 | data->fan_div[1] = i >> 6; | 825 | data->fan_div[1] = i >> 6; |
866 | data->alarms = vt8231_read_value(client, VT8231_REG_ALARM1) | | 826 | data->alarms = vt8231_read_value(data, VT8231_REG_ALARM1) | |
867 | (vt8231_read_value(client, VT8231_REG_ALARM2) << 8); | 827 | (vt8231_read_value(data, VT8231_REG_ALARM2) << 8); |
868 | 828 | ||
869 | /* Set alarm flags correctly */ | 829 | /* Set alarm flags correctly */ |
870 | if (!data->fan[0] && data->fan_min[0]) { | 830 | if (!data->fan[0] && data->fan_min[0]) { |
@@ -888,33 +848,102 @@ static struct vt8231_data *vt8231_update_device(struct device *dev) | |||
888 | return data; | 848 | return data; |
889 | } | 849 | } |
890 | 850 | ||
851 | static int __devinit vt8231_device_add(unsigned short address) | ||
852 | { | ||
853 | struct resource res = { | ||
854 | .start = address, | ||
855 | .end = address + VT8231_EXTENT - 1, | ||
856 | .name = "vt8231", | ||
857 | .flags = IORESOURCE_IO, | ||
858 | }; | ||
859 | int err; | ||
860 | |||
861 | pdev = platform_device_alloc("vt8231", address); | ||
862 | if (!pdev) { | ||
863 | err = -ENOMEM; | ||
864 | printk(KERN_ERR "vt8231: Device allocation failed\n"); | ||
865 | goto exit; | ||
866 | } | ||
867 | |||
868 | err = platform_device_add_resources(pdev, &res, 1); | ||
869 | if (err) { | ||
870 | printk(KERN_ERR "vt8231: Device resource addition failed " | ||
871 | "(%d)\n", err); | ||
872 | goto exit_device_put; | ||
873 | } | ||
874 | |||
875 | err = platform_device_add(pdev); | ||
876 | if (err) { | ||
877 | printk(KERN_ERR "vt8231: Device addition failed (%d)\n", | ||
878 | err); | ||
879 | goto exit_device_put; | ||
880 | } | ||
881 | |||
882 | return 0; | ||
883 | |||
884 | exit_device_put: | ||
885 | platform_device_put(pdev); | ||
886 | exit: | ||
887 | return err; | ||
888 | } | ||
889 | |||
891 | static int __devinit vt8231_pci_probe(struct pci_dev *dev, | 890 | static int __devinit vt8231_pci_probe(struct pci_dev *dev, |
892 | const struct pci_device_id *id) | 891 | const struct pci_device_id *id) |
893 | { | 892 | { |
894 | u16 val; | 893 | u16 address, val; |
894 | if (force_addr) { | ||
895 | address = force_addr & 0xff00; | ||
896 | dev_warn(&dev->dev, "Forcing ISA address 0x%x\n", | ||
897 | address); | ||
898 | |||
899 | if (PCIBIOS_SUCCESSFUL != | ||
900 | pci_write_config_word(dev, VT8231_BASE_REG, address | 1)) | ||
901 | return -ENODEV; | ||
902 | } | ||
895 | 903 | ||
896 | if (PCIBIOS_SUCCESSFUL != pci_read_config_word(dev, VT8231_BASE_REG, | 904 | if (PCIBIOS_SUCCESSFUL != pci_read_config_word(dev, VT8231_BASE_REG, |
897 | &val)) | 905 | &val)) |
898 | return -ENODEV; | 906 | return -ENODEV; |
899 | 907 | ||
900 | isa_address = val & ~(VT8231_EXTENT - 1); | 908 | address = val & ~(VT8231_EXTENT - 1); |
901 | if (isa_address == 0 && force_addr == 0) { | 909 | if (address == 0) { |
902 | dev_err(&dev->dev, "base address not set -\ | 910 | dev_err(&dev->dev, "base address not set -\ |
903 | upgrade BIOS or use force_addr=0xaddr\n"); | 911 | upgrade BIOS or use force_addr=0xaddr\n"); |
904 | return -ENODEV; | 912 | return -ENODEV; |
905 | } | 913 | } |
906 | 914 | ||
907 | s_bridge = pci_dev_get(dev); | 915 | if (PCIBIOS_SUCCESSFUL != pci_read_config_word(dev, VT8231_ENABLE_REG, |
916 | &val)) | ||
917 | return -ENODEV; | ||
908 | 918 | ||
909 | if (i2c_isa_add_driver(&vt8231_driver)) { | 919 | if (!(val & 0x0001)) { |
910 | pci_dev_put(s_bridge); | 920 | dev_warn(&dev->dev, "enabling sensors\n"); |
911 | s_bridge = NULL; | 921 | if (PCIBIOS_SUCCESSFUL != |
922 | pci_write_config_word(dev, VT8231_ENABLE_REG, | ||
923 | val | 0x0001)) | ||
924 | return -ENODEV; | ||
912 | } | 925 | } |
913 | 926 | ||
927 | if (platform_driver_register(&vt8231_driver)) | ||
928 | goto exit; | ||
929 | |||
930 | /* Sets global pdev as a side effect */ | ||
931 | if (vt8231_device_add(address)) | ||
932 | goto exit_unregister; | ||
933 | |||
914 | /* Always return failure here. This is to allow other drivers to bind | 934 | /* Always return failure here. This is to allow other drivers to bind |
915 | * to this pci device. We don't really want to have control over the | 935 | * to this pci device. We don't really want to have control over the |
916 | * pci device, we only wanted to read as few register values from it. | 936 | * pci device, we only wanted to read as few register values from it. |
917 | */ | 937 | */ |
938 | |||
939 | /* We do, however, mark ourselves as using the PCI device to stop it | ||
940 | getting unloaded. */ | ||
941 | s_bridge = pci_dev_get(dev); | ||
942 | return -ENODEV; | ||
943 | |||
944 | exit_unregister: | ||
945 | platform_driver_unregister(&vt8231_driver); | ||
946 | exit: | ||
918 | return -ENODEV; | 947 | return -ENODEV; |
919 | } | 948 | } |
920 | 949 | ||
@@ -927,7 +956,8 @@ static void __exit sm_vt8231_exit(void) | |||
927 | { | 956 | { |
928 | pci_unregister_driver(&vt8231_pci_driver); | 957 | pci_unregister_driver(&vt8231_pci_driver); |
929 | if (s_bridge != NULL) { | 958 | if (s_bridge != NULL) { |
930 | i2c_isa_del_driver(&vt8231_driver); | 959 | platform_device_unregister(pdev); |
960 | platform_driver_unregister(&vt8231_driver); | ||
931 | pci_dev_put(s_bridge); | 961 | pci_dev_put(s_bridge); |
932 | s_bridge = NULL; | 962 | s_bridge = NULL; |
933 | } | 963 | } |
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c index 30a76404f0af..c51ae2e17758 100644 --- a/drivers/hwmon/w83627ehf.c +++ b/drivers/hwmon/w83627ehf.c | |||
@@ -41,41 +41,39 @@ | |||
41 | #include <linux/module.h> | 41 | #include <linux/module.h> |
42 | #include <linux/init.h> | 42 | #include <linux/init.h> |
43 | #include <linux/slab.h> | 43 | #include <linux/slab.h> |
44 | #include <linux/i2c.h> | 44 | #include <linux/jiffies.h> |
45 | #include <linux/i2c-isa.h> | 45 | #include <linux/platform_device.h> |
46 | #include <linux/hwmon.h> | 46 | #include <linux/hwmon.h> |
47 | #include <linux/hwmon-sysfs.h> | 47 | #include <linux/hwmon-sysfs.h> |
48 | #include <linux/hwmon-vid.h> | ||
48 | #include <linux/err.h> | 49 | #include <linux/err.h> |
49 | #include <linux/mutex.h> | 50 | #include <linux/mutex.h> |
50 | #include <asm/io.h> | 51 | #include <asm/io.h> |
51 | #include "lm75.h" | 52 | #include "lm75.h" |
52 | 53 | ||
53 | /* The actual ISA address is read from Super-I/O configuration space */ | 54 | enum kinds { w83627ehf, w83627dhg }; |
54 | static unsigned short address; | ||
55 | 55 | ||
56 | /* | 56 | /* used to set data->name = w83627ehf_device_names[data->sio_kind] */ |
57 | * Super-I/O constants and functions | 57 | static const char * w83627ehf_device_names[] = { |
58 | */ | 58 | "w83627ehf", |
59 | "w83627dhg", | ||
60 | }; | ||
61 | |||
62 | #define DRVNAME "w83627ehf" | ||
59 | 63 | ||
60 | /* | 64 | /* |
61 | * The three following globals are initialized in w83627ehf_find(), before | 65 | * Super-I/O constants and functions |
62 | * the i2c-isa device is created. Otherwise, they could be stored in | ||
63 | * w83627ehf_data. This is ugly, but necessary, and when the driver is next | ||
64 | * updated to become a platform driver, the globals will disappear. | ||
65 | */ | 66 | */ |
66 | static int REG; /* The register to read/write */ | ||
67 | static int VAL; /* The value to read/write */ | ||
68 | /* The w83627ehf/ehg have 10 voltage inputs, but the w83627dhg has 9. This | ||
69 | * value is also used in w83627ehf_detect() to export a device name in sysfs | ||
70 | * (e.g. w83627ehf or w83627dhg) */ | ||
71 | static int w83627ehf_num_in; | ||
72 | 67 | ||
73 | #define W83627EHF_LD_HWM 0x0b | 68 | #define W83627EHF_LD_HWM 0x0b |
74 | 69 | ||
75 | #define SIO_REG_LDSEL 0x07 /* Logical device select */ | 70 | #define SIO_REG_LDSEL 0x07 /* Logical device select */ |
76 | #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */ | 71 | #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */ |
72 | #define SIO_REG_EN_VRM10 0x2C /* GPIO3, GPIO4 selection */ | ||
77 | #define SIO_REG_ENABLE 0x30 /* Logical device enable */ | 73 | #define SIO_REG_ENABLE 0x30 /* Logical device enable */ |
78 | #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */ | 74 | #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */ |
75 | #define SIO_REG_VID_CTRL 0xF0 /* VID control */ | ||
76 | #define SIO_REG_VID_DATA 0xF1 /* VID data */ | ||
79 | 77 | ||
80 | #define SIO_W83627EHF_ID 0x8850 | 78 | #define SIO_W83627EHF_ID 0x8850 |
81 | #define SIO_W83627EHG_ID 0x8860 | 79 | #define SIO_W83627EHG_ID 0x8860 |
@@ -83,38 +81,38 @@ static int w83627ehf_num_in; | |||
83 | #define SIO_ID_MASK 0xFFF0 | 81 | #define SIO_ID_MASK 0xFFF0 |
84 | 82 | ||
85 | static inline void | 83 | static inline void |
86 | superio_outb(int reg, int val) | 84 | superio_outb(int ioreg, int reg, int val) |
87 | { | 85 | { |
88 | outb(reg, REG); | 86 | outb(reg, ioreg); |
89 | outb(val, VAL); | 87 | outb(val, ioreg + 1); |
90 | } | 88 | } |
91 | 89 | ||
92 | static inline int | 90 | static inline int |
93 | superio_inb(int reg) | 91 | superio_inb(int ioreg, int reg) |
94 | { | 92 | { |
95 | outb(reg, REG); | 93 | outb(reg, ioreg); |
96 | return inb(VAL); | 94 | return inb(ioreg + 1); |
97 | } | 95 | } |
98 | 96 | ||
99 | static inline void | 97 | static inline void |
100 | superio_select(int ld) | 98 | superio_select(int ioreg, int ld) |
101 | { | 99 | { |
102 | outb(SIO_REG_LDSEL, REG); | 100 | outb(SIO_REG_LDSEL, ioreg); |
103 | outb(ld, VAL); | 101 | outb(ld, ioreg + 1); |
104 | } | 102 | } |
105 | 103 | ||
106 | static inline void | 104 | static inline void |
107 | superio_enter(void) | 105 | superio_enter(int ioreg) |
108 | { | 106 | { |
109 | outb(0x87, REG); | 107 | outb(0x87, ioreg); |
110 | outb(0x87, REG); | 108 | outb(0x87, ioreg); |
111 | } | 109 | } |
112 | 110 | ||
113 | static inline void | 111 | static inline void |
114 | superio_exit(void) | 112 | superio_exit(int ioreg) |
115 | { | 113 | { |
116 | outb(0x02, REG); | 114 | outb(0x02, ioreg); |
117 | outb(0x02, VAL); | 115 | outb(0x02, ioreg + 1); |
118 | } | 116 | } |
119 | 117 | ||
120 | /* | 118 | /* |
@@ -124,8 +122,8 @@ superio_exit(void) | |||
124 | #define IOREGION_ALIGNMENT ~7 | 122 | #define IOREGION_ALIGNMENT ~7 |
125 | #define IOREGION_OFFSET 5 | 123 | #define IOREGION_OFFSET 5 |
126 | #define IOREGION_LENGTH 2 | 124 | #define IOREGION_LENGTH 2 |
127 | #define ADDR_REG_OFFSET 5 | 125 | #define ADDR_REG_OFFSET 0 |
128 | #define DATA_REG_OFFSET 6 | 126 | #define DATA_REG_OFFSET 1 |
129 | 127 | ||
130 | #define W83627EHF_REG_BANK 0x4E | 128 | #define W83627EHF_REG_BANK 0x4E |
131 | #define W83627EHF_REG_CONFIG 0x40 | 129 | #define W83627EHF_REG_CONFIG 0x40 |
@@ -255,7 +253,9 @@ static inline u8 in_to_reg(u32 val, u8 nr) | |||
255 | */ | 253 | */ |
256 | 254 | ||
257 | struct w83627ehf_data { | 255 | struct w83627ehf_data { |
258 | struct i2c_client client; | 256 | int addr; /* IO base of hw monitor block */ |
257 | const char *name; | ||
258 | |||
259 | struct class_device *class_dev; | 259 | struct class_device *class_dev; |
260 | struct mutex lock; | 260 | struct mutex lock; |
261 | 261 | ||
@@ -264,6 +264,7 @@ struct w83627ehf_data { | |||
264 | unsigned long last_updated; /* In jiffies */ | 264 | unsigned long last_updated; /* In jiffies */ |
265 | 265 | ||
266 | /* Register values */ | 266 | /* Register values */ |
267 | u8 in_num; /* number of in inputs we have */ | ||
267 | u8 in[10]; /* Register value */ | 268 | u8 in[10]; /* Register value */ |
268 | u8 in_max[10]; /* Register value */ | 269 | u8 in_max[10]; /* Register value */ |
269 | u8 in_min[10]; /* Register value */ | 270 | u8 in_min[10]; /* Register value */ |
@@ -271,6 +272,7 @@ struct w83627ehf_data { | |||
271 | u8 fan_min[5]; | 272 | u8 fan_min[5]; |
272 | u8 fan_div[5]; | 273 | u8 fan_div[5]; |
273 | u8 has_fan; /* some fan inputs can be disabled */ | 274 | u8 has_fan; /* some fan inputs can be disabled */ |
275 | u8 temp_type[3]; | ||
274 | s8 temp1; | 276 | s8 temp1; |
275 | s8 temp1_max; | 277 | s8 temp1_max; |
276 | s8 temp1_max_hyst; | 278 | s8 temp1_max_hyst; |
@@ -288,6 +290,14 @@ struct w83627ehf_data { | |||
288 | 290 | ||
289 | u8 fan_min_output[4]; /* minimum fan speed */ | 291 | u8 fan_min_output[4]; /* minimum fan speed */ |
290 | u8 fan_stop_time[4]; | 292 | u8 fan_stop_time[4]; |
293 | |||
294 | u8 vid; | ||
295 | u8 vrm; | ||
296 | }; | ||
297 | |||
298 | struct w83627ehf_sio_data { | ||
299 | int sioreg; | ||
300 | enum kinds kind; | ||
291 | }; | 301 | }; |
292 | 302 | ||
293 | static inline int is_word_sized(u16 reg) | 303 | static inline int is_word_sized(u16 reg) |
@@ -303,156 +313,152 @@ static inline int is_word_sized(u16 reg) | |||
303 | nothing for registers which live in bank 0. For others, they respectively | 313 | nothing for registers which live in bank 0. For others, they respectively |
304 | set the bank register to the correct value (before the register is | 314 | set the bank register to the correct value (before the register is |
305 | accessed), and back to 0 (afterwards). */ | 315 | accessed), and back to 0 (afterwards). */ |
306 | static inline void w83627ehf_set_bank(struct i2c_client *client, u16 reg) | 316 | static inline void w83627ehf_set_bank(struct w83627ehf_data *data, u16 reg) |
307 | { | 317 | { |
308 | if (reg & 0xff00) { | 318 | if (reg & 0xff00) { |
309 | outb_p(W83627EHF_REG_BANK, client->addr + ADDR_REG_OFFSET); | 319 | outb_p(W83627EHF_REG_BANK, data->addr + ADDR_REG_OFFSET); |
310 | outb_p(reg >> 8, client->addr + DATA_REG_OFFSET); | 320 | outb_p(reg >> 8, data->addr + DATA_REG_OFFSET); |
311 | } | 321 | } |
312 | } | 322 | } |
313 | 323 | ||
314 | static inline void w83627ehf_reset_bank(struct i2c_client *client, u16 reg) | 324 | static inline void w83627ehf_reset_bank(struct w83627ehf_data *data, u16 reg) |
315 | { | 325 | { |
316 | if (reg & 0xff00) { | 326 | if (reg & 0xff00) { |
317 | outb_p(W83627EHF_REG_BANK, client->addr + ADDR_REG_OFFSET); | 327 | outb_p(W83627EHF_REG_BANK, data->addr + ADDR_REG_OFFSET); |
318 | outb_p(0, client->addr + DATA_REG_OFFSET); | 328 | outb_p(0, data->addr + DATA_REG_OFFSET); |
319 | } | 329 | } |
320 | } | 330 | } |
321 | 331 | ||
322 | static u16 w83627ehf_read_value(struct i2c_client *client, u16 reg) | 332 | static u16 w83627ehf_read_value(struct w83627ehf_data *data, u16 reg) |
323 | { | 333 | { |
324 | struct w83627ehf_data *data = i2c_get_clientdata(client); | ||
325 | int res, word_sized = is_word_sized(reg); | 334 | int res, word_sized = is_word_sized(reg); |
326 | 335 | ||
327 | mutex_lock(&data->lock); | 336 | mutex_lock(&data->lock); |
328 | 337 | ||
329 | w83627ehf_set_bank(client, reg); | 338 | w83627ehf_set_bank(data, reg); |
330 | outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET); | 339 | outb_p(reg & 0xff, data->addr + ADDR_REG_OFFSET); |
331 | res = inb_p(client->addr + DATA_REG_OFFSET); | 340 | res = inb_p(data->addr + DATA_REG_OFFSET); |
332 | if (word_sized) { | 341 | if (word_sized) { |
333 | outb_p((reg & 0xff) + 1, | 342 | outb_p((reg & 0xff) + 1, |
334 | client->addr + ADDR_REG_OFFSET); | 343 | data->addr + ADDR_REG_OFFSET); |
335 | res = (res << 8) + inb_p(client->addr + DATA_REG_OFFSET); | 344 | res = (res << 8) + inb_p(data->addr + DATA_REG_OFFSET); |
336 | } | 345 | } |
337 | w83627ehf_reset_bank(client, reg); | 346 | w83627ehf_reset_bank(data, reg); |
338 | 347 | ||
339 | mutex_unlock(&data->lock); | 348 | mutex_unlock(&data->lock); |
340 | 349 | ||
341 | return res; | 350 | return res; |
342 | } | 351 | } |
343 | 352 | ||
344 | static int w83627ehf_write_value(struct i2c_client *client, u16 reg, u16 value) | 353 | static int w83627ehf_write_value(struct w83627ehf_data *data, u16 reg, u16 value) |
345 | { | 354 | { |
346 | struct w83627ehf_data *data = i2c_get_clientdata(client); | ||
347 | int word_sized = is_word_sized(reg); | 355 | int word_sized = is_word_sized(reg); |
348 | 356 | ||
349 | mutex_lock(&data->lock); | 357 | mutex_lock(&data->lock); |
350 | 358 | ||
351 | w83627ehf_set_bank(client, reg); | 359 | w83627ehf_set_bank(data, reg); |
352 | outb_p(reg & 0xff, client->addr + ADDR_REG_OFFSET); | 360 | outb_p(reg & 0xff, data->addr + ADDR_REG_OFFSET); |
353 | if (word_sized) { | 361 | if (word_sized) { |
354 | outb_p(value >> 8, client->addr + DATA_REG_OFFSET); | 362 | outb_p(value >> 8, data->addr + DATA_REG_OFFSET); |
355 | outb_p((reg & 0xff) + 1, | 363 | outb_p((reg & 0xff) + 1, |
356 | client->addr + ADDR_REG_OFFSET); | 364 | data->addr + ADDR_REG_OFFSET); |
357 | } | 365 | } |
358 | outb_p(value & 0xff, client->addr + DATA_REG_OFFSET); | 366 | outb_p(value & 0xff, data->addr + DATA_REG_OFFSET); |
359 | w83627ehf_reset_bank(client, reg); | 367 | w83627ehf_reset_bank(data, reg); |
360 | 368 | ||
361 | mutex_unlock(&data->lock); | 369 | mutex_unlock(&data->lock); |
362 | return 0; | 370 | return 0; |
363 | } | 371 | } |
364 | 372 | ||
365 | /* This function assumes that the caller holds data->update_lock */ | 373 | /* This function assumes that the caller holds data->update_lock */ |
366 | static void w83627ehf_write_fan_div(struct i2c_client *client, int nr) | 374 | static void w83627ehf_write_fan_div(struct w83627ehf_data *data, int nr) |
367 | { | 375 | { |
368 | struct w83627ehf_data *data = i2c_get_clientdata(client); | ||
369 | u8 reg; | 376 | u8 reg; |
370 | 377 | ||
371 | switch (nr) { | 378 | switch (nr) { |
372 | case 0: | 379 | case 0: |
373 | reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV1) & 0xcf) | 380 | reg = (w83627ehf_read_value(data, W83627EHF_REG_FANDIV1) & 0xcf) |
374 | | ((data->fan_div[0] & 0x03) << 4); | 381 | | ((data->fan_div[0] & 0x03) << 4); |
375 | /* fan5 input control bit is write only, compute the value */ | 382 | /* fan5 input control bit is write only, compute the value */ |
376 | reg |= (data->has_fan & (1 << 4)) ? 1 : 0; | 383 | reg |= (data->has_fan & (1 << 4)) ? 1 : 0; |
377 | w83627ehf_write_value(client, W83627EHF_REG_FANDIV1, reg); | 384 | w83627ehf_write_value(data, W83627EHF_REG_FANDIV1, reg); |
378 | reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0xdf) | 385 | reg = (w83627ehf_read_value(data, W83627EHF_REG_VBAT) & 0xdf) |
379 | | ((data->fan_div[0] & 0x04) << 3); | 386 | | ((data->fan_div[0] & 0x04) << 3); |
380 | w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg); | 387 | w83627ehf_write_value(data, W83627EHF_REG_VBAT, reg); |
381 | break; | 388 | break; |
382 | case 1: | 389 | case 1: |
383 | reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV1) & 0x3f) | 390 | reg = (w83627ehf_read_value(data, W83627EHF_REG_FANDIV1) & 0x3f) |
384 | | ((data->fan_div[1] & 0x03) << 6); | 391 | | ((data->fan_div[1] & 0x03) << 6); |
385 | /* fan5 input control bit is write only, compute the value */ | 392 | /* fan5 input control bit is write only, compute the value */ |
386 | reg |= (data->has_fan & (1 << 4)) ? 1 : 0; | 393 | reg |= (data->has_fan & (1 << 4)) ? 1 : 0; |
387 | w83627ehf_write_value(client, W83627EHF_REG_FANDIV1, reg); | 394 | w83627ehf_write_value(data, W83627EHF_REG_FANDIV1, reg); |
388 | reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0xbf) | 395 | reg = (w83627ehf_read_value(data, W83627EHF_REG_VBAT) & 0xbf) |
389 | | ((data->fan_div[1] & 0x04) << 4); | 396 | | ((data->fan_div[1] & 0x04) << 4); |
390 | w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg); | 397 | w83627ehf_write_value(data, W83627EHF_REG_VBAT, reg); |
391 | break; | 398 | break; |
392 | case 2: | 399 | case 2: |
393 | reg = (w83627ehf_read_value(client, W83627EHF_REG_FANDIV2) & 0x3f) | 400 | reg = (w83627ehf_read_value(data, W83627EHF_REG_FANDIV2) & 0x3f) |
394 | | ((data->fan_div[2] & 0x03) << 6); | 401 | | ((data->fan_div[2] & 0x03) << 6); |
395 | w83627ehf_write_value(client, W83627EHF_REG_FANDIV2, reg); | 402 | w83627ehf_write_value(data, W83627EHF_REG_FANDIV2, reg); |
396 | reg = (w83627ehf_read_value(client, W83627EHF_REG_VBAT) & 0x7f) | 403 | reg = (w83627ehf_read_value(data, W83627EHF_REG_VBAT) & 0x7f) |
397 | | ((data->fan_div[2] & 0x04) << 5); | 404 | | ((data->fan_div[2] & 0x04) << 5); |
398 | w83627ehf_write_value(client, W83627EHF_REG_VBAT, reg); | 405 | w83627ehf_write_value(data, W83627EHF_REG_VBAT, reg); |
399 | break; | 406 | break; |
400 | case 3: | 407 | case 3: |
401 | reg = (w83627ehf_read_value(client, W83627EHF_REG_DIODE) & 0xfc) | 408 | reg = (w83627ehf_read_value(data, W83627EHF_REG_DIODE) & 0xfc) |
402 | | (data->fan_div[3] & 0x03); | 409 | | (data->fan_div[3] & 0x03); |
403 | w83627ehf_write_value(client, W83627EHF_REG_DIODE, reg); | 410 | w83627ehf_write_value(data, W83627EHF_REG_DIODE, reg); |
404 | reg = (w83627ehf_read_value(client, W83627EHF_REG_SMI_OVT) & 0x7f) | 411 | reg = (w83627ehf_read_value(data, W83627EHF_REG_SMI_OVT) & 0x7f) |
405 | | ((data->fan_div[3] & 0x04) << 5); | 412 | | ((data->fan_div[3] & 0x04) << 5); |
406 | w83627ehf_write_value(client, W83627EHF_REG_SMI_OVT, reg); | 413 | w83627ehf_write_value(data, W83627EHF_REG_SMI_OVT, reg); |
407 | break; | 414 | break; |
408 | case 4: | 415 | case 4: |
409 | reg = (w83627ehf_read_value(client, W83627EHF_REG_DIODE) & 0x73) | 416 | reg = (w83627ehf_read_value(data, W83627EHF_REG_DIODE) & 0x73) |
410 | | ((data->fan_div[4] & 0x03) << 2) | 417 | | ((data->fan_div[4] & 0x03) << 2) |
411 | | ((data->fan_div[4] & 0x04) << 5); | 418 | | ((data->fan_div[4] & 0x04) << 5); |
412 | w83627ehf_write_value(client, W83627EHF_REG_DIODE, reg); | 419 | w83627ehf_write_value(data, W83627EHF_REG_DIODE, reg); |
413 | break; | 420 | break; |
414 | } | 421 | } |
415 | } | 422 | } |
416 | 423 | ||
417 | static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) | 424 | static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) |
418 | { | 425 | { |
419 | struct i2c_client *client = to_i2c_client(dev); | 426 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
420 | struct w83627ehf_data *data = i2c_get_clientdata(client); | ||
421 | int pwmcfg = 0, tolerance = 0; /* shut up the compiler */ | 427 | int pwmcfg = 0, tolerance = 0; /* shut up the compiler */ |
422 | int i; | 428 | int i; |
423 | 429 | ||
424 | mutex_lock(&data->update_lock); | 430 | mutex_lock(&data->update_lock); |
425 | 431 | ||
426 | if (time_after(jiffies, data->last_updated + HZ) | 432 | if (time_after(jiffies, data->last_updated + HZ + HZ/2) |
427 | || !data->valid) { | 433 | || !data->valid) { |
428 | /* Fan clock dividers */ | 434 | /* Fan clock dividers */ |
429 | i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV1); | 435 | i = w83627ehf_read_value(data, W83627EHF_REG_FANDIV1); |
430 | data->fan_div[0] = (i >> 4) & 0x03; | 436 | data->fan_div[0] = (i >> 4) & 0x03; |
431 | data->fan_div[1] = (i >> 6) & 0x03; | 437 | data->fan_div[1] = (i >> 6) & 0x03; |
432 | i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV2); | 438 | i = w83627ehf_read_value(data, W83627EHF_REG_FANDIV2); |
433 | data->fan_div[2] = (i >> 6) & 0x03; | 439 | data->fan_div[2] = (i >> 6) & 0x03; |
434 | i = w83627ehf_read_value(client, W83627EHF_REG_VBAT); | 440 | i = w83627ehf_read_value(data, W83627EHF_REG_VBAT); |
435 | data->fan_div[0] |= (i >> 3) & 0x04; | 441 | data->fan_div[0] |= (i >> 3) & 0x04; |
436 | data->fan_div[1] |= (i >> 4) & 0x04; | 442 | data->fan_div[1] |= (i >> 4) & 0x04; |
437 | data->fan_div[2] |= (i >> 5) & 0x04; | 443 | data->fan_div[2] |= (i >> 5) & 0x04; |
438 | if (data->has_fan & ((1 << 3) | (1 << 4))) { | 444 | if (data->has_fan & ((1 << 3) | (1 << 4))) { |
439 | i = w83627ehf_read_value(client, W83627EHF_REG_DIODE); | 445 | i = w83627ehf_read_value(data, W83627EHF_REG_DIODE); |
440 | data->fan_div[3] = i & 0x03; | 446 | data->fan_div[3] = i & 0x03; |
441 | data->fan_div[4] = ((i >> 2) & 0x03) | 447 | data->fan_div[4] = ((i >> 2) & 0x03) |
442 | | ((i >> 5) & 0x04); | 448 | | ((i >> 5) & 0x04); |
443 | } | 449 | } |
444 | if (data->has_fan & (1 << 3)) { | 450 | if (data->has_fan & (1 << 3)) { |
445 | i = w83627ehf_read_value(client, W83627EHF_REG_SMI_OVT); | 451 | i = w83627ehf_read_value(data, W83627EHF_REG_SMI_OVT); |
446 | data->fan_div[3] |= (i >> 5) & 0x04; | 452 | data->fan_div[3] |= (i >> 5) & 0x04; |
447 | } | 453 | } |
448 | 454 | ||
449 | /* Measured voltages and limits */ | 455 | /* Measured voltages and limits */ |
450 | for (i = 0; i < w83627ehf_num_in; i++) { | 456 | for (i = 0; i < data->in_num; i++) { |
451 | data->in[i] = w83627ehf_read_value(client, | 457 | data->in[i] = w83627ehf_read_value(data, |
452 | W83627EHF_REG_IN(i)); | 458 | W83627EHF_REG_IN(i)); |
453 | data->in_min[i] = w83627ehf_read_value(client, | 459 | data->in_min[i] = w83627ehf_read_value(data, |
454 | W83627EHF_REG_IN_MIN(i)); | 460 | W83627EHF_REG_IN_MIN(i)); |
455 | data->in_max[i] = w83627ehf_read_value(client, | 461 | data->in_max[i] = w83627ehf_read_value(data, |
456 | W83627EHF_REG_IN_MAX(i)); | 462 | W83627EHF_REG_IN_MAX(i)); |
457 | } | 463 | } |
458 | 464 | ||
@@ -461,9 +467,9 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) | |||
461 | if (!(data->has_fan & (1 << i))) | 467 | if (!(data->has_fan & (1 << i))) |
462 | continue; | 468 | continue; |
463 | 469 | ||
464 | data->fan[i] = w83627ehf_read_value(client, | 470 | data->fan[i] = w83627ehf_read_value(data, |
465 | W83627EHF_REG_FAN[i]); | 471 | W83627EHF_REG_FAN[i]); |
466 | data->fan_min[i] = w83627ehf_read_value(client, | 472 | data->fan_min[i] = w83627ehf_read_value(data, |
467 | W83627EHF_REG_FAN_MIN[i]); | 473 | W83627EHF_REG_FAN_MIN[i]); |
468 | 474 | ||
469 | /* If we failed to measure the fan speed and clock | 475 | /* If we failed to measure the fan speed and clock |
@@ -471,16 +477,16 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) | |||
471 | time */ | 477 | time */ |
472 | if (data->fan[i] == 0xff | 478 | if (data->fan[i] == 0xff |
473 | && data->fan_div[i] < 0x07) { | 479 | && data->fan_div[i] < 0x07) { |
474 | dev_dbg(&client->dev, "Increasing fan%d " | 480 | dev_dbg(dev, "Increasing fan%d " |
475 | "clock divider from %u to %u\n", | 481 | "clock divider from %u to %u\n", |
476 | i + 1, div_from_reg(data->fan_div[i]), | 482 | i + 1, div_from_reg(data->fan_div[i]), |
477 | div_from_reg(data->fan_div[i] + 1)); | 483 | div_from_reg(data->fan_div[i] + 1)); |
478 | data->fan_div[i]++; | 484 | data->fan_div[i]++; |
479 | w83627ehf_write_fan_div(client, i); | 485 | w83627ehf_write_fan_div(data, i); |
480 | /* Preserve min limit if possible */ | 486 | /* Preserve min limit if possible */ |
481 | if (data->fan_min[i] >= 2 | 487 | if (data->fan_min[i] >= 2 |
482 | && data->fan_min[i] != 255) | 488 | && data->fan_min[i] != 255) |
483 | w83627ehf_write_value(client, | 489 | w83627ehf_write_value(data, |
484 | W83627EHF_REG_FAN_MIN[i], | 490 | W83627EHF_REG_FAN_MIN[i], |
485 | (data->fan_min[i] /= 2)); | 491 | (data->fan_min[i] /= 2)); |
486 | } | 492 | } |
@@ -489,9 +495,9 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) | |||
489 | for (i = 0; i < 4; i++) { | 495 | for (i = 0; i < 4; i++) { |
490 | /* pwmcfg, tolarance mapped for i=0, i=1 to same reg */ | 496 | /* pwmcfg, tolarance mapped for i=0, i=1 to same reg */ |
491 | if (i != 1) { | 497 | if (i != 1) { |
492 | pwmcfg = w83627ehf_read_value(client, | 498 | pwmcfg = w83627ehf_read_value(data, |
493 | W83627EHF_REG_PWM_ENABLE[i]); | 499 | W83627EHF_REG_PWM_ENABLE[i]); |
494 | tolerance = w83627ehf_read_value(client, | 500 | tolerance = w83627ehf_read_value(data, |
495 | W83627EHF_REG_TOLERANCE[i]); | 501 | W83627EHF_REG_TOLERANCE[i]); |
496 | } | 502 | } |
497 | data->pwm_mode[i] = | 503 | data->pwm_mode[i] = |
@@ -500,14 +506,14 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) | |||
500 | data->pwm_enable[i] = | 506 | data->pwm_enable[i] = |
501 | ((pwmcfg >> W83627EHF_PWM_ENABLE_SHIFT[i]) | 507 | ((pwmcfg >> W83627EHF_PWM_ENABLE_SHIFT[i]) |
502 | & 3) + 1; | 508 | & 3) + 1; |
503 | data->pwm[i] = w83627ehf_read_value(client, | 509 | data->pwm[i] = w83627ehf_read_value(data, |
504 | W83627EHF_REG_PWM[i]); | 510 | W83627EHF_REG_PWM[i]); |
505 | data->fan_min_output[i] = w83627ehf_read_value(client, | 511 | data->fan_min_output[i] = w83627ehf_read_value(data, |
506 | W83627EHF_REG_FAN_MIN_OUTPUT[i]); | 512 | W83627EHF_REG_FAN_MIN_OUTPUT[i]); |
507 | data->fan_stop_time[i] = w83627ehf_read_value(client, | 513 | data->fan_stop_time[i] = w83627ehf_read_value(data, |
508 | W83627EHF_REG_FAN_STOP_TIME[i]); | 514 | W83627EHF_REG_FAN_STOP_TIME[i]); |
509 | data->target_temp[i] = | 515 | data->target_temp[i] = |
510 | w83627ehf_read_value(client, | 516 | w83627ehf_read_value(data, |
511 | W83627EHF_REG_TARGET[i]) & | 517 | W83627EHF_REG_TARGET[i]) & |
512 | (data->pwm_mode[i] == 1 ? 0x7f : 0xff); | 518 | (data->pwm_mode[i] == 1 ? 0x7f : 0xff); |
513 | data->tolerance[i] = (tolerance >> (i == 1 ? 4 : 0)) | 519 | data->tolerance[i] = (tolerance >> (i == 1 ? 4 : 0)) |
@@ -515,26 +521,26 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) | |||
515 | } | 521 | } |
516 | 522 | ||
517 | /* Measured temperatures and limits */ | 523 | /* Measured temperatures and limits */ |
518 | data->temp1 = w83627ehf_read_value(client, | 524 | data->temp1 = w83627ehf_read_value(data, |
519 | W83627EHF_REG_TEMP1); | 525 | W83627EHF_REG_TEMP1); |
520 | data->temp1_max = w83627ehf_read_value(client, | 526 | data->temp1_max = w83627ehf_read_value(data, |
521 | W83627EHF_REG_TEMP1_OVER); | 527 | W83627EHF_REG_TEMP1_OVER); |
522 | data->temp1_max_hyst = w83627ehf_read_value(client, | 528 | data->temp1_max_hyst = w83627ehf_read_value(data, |
523 | W83627EHF_REG_TEMP1_HYST); | 529 | W83627EHF_REG_TEMP1_HYST); |
524 | for (i = 0; i < 2; i++) { | 530 | for (i = 0; i < 2; i++) { |
525 | data->temp[i] = w83627ehf_read_value(client, | 531 | data->temp[i] = w83627ehf_read_value(data, |
526 | W83627EHF_REG_TEMP[i]); | 532 | W83627EHF_REG_TEMP[i]); |
527 | data->temp_max[i] = w83627ehf_read_value(client, | 533 | data->temp_max[i] = w83627ehf_read_value(data, |
528 | W83627EHF_REG_TEMP_OVER[i]); | 534 | W83627EHF_REG_TEMP_OVER[i]); |
529 | data->temp_max_hyst[i] = w83627ehf_read_value(client, | 535 | data->temp_max_hyst[i] = w83627ehf_read_value(data, |
530 | W83627EHF_REG_TEMP_HYST[i]); | 536 | W83627EHF_REG_TEMP_HYST[i]); |
531 | } | 537 | } |
532 | 538 | ||
533 | data->alarms = w83627ehf_read_value(client, | 539 | data->alarms = w83627ehf_read_value(data, |
534 | W83627EHF_REG_ALARM1) | | 540 | W83627EHF_REG_ALARM1) | |
535 | (w83627ehf_read_value(client, | 541 | (w83627ehf_read_value(data, |
536 | W83627EHF_REG_ALARM2) << 8) | | 542 | W83627EHF_REG_ALARM2) << 8) | |
537 | (w83627ehf_read_value(client, | 543 | (w83627ehf_read_value(data, |
538 | W83627EHF_REG_ALARM3) << 16); | 544 | W83627EHF_REG_ALARM3) << 16); |
539 | 545 | ||
540 | data->last_updated = jiffies; | 546 | data->last_updated = jiffies; |
@@ -567,15 +573,14 @@ static ssize_t \ | |||
567 | store_in_##reg (struct device *dev, struct device_attribute *attr, \ | 573 | store_in_##reg (struct device *dev, struct device_attribute *attr, \ |
568 | const char *buf, size_t count) \ | 574 | const char *buf, size_t count) \ |
569 | { \ | 575 | { \ |
570 | struct i2c_client *client = to_i2c_client(dev); \ | 576 | struct w83627ehf_data *data = dev_get_drvdata(dev); \ |
571 | struct w83627ehf_data *data = i2c_get_clientdata(client); \ | ||
572 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ | 577 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ |
573 | int nr = sensor_attr->index; \ | 578 | int nr = sensor_attr->index; \ |
574 | u32 val = simple_strtoul(buf, NULL, 10); \ | 579 | u32 val = simple_strtoul(buf, NULL, 10); \ |
575 | \ | 580 | \ |
576 | mutex_lock(&data->update_lock); \ | 581 | mutex_lock(&data->update_lock); \ |
577 | data->in_##reg[nr] = in_to_reg(val, nr); \ | 582 | data->in_##reg[nr] = in_to_reg(val, nr); \ |
578 | w83627ehf_write_value(client, W83627EHF_REG_IN_##REG(nr), \ | 583 | w83627ehf_write_value(data, W83627EHF_REG_IN_##REG(nr), \ |
579 | data->in_##reg[nr]); \ | 584 | data->in_##reg[nr]); \ |
580 | mutex_unlock(&data->update_lock); \ | 585 | mutex_unlock(&data->update_lock); \ |
581 | return count; \ | 586 | return count; \ |
@@ -673,8 +678,7 @@ static ssize_t | |||
673 | store_fan_min(struct device *dev, struct device_attribute *attr, | 678 | store_fan_min(struct device *dev, struct device_attribute *attr, |
674 | const char *buf, size_t count) | 679 | const char *buf, size_t count) |
675 | { | 680 | { |
676 | struct i2c_client *client = to_i2c_client(dev); | 681 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
677 | struct w83627ehf_data *data = i2c_get_clientdata(client); | ||
678 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 682 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
679 | int nr = sensor_attr->index; | 683 | int nr = sensor_attr->index; |
680 | unsigned int val = simple_strtoul(buf, NULL, 10); | 684 | unsigned int val = simple_strtoul(buf, NULL, 10); |
@@ -716,18 +720,25 @@ store_fan_min(struct device *dev, struct device_attribute *attr, | |||
716 | /* Write both the fan clock divider (if it changed) and the new | 720 | /* Write both the fan clock divider (if it changed) and the new |
717 | fan min (unconditionally) */ | 721 | fan min (unconditionally) */ |
718 | if (new_div != data->fan_div[nr]) { | 722 | if (new_div != data->fan_div[nr]) { |
719 | if (new_div > data->fan_div[nr]) | 723 | /* Preserve the fan speed reading */ |
720 | data->fan[nr] >>= (data->fan_div[nr] - new_div); | 724 | if (data->fan[nr] != 0xff) { |
721 | else | 725 | if (new_div > data->fan_div[nr]) |
722 | data->fan[nr] <<= (new_div - data->fan_div[nr]); | 726 | data->fan[nr] >>= new_div - data->fan_div[nr]; |
727 | else if (data->fan[nr] & 0x80) | ||
728 | data->fan[nr] = 0xff; | ||
729 | else | ||
730 | data->fan[nr] <<= data->fan_div[nr] - new_div; | ||
731 | } | ||
723 | 732 | ||
724 | dev_dbg(dev, "fan%u clock divider changed from %u to %u\n", | 733 | dev_dbg(dev, "fan%u clock divider changed from %u to %u\n", |
725 | nr + 1, div_from_reg(data->fan_div[nr]), | 734 | nr + 1, div_from_reg(data->fan_div[nr]), |
726 | div_from_reg(new_div)); | 735 | div_from_reg(new_div)); |
727 | data->fan_div[nr] = new_div; | 736 | data->fan_div[nr] = new_div; |
728 | w83627ehf_write_fan_div(client, nr); | 737 | w83627ehf_write_fan_div(data, nr); |
738 | /* Give the chip time to sample a new speed value */ | ||
739 | data->last_updated = jiffies; | ||
729 | } | 740 | } |
730 | w83627ehf_write_value(client, W83627EHF_REG_FAN_MIN[nr], | 741 | w83627ehf_write_value(data, W83627EHF_REG_FAN_MIN[nr], |
731 | data->fan_min[nr]); | 742 | data->fan_min[nr]); |
732 | mutex_unlock(&data->update_lock); | 743 | mutex_unlock(&data->update_lock); |
733 | 744 | ||
@@ -788,13 +799,12 @@ static ssize_t \ | |||
788 | store_temp1_##reg(struct device *dev, struct device_attribute *attr, \ | 799 | store_temp1_##reg(struct device *dev, struct device_attribute *attr, \ |
789 | const char *buf, size_t count) \ | 800 | const char *buf, size_t count) \ |
790 | { \ | 801 | { \ |
791 | struct i2c_client *client = to_i2c_client(dev); \ | 802 | struct w83627ehf_data *data = dev_get_drvdata(dev); \ |
792 | struct w83627ehf_data *data = i2c_get_clientdata(client); \ | ||
793 | u32 val = simple_strtoul(buf, NULL, 10); \ | 803 | u32 val = simple_strtoul(buf, NULL, 10); \ |
794 | \ | 804 | \ |
795 | mutex_lock(&data->update_lock); \ | 805 | mutex_lock(&data->update_lock); \ |
796 | data->temp1_##reg = temp1_to_reg(val, -128000, 127000); \ | 806 | data->temp1_##reg = temp1_to_reg(val, -128000, 127000); \ |
797 | w83627ehf_write_value(client, W83627EHF_REG_TEMP1_##REG, \ | 807 | w83627ehf_write_value(data, W83627EHF_REG_TEMP1_##REG, \ |
798 | data->temp1_##reg); \ | 808 | data->temp1_##reg); \ |
799 | mutex_unlock(&data->update_lock); \ | 809 | mutex_unlock(&data->update_lock); \ |
800 | return count; \ | 810 | return count; \ |
@@ -822,15 +832,14 @@ static ssize_t \ | |||
822 | store_##reg(struct device *dev, struct device_attribute *attr, \ | 832 | store_##reg(struct device *dev, struct device_attribute *attr, \ |
823 | const char *buf, size_t count) \ | 833 | const char *buf, size_t count) \ |
824 | { \ | 834 | { \ |
825 | struct i2c_client *client = to_i2c_client(dev); \ | 835 | struct w83627ehf_data *data = dev_get_drvdata(dev); \ |
826 | struct w83627ehf_data *data = i2c_get_clientdata(client); \ | ||
827 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ | 836 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ |
828 | int nr = sensor_attr->index; \ | 837 | int nr = sensor_attr->index; \ |
829 | u32 val = simple_strtoul(buf, NULL, 10); \ | 838 | u32 val = simple_strtoul(buf, NULL, 10); \ |
830 | \ | 839 | \ |
831 | mutex_lock(&data->update_lock); \ | 840 | mutex_lock(&data->update_lock); \ |
832 | data->reg[nr] = LM75_TEMP_TO_REG(val); \ | 841 | data->reg[nr] = LM75_TEMP_TO_REG(val); \ |
833 | w83627ehf_write_value(client, W83627EHF_REG_TEMP_##REG[nr], \ | 842 | w83627ehf_write_value(data, W83627EHF_REG_TEMP_##REG[nr], \ |
834 | data->reg[nr]); \ | 843 | data->reg[nr]); \ |
835 | mutex_unlock(&data->update_lock); \ | 844 | mutex_unlock(&data->update_lock); \ |
836 | return count; \ | 845 | return count; \ |
@@ -838,6 +847,15 @@ store_##reg(struct device *dev, struct device_attribute *attr, \ | |||
838 | store_temp_reg(OVER, temp_max); | 847 | store_temp_reg(OVER, temp_max); |
839 | store_temp_reg(HYST, temp_max_hyst); | 848 | store_temp_reg(HYST, temp_max_hyst); |
840 | 849 | ||
850 | static ssize_t | ||
851 | show_temp_type(struct device *dev, struct device_attribute *attr, char *buf) | ||
852 | { | ||
853 | struct w83627ehf_data *data = w83627ehf_update_device(dev); | ||
854 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | ||
855 | int nr = sensor_attr->index; | ||
856 | return sprintf(buf, "%d\n", (int)data->temp_type[nr]); | ||
857 | } | ||
858 | |||
841 | static struct sensor_device_attribute sda_temp[] = { | 859 | static struct sensor_device_attribute sda_temp[] = { |
842 | SENSOR_ATTR(temp1_input, S_IRUGO, show_temp1, NULL, 0), | 860 | SENSOR_ATTR(temp1_input, S_IRUGO, show_temp1, NULL, 0), |
843 | SENSOR_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 0), | 861 | SENSOR_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 0), |
@@ -857,6 +875,9 @@ static struct sensor_device_attribute sda_temp[] = { | |||
857 | SENSOR_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4), | 875 | SENSOR_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4), |
858 | SENSOR_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5), | 876 | SENSOR_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5), |
859 | SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13), | 877 | SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13), |
878 | SENSOR_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0), | ||
879 | SENSOR_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1), | ||
880 | SENSOR_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2), | ||
860 | }; | 881 | }; |
861 | 882 | ||
862 | #define show_pwm_reg(reg) \ | 883 | #define show_pwm_reg(reg) \ |
@@ -877,8 +898,7 @@ static ssize_t | |||
877 | store_pwm_mode(struct device *dev, struct device_attribute *attr, | 898 | store_pwm_mode(struct device *dev, struct device_attribute *attr, |
878 | const char *buf, size_t count) | 899 | const char *buf, size_t count) |
879 | { | 900 | { |
880 | struct i2c_client *client = to_i2c_client(dev); | 901 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
881 | struct w83627ehf_data *data = i2c_get_clientdata(client); | ||
882 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 902 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
883 | int nr = sensor_attr->index; | 903 | int nr = sensor_attr->index; |
884 | u32 val = simple_strtoul(buf, NULL, 10); | 904 | u32 val = simple_strtoul(buf, NULL, 10); |
@@ -887,12 +907,12 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr, | |||
887 | if (val > 1) | 907 | if (val > 1) |
888 | return -EINVAL; | 908 | return -EINVAL; |
889 | mutex_lock(&data->update_lock); | 909 | mutex_lock(&data->update_lock); |
890 | reg = w83627ehf_read_value(client, W83627EHF_REG_PWM_ENABLE[nr]); | 910 | reg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[nr]); |
891 | data->pwm_mode[nr] = val; | 911 | data->pwm_mode[nr] = val; |
892 | reg &= ~(1 << W83627EHF_PWM_MODE_SHIFT[nr]); | 912 | reg &= ~(1 << W83627EHF_PWM_MODE_SHIFT[nr]); |
893 | if (!val) | 913 | if (!val) |
894 | reg |= 1 << W83627EHF_PWM_MODE_SHIFT[nr]; | 914 | reg |= 1 << W83627EHF_PWM_MODE_SHIFT[nr]; |
895 | w83627ehf_write_value(client, W83627EHF_REG_PWM_ENABLE[nr], reg); | 915 | w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[nr], reg); |
896 | mutex_unlock(&data->update_lock); | 916 | mutex_unlock(&data->update_lock); |
897 | return count; | 917 | return count; |
898 | } | 918 | } |
@@ -901,15 +921,14 @@ static ssize_t | |||
901 | store_pwm(struct device *dev, struct device_attribute *attr, | 921 | store_pwm(struct device *dev, struct device_attribute *attr, |
902 | const char *buf, size_t count) | 922 | const char *buf, size_t count) |
903 | { | 923 | { |
904 | struct i2c_client *client = to_i2c_client(dev); | 924 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
905 | struct w83627ehf_data *data = i2c_get_clientdata(client); | ||
906 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 925 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
907 | int nr = sensor_attr->index; | 926 | int nr = sensor_attr->index; |
908 | u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 255); | 927 | u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 255); |
909 | 928 | ||
910 | mutex_lock(&data->update_lock); | 929 | mutex_lock(&data->update_lock); |
911 | data->pwm[nr] = val; | 930 | data->pwm[nr] = val; |
912 | w83627ehf_write_value(client, W83627EHF_REG_PWM[nr], val); | 931 | w83627ehf_write_value(data, W83627EHF_REG_PWM[nr], val); |
913 | mutex_unlock(&data->update_lock); | 932 | mutex_unlock(&data->update_lock); |
914 | return count; | 933 | return count; |
915 | } | 934 | } |
@@ -918,8 +937,7 @@ static ssize_t | |||
918 | store_pwm_enable(struct device *dev, struct device_attribute *attr, | 937 | store_pwm_enable(struct device *dev, struct device_attribute *attr, |
919 | const char *buf, size_t count) | 938 | const char *buf, size_t count) |
920 | { | 939 | { |
921 | struct i2c_client *client = to_i2c_client(dev); | 940 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
922 | struct w83627ehf_data *data = i2c_get_clientdata(client); | ||
923 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 941 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
924 | int nr = sensor_attr->index; | 942 | int nr = sensor_attr->index; |
925 | u32 val = simple_strtoul(buf, NULL, 10); | 943 | u32 val = simple_strtoul(buf, NULL, 10); |
@@ -928,11 +946,11 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr, | |||
928 | if (!val || (val > 2)) /* only modes 1 and 2 are supported */ | 946 | if (!val || (val > 2)) /* only modes 1 and 2 are supported */ |
929 | return -EINVAL; | 947 | return -EINVAL; |
930 | mutex_lock(&data->update_lock); | 948 | mutex_lock(&data->update_lock); |
931 | reg = w83627ehf_read_value(client, W83627EHF_REG_PWM_ENABLE[nr]); | 949 | reg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[nr]); |
932 | data->pwm_enable[nr] = val; | 950 | data->pwm_enable[nr] = val; |
933 | reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[nr]); | 951 | reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[nr]); |
934 | reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[nr]; | 952 | reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[nr]; |
935 | w83627ehf_write_value(client, W83627EHF_REG_PWM_ENABLE[nr], reg); | 953 | w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[nr], reg); |
936 | mutex_unlock(&data->update_lock); | 954 | mutex_unlock(&data->update_lock); |
937 | return count; | 955 | return count; |
938 | } | 956 | } |
@@ -955,15 +973,14 @@ static ssize_t | |||
955 | store_target_temp(struct device *dev, struct device_attribute *attr, | 973 | store_target_temp(struct device *dev, struct device_attribute *attr, |
956 | const char *buf, size_t count) | 974 | const char *buf, size_t count) |
957 | { | 975 | { |
958 | struct i2c_client *client = to_i2c_client(dev); | 976 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
959 | struct w83627ehf_data *data = i2c_get_clientdata(client); | ||
960 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 977 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
961 | int nr = sensor_attr->index; | 978 | int nr = sensor_attr->index; |
962 | u8 val = temp1_to_reg(simple_strtoul(buf, NULL, 10), 0, 127000); | 979 | u8 val = temp1_to_reg(simple_strtoul(buf, NULL, 10), 0, 127000); |
963 | 980 | ||
964 | mutex_lock(&data->update_lock); | 981 | mutex_lock(&data->update_lock); |
965 | data->target_temp[nr] = val; | 982 | data->target_temp[nr] = val; |
966 | w83627ehf_write_value(client, W83627EHF_REG_TARGET[nr], val); | 983 | w83627ehf_write_value(data, W83627EHF_REG_TARGET[nr], val); |
967 | mutex_unlock(&data->update_lock); | 984 | mutex_unlock(&data->update_lock); |
968 | return count; | 985 | return count; |
969 | } | 986 | } |
@@ -972,8 +989,7 @@ static ssize_t | |||
972 | store_tolerance(struct device *dev, struct device_attribute *attr, | 989 | store_tolerance(struct device *dev, struct device_attribute *attr, |
973 | const char *buf, size_t count) | 990 | const char *buf, size_t count) |
974 | { | 991 | { |
975 | struct i2c_client *client = to_i2c_client(dev); | 992 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
976 | struct w83627ehf_data *data = i2c_get_clientdata(client); | ||
977 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 993 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
978 | int nr = sensor_attr->index; | 994 | int nr = sensor_attr->index; |
979 | u16 reg; | 995 | u16 reg; |
@@ -981,13 +997,13 @@ store_tolerance(struct device *dev, struct device_attribute *attr, | |||
981 | u8 val = temp1_to_reg(simple_strtoul(buf, NULL, 10), 0, 15000); | 997 | u8 val = temp1_to_reg(simple_strtoul(buf, NULL, 10), 0, 15000); |
982 | 998 | ||
983 | mutex_lock(&data->update_lock); | 999 | mutex_lock(&data->update_lock); |
984 | reg = w83627ehf_read_value(client, W83627EHF_REG_TOLERANCE[nr]); | 1000 | reg = w83627ehf_read_value(data, W83627EHF_REG_TOLERANCE[nr]); |
985 | data->tolerance[nr] = val; | 1001 | data->tolerance[nr] = val; |
986 | if (nr == 1) | 1002 | if (nr == 1) |
987 | reg = (reg & 0x0f) | (val << 4); | 1003 | reg = (reg & 0x0f) | (val << 4); |
988 | else | 1004 | else |
989 | reg = (reg & 0xf0) | val; | 1005 | reg = (reg & 0xf0) | val; |
990 | w83627ehf_write_value(client, W83627EHF_REG_TOLERANCE[nr], reg); | 1006 | w83627ehf_write_value(data, W83627EHF_REG_TOLERANCE[nr], reg); |
991 | mutex_unlock(&data->update_lock); | 1007 | mutex_unlock(&data->update_lock); |
992 | return count; | 1008 | return count; |
993 | } | 1009 | } |
@@ -1058,14 +1074,13 @@ static ssize_t \ | |||
1058 | store_##reg(struct device *dev, struct device_attribute *attr, \ | 1074 | store_##reg(struct device *dev, struct device_attribute *attr, \ |
1059 | const char *buf, size_t count) \ | 1075 | const char *buf, size_t count) \ |
1060 | {\ | 1076 | {\ |
1061 | struct i2c_client *client = to_i2c_client(dev); \ | 1077 | struct w83627ehf_data *data = dev_get_drvdata(dev); \ |
1062 | struct w83627ehf_data *data = i2c_get_clientdata(client); \ | ||
1063 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ | 1078 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ |
1064 | int nr = sensor_attr->index; \ | 1079 | int nr = sensor_attr->index; \ |
1065 | u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 1, 255); \ | 1080 | u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 1, 255); \ |
1066 | mutex_lock(&data->update_lock); \ | 1081 | mutex_lock(&data->update_lock); \ |
1067 | data->reg[nr] = val; \ | 1082 | data->reg[nr] = val; \ |
1068 | w83627ehf_write_value(client, W83627EHF_REG_##REG[nr], val); \ | 1083 | w83627ehf_write_value(data, W83627EHF_REG_##REG[nr], val); \ |
1069 | mutex_unlock(&data->update_lock); \ | 1084 | mutex_unlock(&data->update_lock); \ |
1070 | return count; \ | 1085 | return count; \ |
1071 | } | 1086 | } |
@@ -1087,21 +1102,28 @@ static ssize_t \ | |||
1087 | store_##reg(struct device *dev, struct device_attribute *attr, \ | 1102 | store_##reg(struct device *dev, struct device_attribute *attr, \ |
1088 | const char *buf, size_t count) \ | 1103 | const char *buf, size_t count) \ |
1089 | { \ | 1104 | { \ |
1090 | struct i2c_client *client = to_i2c_client(dev); \ | 1105 | struct w83627ehf_data *data = dev_get_drvdata(dev); \ |
1091 | struct w83627ehf_data *data = i2c_get_clientdata(client); \ | ||
1092 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ | 1106 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ |
1093 | int nr = sensor_attr->index; \ | 1107 | int nr = sensor_attr->index; \ |
1094 | u8 val = step_time_to_reg(simple_strtoul(buf, NULL, 10), \ | 1108 | u8 val = step_time_to_reg(simple_strtoul(buf, NULL, 10), \ |
1095 | data->pwm_mode[nr]); \ | 1109 | data->pwm_mode[nr]); \ |
1096 | mutex_lock(&data->update_lock); \ | 1110 | mutex_lock(&data->update_lock); \ |
1097 | data->reg[nr] = val; \ | 1111 | data->reg[nr] = val; \ |
1098 | w83627ehf_write_value(client, W83627EHF_REG_##REG[nr], val); \ | 1112 | w83627ehf_write_value(data, W83627EHF_REG_##REG[nr], val); \ |
1099 | mutex_unlock(&data->update_lock); \ | 1113 | mutex_unlock(&data->update_lock); \ |
1100 | return count; \ | 1114 | return count; \ |
1101 | } \ | 1115 | } \ |
1102 | 1116 | ||
1103 | fan_time_functions(fan_stop_time, FAN_STOP_TIME) | 1117 | fan_time_functions(fan_stop_time, FAN_STOP_TIME) |
1104 | 1118 | ||
1119 | static ssize_t show_name(struct device *dev, struct device_attribute *attr, | ||
1120 | char *buf) | ||
1121 | { | ||
1122 | struct w83627ehf_data *data = dev_get_drvdata(dev); | ||
1123 | |||
1124 | return sprintf(buf, "%s\n", data->name); | ||
1125 | } | ||
1126 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
1105 | 1127 | ||
1106 | static struct sensor_device_attribute sda_sf3_arrays_fan4[] = { | 1128 | static struct sensor_device_attribute sda_sf3_arrays_fan4[] = { |
1107 | SENSOR_ATTR(pwm4_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time, | 1129 | SENSOR_ATTR(pwm4_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time, |
@@ -1125,8 +1147,16 @@ static struct sensor_device_attribute sda_sf3_arrays[] = { | |||
1125 | store_fan_min_output, 2), | 1147 | store_fan_min_output, 2), |
1126 | }; | 1148 | }; |
1127 | 1149 | ||
1150 | static ssize_t | ||
1151 | show_vid(struct device *dev, struct device_attribute *attr, char *buf) | ||
1152 | { | ||
1153 | struct w83627ehf_data *data = dev_get_drvdata(dev); | ||
1154 | return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); | ||
1155 | } | ||
1156 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); | ||
1157 | |||
1128 | /* | 1158 | /* |
1129 | * Driver and client management | 1159 | * Driver and device management |
1130 | */ | 1160 | */ |
1131 | 1161 | ||
1132 | static void w83627ehf_device_remove_files(struct device *dev) | 1162 | static void w83627ehf_device_remove_files(struct device *dev) |
@@ -1134,12 +1164,13 @@ static void w83627ehf_device_remove_files(struct device *dev) | |||
1134 | /* some entries in the following arrays may not have been used in | 1164 | /* some entries in the following arrays may not have been used in |
1135 | * device_create_file(), but device_remove_file() will ignore them */ | 1165 | * device_create_file(), but device_remove_file() will ignore them */ |
1136 | int i; | 1166 | int i; |
1167 | struct w83627ehf_data *data = dev_get_drvdata(dev); | ||
1137 | 1168 | ||
1138 | for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++) | 1169 | for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++) |
1139 | device_remove_file(dev, &sda_sf3_arrays[i].dev_attr); | 1170 | device_remove_file(dev, &sda_sf3_arrays[i].dev_attr); |
1140 | for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) | 1171 | for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) |
1141 | device_remove_file(dev, &sda_sf3_arrays_fan4[i].dev_attr); | 1172 | device_remove_file(dev, &sda_sf3_arrays_fan4[i].dev_attr); |
1142 | for (i = 0; i < w83627ehf_num_in; i++) { | 1173 | for (i = 0; i < data->in_num; i++) { |
1143 | device_remove_file(dev, &sda_in_input[i].dev_attr); | 1174 | device_remove_file(dev, &sda_in_input[i].dev_attr); |
1144 | device_remove_file(dev, &sda_in_alarm[i].dev_attr); | 1175 | device_remove_file(dev, &sda_in_alarm[i].dev_attr); |
1145 | device_remove_file(dev, &sda_in_min[i].dev_attr); | 1176 | device_remove_file(dev, &sda_in_min[i].dev_attr); |
@@ -1160,43 +1191,64 @@ static void w83627ehf_device_remove_files(struct device *dev) | |||
1160 | } | 1191 | } |
1161 | for (i = 0; i < ARRAY_SIZE(sda_temp); i++) | 1192 | for (i = 0; i < ARRAY_SIZE(sda_temp); i++) |
1162 | device_remove_file(dev, &sda_temp[i].dev_attr); | 1193 | device_remove_file(dev, &sda_temp[i].dev_attr); |
1163 | } | ||
1164 | 1194 | ||
1165 | static struct i2c_driver w83627ehf_driver; | 1195 | device_remove_file(dev, &dev_attr_name); |
1196 | if (data->vid != 0x3f) | ||
1197 | device_remove_file(dev, &dev_attr_cpu0_vid); | ||
1198 | } | ||
1166 | 1199 | ||
1167 | static void w83627ehf_init_client(struct i2c_client *client) | 1200 | /* Get the monitoring functions started */ |
1201 | static inline void __devinit w83627ehf_init_device(struct w83627ehf_data *data) | ||
1168 | { | 1202 | { |
1169 | int i; | 1203 | int i; |
1170 | u8 tmp; | 1204 | u8 tmp, diode; |
1171 | 1205 | ||
1172 | /* Start monitoring is needed */ | 1206 | /* Start monitoring is needed */ |
1173 | tmp = w83627ehf_read_value(client, W83627EHF_REG_CONFIG); | 1207 | tmp = w83627ehf_read_value(data, W83627EHF_REG_CONFIG); |
1174 | if (!(tmp & 0x01)) | 1208 | if (!(tmp & 0x01)) |
1175 | w83627ehf_write_value(client, W83627EHF_REG_CONFIG, | 1209 | w83627ehf_write_value(data, W83627EHF_REG_CONFIG, |
1176 | tmp | 0x01); | 1210 | tmp | 0x01); |
1177 | 1211 | ||
1178 | /* Enable temp2 and temp3 if needed */ | 1212 | /* Enable temp2 and temp3 if needed */ |
1179 | for (i = 0; i < 2; i++) { | 1213 | for (i = 0; i < 2; i++) { |
1180 | tmp = w83627ehf_read_value(client, | 1214 | tmp = w83627ehf_read_value(data, |
1181 | W83627EHF_REG_TEMP_CONFIG[i]); | 1215 | W83627EHF_REG_TEMP_CONFIG[i]); |
1182 | if (tmp & 0x01) | 1216 | if (tmp & 0x01) |
1183 | w83627ehf_write_value(client, | 1217 | w83627ehf_write_value(data, |
1184 | W83627EHF_REG_TEMP_CONFIG[i], | 1218 | W83627EHF_REG_TEMP_CONFIG[i], |
1185 | tmp & 0xfe); | 1219 | tmp & 0xfe); |
1186 | } | 1220 | } |
1221 | |||
1222 | /* Enable VBAT monitoring if needed */ | ||
1223 | tmp = w83627ehf_read_value(data, W83627EHF_REG_VBAT); | ||
1224 | if (!(tmp & 0x01)) | ||
1225 | w83627ehf_write_value(data, W83627EHF_REG_VBAT, tmp | 0x01); | ||
1226 | |||
1227 | /* Get thermal sensor types */ | ||
1228 | diode = w83627ehf_read_value(data, W83627EHF_REG_DIODE); | ||
1229 | for (i = 0; i < 3; i++) { | ||
1230 | if ((tmp & (0x02 << i))) | ||
1231 | data->temp_type[i] = (diode & (0x10 << i)) ? 1 : 2; | ||
1232 | else | ||
1233 | data->temp_type[i] = 4; /* thermistor */ | ||
1234 | } | ||
1187 | } | 1235 | } |
1188 | 1236 | ||
1189 | static int w83627ehf_detect(struct i2c_adapter *adapter) | 1237 | static int __devinit w83627ehf_probe(struct platform_device *pdev) |
1190 | { | 1238 | { |
1191 | struct i2c_client *client; | 1239 | struct device *dev = &pdev->dev; |
1240 | struct w83627ehf_sio_data *sio_data = dev->platform_data; | ||
1192 | struct w83627ehf_data *data; | 1241 | struct w83627ehf_data *data; |
1193 | struct device *dev; | 1242 | struct resource *res; |
1194 | u8 fan4pin, fan5pin; | 1243 | u8 fan4pin, fan5pin, en_vrm10; |
1195 | int i, err = 0; | 1244 | int i, err = 0; |
1196 | 1245 | ||
1197 | if (!request_region(address + IOREGION_OFFSET, IOREGION_LENGTH, | 1246 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
1198 | w83627ehf_driver.driver.name)) { | 1247 | if (!request_region(res->start, IOREGION_LENGTH, DRVNAME)) { |
1199 | err = -EBUSY; | 1248 | err = -EBUSY; |
1249 | dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", | ||
1250 | (unsigned long)res->start, | ||
1251 | (unsigned long)res->start + IOREGION_LENGTH - 1); | ||
1200 | goto exit; | 1252 | goto exit; |
1201 | } | 1253 | } |
1202 | 1254 | ||
@@ -1205,41 +1257,47 @@ static int w83627ehf_detect(struct i2c_adapter *adapter) | |||
1205 | goto exit_release; | 1257 | goto exit_release; |
1206 | } | 1258 | } |
1207 | 1259 | ||
1208 | client = &data->client; | 1260 | data->addr = res->start; |
1209 | i2c_set_clientdata(client, data); | ||
1210 | client->addr = address; | ||
1211 | mutex_init(&data->lock); | 1261 | mutex_init(&data->lock); |
1212 | client->adapter = adapter; | ||
1213 | client->driver = &w83627ehf_driver; | ||
1214 | client->flags = 0; | ||
1215 | dev = &client->dev; | ||
1216 | |||
1217 | if (w83627ehf_num_in == 9) | ||
1218 | strlcpy(client->name, "w83627dhg", I2C_NAME_SIZE); | ||
1219 | else /* just say ehf. 627EHG is 627EHF in lead-free packaging. */ | ||
1220 | strlcpy(client->name, "w83627ehf", I2C_NAME_SIZE); | ||
1221 | |||
1222 | data->valid = 0; | ||
1223 | mutex_init(&data->update_lock); | 1262 | mutex_init(&data->update_lock); |
1263 | data->name = w83627ehf_device_names[sio_data->kind]; | ||
1264 | platform_set_drvdata(pdev, data); | ||
1224 | 1265 | ||
1225 | /* Tell the i2c layer a new client has arrived */ | 1266 | /* 627EHG and 627EHF have 10 voltage inputs; DHG has 9 */ |
1226 | if ((err = i2c_attach_client(client))) | 1267 | data->in_num = (sio_data->kind == w83627dhg) ? 9 : 10; |
1227 | goto exit_free; | ||
1228 | 1268 | ||
1229 | /* Initialize the chip */ | 1269 | /* Initialize the chip */ |
1230 | w83627ehf_init_client(client); | 1270 | w83627ehf_init_device(data); |
1231 | 1271 | ||
1232 | /* A few vars need to be filled upon startup */ | 1272 | data->vrm = vid_which_vrm(); |
1233 | for (i = 0; i < 5; i++) | 1273 | superio_enter(sio_data->sioreg); |
1234 | data->fan_min[i] = w83627ehf_read_value(client, | 1274 | /* Set VID input sensibility if needed. In theory the BIOS should |
1235 | W83627EHF_REG_FAN_MIN[i]); | 1275 | have set it, but in practice it's not always the case. */ |
1276 | en_vrm10 = superio_inb(sio_data->sioreg, SIO_REG_EN_VRM10); | ||
1277 | if ((en_vrm10 & 0x08) && data->vrm != 100) { | ||
1278 | dev_warn(dev, "Setting VID input voltage to TTL\n"); | ||
1279 | superio_outb(sio_data->sioreg, SIO_REG_EN_VRM10, | ||
1280 | en_vrm10 & ~0x08); | ||
1281 | } else if (!(en_vrm10 & 0x08) && data->vrm == 100) { | ||
1282 | dev_warn(dev, "Setting VID input voltage to VRM10\n"); | ||
1283 | superio_outb(sio_data->sioreg, SIO_REG_EN_VRM10, | ||
1284 | en_vrm10 | 0x08); | ||
1285 | } | ||
1286 | /* Read VID value */ | ||
1287 | superio_select(sio_data->sioreg, W83627EHF_LD_HWM); | ||
1288 | if (superio_inb(sio_data->sioreg, SIO_REG_VID_CTRL) & 0x80) | ||
1289 | data->vid = superio_inb(sio_data->sioreg, SIO_REG_VID_DATA) & 0x3f; | ||
1290 | else { | ||
1291 | dev_info(dev, "VID pins in output mode, CPU VID not " | ||
1292 | "available\n"); | ||
1293 | data->vid = 0x3f; | ||
1294 | } | ||
1236 | 1295 | ||
1237 | /* fan4 and fan5 share some pins with the GPIO and serial flash */ | 1296 | /* fan4 and fan5 share some pins with the GPIO and serial flash */ |
1238 | 1297 | ||
1239 | superio_enter(); | 1298 | fan5pin = superio_inb(sio_data->sioreg, 0x24) & 0x2; |
1240 | fan5pin = superio_inb(0x24) & 0x2; | 1299 | fan4pin = superio_inb(sio_data->sioreg, 0x29) & 0x6; |
1241 | fan4pin = superio_inb(0x29) & 0x6; | 1300 | superio_exit(sio_data->sioreg); |
1242 | superio_exit(); | ||
1243 | 1301 | ||
1244 | /* It looks like fan4 and fan5 pins can be alternatively used | 1302 | /* It looks like fan4 and fan5 pins can be alternatively used |
1245 | as fan on/off switches, but fan5 control is write only :/ | 1303 | as fan on/off switches, but fan5 control is write only :/ |
@@ -1248,7 +1306,7 @@ static int w83627ehf_detect(struct i2c_adapter *adapter) | |||
1248 | is not the default. */ | 1306 | is not the default. */ |
1249 | 1307 | ||
1250 | data->has_fan = 0x07; /* fan1, fan2 and fan3 */ | 1308 | data->has_fan = 0x07; /* fan1, fan2 and fan3 */ |
1251 | i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV1); | 1309 | i = w83627ehf_read_value(data, W83627EHF_REG_FANDIV1); |
1252 | if ((i & (1 << 2)) && (!fan4pin)) | 1310 | if ((i & (1 << 2)) && (!fan4pin)) |
1253 | data->has_fan |= (1 << 3); | 1311 | data->has_fan |= (1 << 3); |
1254 | if (!(i & (1 << 1)) && (!fan5pin)) | 1312 | if (!(i & (1 << 1)) && (!fan5pin)) |
@@ -1268,7 +1326,7 @@ static int w83627ehf_detect(struct i2c_adapter *adapter) | |||
1268 | goto exit_remove; | 1326 | goto exit_remove; |
1269 | } | 1327 | } |
1270 | 1328 | ||
1271 | for (i = 0; i < w83627ehf_num_in; i++) | 1329 | for (i = 0; i < data->in_num; i++) |
1272 | if ((err = device_create_file(dev, &sda_in_input[i].dev_attr)) | 1330 | if ((err = device_create_file(dev, &sda_in_input[i].dev_attr)) |
1273 | || (err = device_create_file(dev, | 1331 | || (err = device_create_file(dev, |
1274 | &sda_in_alarm[i].dev_attr)) | 1332 | &sda_in_alarm[i].dev_attr)) |
@@ -1308,6 +1366,16 @@ static int w83627ehf_detect(struct i2c_adapter *adapter) | |||
1308 | if ((err = device_create_file(dev, &sda_temp[i].dev_attr))) | 1366 | if ((err = device_create_file(dev, &sda_temp[i].dev_attr))) |
1309 | goto exit_remove; | 1367 | goto exit_remove; |
1310 | 1368 | ||
1369 | err = device_create_file(dev, &dev_attr_name); | ||
1370 | if (err) | ||
1371 | goto exit_remove; | ||
1372 | |||
1373 | if (data->vid != 0x3f) { | ||
1374 | err = device_create_file(dev, &dev_attr_cpu0_vid); | ||
1375 | if (err) | ||
1376 | goto exit_remove; | ||
1377 | } | ||
1378 | |||
1311 | data->class_dev = hwmon_device_register(dev); | 1379 | data->class_dev = hwmon_device_register(dev); |
1312 | if (IS_ERR(data->class_dev)) { | 1380 | if (IS_ERR(data->class_dev)) { |
1313 | err = PTR_ERR(data->class_dev); | 1381 | err = PTR_ERR(data->class_dev); |
@@ -1318,95 +1386,172 @@ static int w83627ehf_detect(struct i2c_adapter *adapter) | |||
1318 | 1386 | ||
1319 | exit_remove: | 1387 | exit_remove: |
1320 | w83627ehf_device_remove_files(dev); | 1388 | w83627ehf_device_remove_files(dev); |
1321 | i2c_detach_client(client); | ||
1322 | exit_free: | ||
1323 | kfree(data); | 1389 | kfree(data); |
1390 | platform_set_drvdata(pdev, NULL); | ||
1324 | exit_release: | 1391 | exit_release: |
1325 | release_region(address + IOREGION_OFFSET, IOREGION_LENGTH); | 1392 | release_region(res->start, IOREGION_LENGTH); |
1326 | exit: | 1393 | exit: |
1327 | return err; | 1394 | return err; |
1328 | } | 1395 | } |
1329 | 1396 | ||
1330 | static int w83627ehf_detach_client(struct i2c_client *client) | 1397 | static int __devexit w83627ehf_remove(struct platform_device *pdev) |
1331 | { | 1398 | { |
1332 | struct w83627ehf_data *data = i2c_get_clientdata(client); | 1399 | struct w83627ehf_data *data = platform_get_drvdata(pdev); |
1333 | int err; | ||
1334 | 1400 | ||
1335 | hwmon_device_unregister(data->class_dev); | 1401 | hwmon_device_unregister(data->class_dev); |
1336 | w83627ehf_device_remove_files(&client->dev); | 1402 | w83627ehf_device_remove_files(&pdev->dev); |
1337 | 1403 | release_region(data->addr, IOREGION_LENGTH); | |
1338 | if ((err = i2c_detach_client(client))) | 1404 | platform_set_drvdata(pdev, NULL); |
1339 | return err; | ||
1340 | release_region(client->addr + IOREGION_OFFSET, IOREGION_LENGTH); | ||
1341 | kfree(data); | 1405 | kfree(data); |
1342 | 1406 | ||
1343 | return 0; | 1407 | return 0; |
1344 | } | 1408 | } |
1345 | 1409 | ||
1346 | static struct i2c_driver w83627ehf_driver = { | 1410 | static struct platform_driver w83627ehf_driver = { |
1347 | .driver = { | 1411 | .driver = { |
1348 | .owner = THIS_MODULE, | 1412 | .owner = THIS_MODULE, |
1349 | .name = "w83627ehf", | 1413 | .name = DRVNAME, |
1350 | }, | 1414 | }, |
1351 | .attach_adapter = w83627ehf_detect, | 1415 | .probe = w83627ehf_probe, |
1352 | .detach_client = w83627ehf_detach_client, | 1416 | .remove = __devexit_p(w83627ehf_remove), |
1353 | }; | 1417 | }; |
1354 | 1418 | ||
1355 | static int __init w83627ehf_find(int sioaddr, unsigned short *addr) | 1419 | /* w83627ehf_find() looks for a '627 in the Super-I/O config space */ |
1420 | static int __init w83627ehf_find(int sioaddr, unsigned short *addr, | ||
1421 | struct w83627ehf_sio_data *sio_data) | ||
1356 | { | 1422 | { |
1423 | static const char __initdata sio_name_W83627EHF[] = "W83627EHF"; | ||
1424 | static const char __initdata sio_name_W83627EHG[] = "W83627EHG"; | ||
1425 | static const char __initdata sio_name_W83627DHG[] = "W83627DHG"; | ||
1426 | |||
1357 | u16 val; | 1427 | u16 val; |
1428 | const char *sio_name; | ||
1358 | 1429 | ||
1359 | REG = sioaddr; | 1430 | superio_enter(sioaddr); |
1360 | VAL = sioaddr + 1; | ||
1361 | superio_enter(); | ||
1362 | 1431 | ||
1363 | val = (superio_inb(SIO_REG_DEVID) << 8) | 1432 | val = (superio_inb(sioaddr, SIO_REG_DEVID) << 8) |
1364 | | superio_inb(SIO_REG_DEVID + 1); | 1433 | | superio_inb(sioaddr, SIO_REG_DEVID + 1); |
1365 | switch (val & SIO_ID_MASK) { | 1434 | switch (val & SIO_ID_MASK) { |
1366 | case SIO_W83627DHG_ID: | ||
1367 | w83627ehf_num_in = 9; | ||
1368 | break; | ||
1369 | case SIO_W83627EHF_ID: | 1435 | case SIO_W83627EHF_ID: |
1436 | sio_data->kind = w83627ehf; | ||
1437 | sio_name = sio_name_W83627EHF; | ||
1438 | break; | ||
1370 | case SIO_W83627EHG_ID: | 1439 | case SIO_W83627EHG_ID: |
1371 | w83627ehf_num_in = 10; | 1440 | sio_data->kind = w83627ehf; |
1441 | sio_name = sio_name_W83627EHG; | ||
1442 | break; | ||
1443 | case SIO_W83627DHG_ID: | ||
1444 | sio_data->kind = w83627dhg; | ||
1445 | sio_name = sio_name_W83627DHG; | ||
1372 | break; | 1446 | break; |
1373 | default: | 1447 | default: |
1374 | printk(KERN_WARNING "w83627ehf: unsupported chip ID: 0x%04x\n", | 1448 | if (val != 0xffff) |
1375 | val); | 1449 | pr_debug(DRVNAME ": unsupported chip ID: 0x%04x\n", |
1376 | superio_exit(); | 1450 | val); |
1451 | superio_exit(sioaddr); | ||
1377 | return -ENODEV; | 1452 | return -ENODEV; |
1378 | } | 1453 | } |
1379 | 1454 | ||
1380 | superio_select(W83627EHF_LD_HWM); | 1455 | /* We have a known chip, find the HWM I/O address */ |
1381 | val = (superio_inb(SIO_REG_ADDR) << 8) | 1456 | superio_select(sioaddr, W83627EHF_LD_HWM); |
1382 | | superio_inb(SIO_REG_ADDR + 1); | 1457 | val = (superio_inb(sioaddr, SIO_REG_ADDR) << 8) |
1458 | | superio_inb(sioaddr, SIO_REG_ADDR + 1); | ||
1383 | *addr = val & IOREGION_ALIGNMENT; | 1459 | *addr = val & IOREGION_ALIGNMENT; |
1384 | if (*addr == 0) { | 1460 | if (*addr == 0) { |
1385 | superio_exit(); | 1461 | printk(KERN_ERR DRVNAME ": Refusing to enable a Super-I/O " |
1462 | "device with a base I/O port 0.\n"); | ||
1463 | superio_exit(sioaddr); | ||
1386 | return -ENODEV; | 1464 | return -ENODEV; |
1387 | } | 1465 | } |
1388 | 1466 | ||
1389 | /* Activate logical device if needed */ | 1467 | /* Activate logical device if needed */ |
1390 | val = superio_inb(SIO_REG_ENABLE); | 1468 | val = superio_inb(sioaddr, SIO_REG_ENABLE); |
1391 | if (!(val & 0x01)) | 1469 | if (!(val & 0x01)) { |
1392 | superio_outb(SIO_REG_ENABLE, val | 0x01); | 1470 | printk(KERN_WARNING DRVNAME ": Forcibly enabling Super-I/O. " |
1471 | "Sensor is probably unusable.\n"); | ||
1472 | superio_outb(sioaddr, SIO_REG_ENABLE, val | 0x01); | ||
1473 | } | ||
1474 | |||
1475 | superio_exit(sioaddr); | ||
1476 | pr_info(DRVNAME ": Found %s chip at %#x\n", sio_name, *addr); | ||
1477 | sio_data->sioreg = sioaddr; | ||
1393 | 1478 | ||
1394 | superio_exit(); | ||
1395 | return 0; | 1479 | return 0; |
1396 | } | 1480 | } |
1397 | 1481 | ||
1482 | /* when Super-I/O functions move to a separate file, the Super-I/O | ||
1483 | * bus will manage the lifetime of the device and this module will only keep | ||
1484 | * track of the w83627ehf driver. But since we platform_device_alloc(), we | ||
1485 | * must keep track of the device */ | ||
1486 | static struct platform_device *pdev; | ||
1487 | |||
1398 | static int __init sensors_w83627ehf_init(void) | 1488 | static int __init sensors_w83627ehf_init(void) |
1399 | { | 1489 | { |
1400 | if (w83627ehf_find(0x2e, &address) | 1490 | int err; |
1401 | && w83627ehf_find(0x4e, &address)) | 1491 | unsigned short address; |
1492 | struct resource res; | ||
1493 | struct w83627ehf_sio_data sio_data; | ||
1494 | |||
1495 | /* initialize sio_data->kind and sio_data->sioreg. | ||
1496 | * | ||
1497 | * when Super-I/O functions move to a separate file, the Super-I/O | ||
1498 | * driver will probe 0x2e and 0x4e and auto-detect the presence of a | ||
1499 | * w83627ehf hardware monitor, and call probe() */ | ||
1500 | if (w83627ehf_find(0x2e, &address, &sio_data) && | ||
1501 | w83627ehf_find(0x4e, &address, &sio_data)) | ||
1402 | return -ENODEV; | 1502 | return -ENODEV; |
1403 | 1503 | ||
1404 | return i2c_isa_add_driver(&w83627ehf_driver); | 1504 | err = platform_driver_register(&w83627ehf_driver); |
1505 | if (err) | ||
1506 | goto exit; | ||
1507 | |||
1508 | if (!(pdev = platform_device_alloc(DRVNAME, address))) { | ||
1509 | err = -ENOMEM; | ||
1510 | printk(KERN_ERR DRVNAME ": Device allocation failed\n"); | ||
1511 | goto exit_unregister; | ||
1512 | } | ||
1513 | |||
1514 | err = platform_device_add_data(pdev, &sio_data, | ||
1515 | sizeof(struct w83627ehf_sio_data)); | ||
1516 | if (err) { | ||
1517 | printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); | ||
1518 | goto exit_device_put; | ||
1519 | } | ||
1520 | |||
1521 | memset(&res, 0, sizeof(res)); | ||
1522 | res.name = DRVNAME; | ||
1523 | res.start = address + IOREGION_OFFSET; | ||
1524 | res.end = address + IOREGION_OFFSET + IOREGION_LENGTH - 1; | ||
1525 | res.flags = IORESOURCE_IO; | ||
1526 | err = platform_device_add_resources(pdev, &res, 1); | ||
1527 | if (err) { | ||
1528 | printk(KERN_ERR DRVNAME ": Device resource addition failed " | ||
1529 | "(%d)\n", err); | ||
1530 | goto exit_device_put; | ||
1531 | } | ||
1532 | |||
1533 | /* platform_device_add calls probe() */ | ||
1534 | err = platform_device_add(pdev); | ||
1535 | if (err) { | ||
1536 | printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", | ||
1537 | err); | ||
1538 | goto exit_device_put; | ||
1539 | } | ||
1540 | |||
1541 | return 0; | ||
1542 | |||
1543 | exit_device_put: | ||
1544 | platform_device_put(pdev); | ||
1545 | exit_unregister: | ||
1546 | platform_driver_unregister(&w83627ehf_driver); | ||
1547 | exit: | ||
1548 | return err; | ||
1405 | } | 1549 | } |
1406 | 1550 | ||
1407 | static void __exit sensors_w83627ehf_exit(void) | 1551 | static void __exit sensors_w83627ehf_exit(void) |
1408 | { | 1552 | { |
1409 | i2c_isa_del_driver(&w83627ehf_driver); | 1553 | platform_device_unregister(pdev); |
1554 | platform_driver_unregister(&w83627ehf_driver); | ||
1410 | } | 1555 | } |
1411 | 1556 | ||
1412 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); | 1557 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); |
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c index 12cb40a975de..1ce78179b005 100644 --- a/drivers/hwmon/w83627hf.c +++ b/drivers/hwmon/w83627hf.c | |||
@@ -220,6 +220,18 @@ static const u8 regpwm[] = { W83627THF_REG_PWM1, W83627THF_REG_PWM2, | |||
220 | #define W836X7HF_REG_PWM(type, nr) (((type) == w83627hf) ? \ | 220 | #define W836X7HF_REG_PWM(type, nr) (((type) == w83627hf) ? \ |
221 | regpwm_627hf[(nr) - 1] : regpwm[(nr) - 1]) | 221 | regpwm_627hf[(nr) - 1] : regpwm[(nr) - 1]) |
222 | 222 | ||
223 | #define W83627HF_REG_PWM_FREQ 0x5C /* Only for the 627HF */ | ||
224 | |||
225 | #define W83637HF_REG_PWM_FREQ1 0x00 /* 697HF/687THF too */ | ||
226 | #define W83637HF_REG_PWM_FREQ2 0x02 /* 697HF/687THF too */ | ||
227 | #define W83637HF_REG_PWM_FREQ3 0x10 /* 687THF too */ | ||
228 | |||
229 | static const u8 W83637HF_REG_PWM_FREQ[] = { W83637HF_REG_PWM_FREQ1, | ||
230 | W83637HF_REG_PWM_FREQ2, | ||
231 | W83637HF_REG_PWM_FREQ3 }; | ||
232 | |||
233 | #define W83627HF_BASE_PWM_FREQ 46870 | ||
234 | |||
223 | #define W83781D_REG_I2C_ADDR 0x48 | 235 | #define W83781D_REG_I2C_ADDR 0x48 |
224 | #define W83781D_REG_I2C_SUBADDR 0x4A | 236 | #define W83781D_REG_I2C_SUBADDR 0x4A |
225 | 237 | ||
@@ -267,6 +279,49 @@ static int TEMP_FROM_REG(u8 reg) | |||
267 | 279 | ||
268 | #define PWM_TO_REG(val) (SENSORS_LIMIT((val),0,255)) | 280 | #define PWM_TO_REG(val) (SENSORS_LIMIT((val),0,255)) |
269 | 281 | ||
282 | static inline unsigned long pwm_freq_from_reg_627hf(u8 reg) | ||
283 | { | ||
284 | unsigned long freq; | ||
285 | freq = W83627HF_BASE_PWM_FREQ >> reg; | ||
286 | return freq; | ||
287 | } | ||
288 | static inline u8 pwm_freq_to_reg_627hf(unsigned long val) | ||
289 | { | ||
290 | u8 i; | ||
291 | /* Only 5 dividers (1 2 4 8 16) | ||
292 | Search for the nearest available frequency */ | ||
293 | for (i = 0; i < 4; i++) { | ||
294 | if (val > (((W83627HF_BASE_PWM_FREQ >> i) + | ||
295 | (W83627HF_BASE_PWM_FREQ >> (i+1))) / 2)) | ||
296 | break; | ||
297 | } | ||
298 | return i; | ||
299 | } | ||
300 | |||
301 | static inline unsigned long pwm_freq_from_reg(u8 reg) | ||
302 | { | ||
303 | /* Clock bit 8 -> 180 kHz or 24 MHz */ | ||
304 | unsigned long clock = (reg & 0x80) ? 180000UL : 24000000UL; | ||
305 | |||
306 | reg &= 0x7f; | ||
307 | /* This should not happen but anyway... */ | ||
308 | if (reg == 0) | ||
309 | reg++; | ||
310 | return (clock / (reg << 8)); | ||
311 | } | ||
312 | static inline u8 pwm_freq_to_reg(unsigned long val) | ||
313 | { | ||
314 | /* Minimum divider value is 0x01 and maximum is 0x7F */ | ||
315 | if (val >= 93750) /* The highest we can do */ | ||
316 | return 0x01; | ||
317 | if (val >= 720) /* Use 24 MHz clock */ | ||
318 | return (24000000UL / (val << 8)); | ||
319 | if (val < 6) /* The lowest we can do */ | ||
320 | return 0xFF; | ||
321 | else /* Use 180 kHz clock */ | ||
322 | return (0x80 | (180000UL / (val << 8))); | ||
323 | } | ||
324 | |||
270 | #define BEEP_MASK_FROM_REG(val) (val) | 325 | #define BEEP_MASK_FROM_REG(val) (val) |
271 | #define BEEP_MASK_TO_REG(val) ((val) & 0xffffff) | 326 | #define BEEP_MASK_TO_REG(val) ((val) & 0xffffff) |
272 | #define BEEP_ENABLE_TO_REG(val) ((val)?1:0) | 327 | #define BEEP_ENABLE_TO_REG(val) ((val)?1:0) |
@@ -316,6 +371,7 @@ struct w83627hf_data { | |||
316 | u32 beep_mask; /* Register encoding, combined */ | 371 | u32 beep_mask; /* Register encoding, combined */ |
317 | u8 beep_enable; /* Boolean */ | 372 | u8 beep_enable; /* Boolean */ |
318 | u8 pwm[3]; /* Register value */ | 373 | u8 pwm[3]; /* Register value */ |
374 | u8 pwm_freq[3]; /* Register value */ | ||
319 | u16 sens[3]; /* 782D/783S only. | 375 | u16 sens[3]; /* 782D/783S only. |
320 | 1 = pentium diode; 2 = 3904 diode; | 376 | 1 = pentium diode; 2 = 3904 diode; |
321 | 3000-5000 = thermistor beta. | 377 | 3000-5000 = thermistor beta. |
@@ -852,6 +908,64 @@ sysfs_pwm(2); | |||
852 | sysfs_pwm(3); | 908 | sysfs_pwm(3); |
853 | 909 | ||
854 | static ssize_t | 910 | static ssize_t |
911 | show_pwm_freq_reg(struct device *dev, char *buf, int nr) | ||
912 | { | ||
913 | struct w83627hf_data *data = w83627hf_update_device(dev); | ||
914 | if (data->type == w83627hf) | ||
915 | return sprintf(buf, "%ld\n", | ||
916 | pwm_freq_from_reg_627hf(data->pwm_freq[nr - 1])); | ||
917 | else | ||
918 | return sprintf(buf, "%ld\n", | ||
919 | pwm_freq_from_reg(data->pwm_freq[nr - 1])); | ||
920 | } | ||
921 | |||
922 | static ssize_t | ||
923 | store_pwm_freq_reg(struct device *dev, const char *buf, size_t count, int nr) | ||
924 | { | ||
925 | struct w83627hf_data *data = dev_get_drvdata(dev); | ||
926 | static const u8 mask[]={0xF8, 0x8F}; | ||
927 | u32 val; | ||
928 | |||
929 | val = simple_strtoul(buf, NULL, 10); | ||
930 | |||
931 | mutex_lock(&data->update_lock); | ||
932 | |||
933 | if (data->type == w83627hf) { | ||
934 | data->pwm_freq[nr - 1] = pwm_freq_to_reg_627hf(val); | ||
935 | w83627hf_write_value(data, W83627HF_REG_PWM_FREQ, | ||
936 | (data->pwm_freq[nr - 1] << ((nr - 1)*4)) | | ||
937 | (w83627hf_read_value(data, | ||
938 | W83627HF_REG_PWM_FREQ) & mask[nr - 1])); | ||
939 | } else { | ||
940 | data->pwm_freq[nr - 1] = pwm_freq_to_reg(val); | ||
941 | w83627hf_write_value(data, W83637HF_REG_PWM_FREQ[nr - 1], | ||
942 | data->pwm_freq[nr - 1]); | ||
943 | } | ||
944 | |||
945 | mutex_unlock(&data->update_lock); | ||
946 | return count; | ||
947 | } | ||
948 | |||
949 | #define sysfs_pwm_freq(offset) \ | ||
950 | static ssize_t show_regs_pwm_freq_##offset(struct device *dev, \ | ||
951 | struct device_attribute *attr, char *buf) \ | ||
952 | { \ | ||
953 | return show_pwm_freq_reg(dev, buf, offset); \ | ||
954 | } \ | ||
955 | static ssize_t \ | ||
956 | store_regs_pwm_freq_##offset(struct device *dev, \ | ||
957 | struct device_attribute *attr, const char *buf, size_t count) \ | ||
958 | { \ | ||
959 | return store_pwm_freq_reg(dev, buf, count, offset); \ | ||
960 | } \ | ||
961 | static DEVICE_ATTR(pwm##offset##_freq, S_IRUGO | S_IWUSR, \ | ||
962 | show_regs_pwm_freq_##offset, store_regs_pwm_freq_##offset); | ||
963 | |||
964 | sysfs_pwm_freq(1); | ||
965 | sysfs_pwm_freq(2); | ||
966 | sysfs_pwm_freq(3); | ||
967 | |||
968 | static ssize_t | ||
855 | show_sensor_reg(struct device *dev, char *buf, int nr) | 969 | show_sensor_reg(struct device *dev, char *buf, int nr) |
856 | { | 970 | { |
857 | struct w83627hf_data *data = w83627hf_update_device(dev); | 971 | struct w83627hf_data *data = w83627hf_update_device(dev); |
@@ -1077,6 +1191,9 @@ static struct attribute *w83627hf_attributes_opt[] = { | |||
1077 | 1191 | ||
1078 | &dev_attr_pwm3.attr, | 1192 | &dev_attr_pwm3.attr, |
1079 | 1193 | ||
1194 | &dev_attr_pwm1_freq.attr, | ||
1195 | &dev_attr_pwm2_freq.attr, | ||
1196 | &dev_attr_pwm3_freq.attr, | ||
1080 | NULL | 1197 | NULL |
1081 | }; | 1198 | }; |
1082 | 1199 | ||
@@ -1139,7 +1256,9 @@ static int __devinit w83627hf_probe(struct platform_device *pdev) | |||
1139 | || (err = device_create_file(dev, &dev_attr_in5_max)) | 1256 | || (err = device_create_file(dev, &dev_attr_in5_max)) |
1140 | || (err = device_create_file(dev, &dev_attr_in6_input)) | 1257 | || (err = device_create_file(dev, &dev_attr_in6_input)) |
1141 | || (err = device_create_file(dev, &dev_attr_in6_min)) | 1258 | || (err = device_create_file(dev, &dev_attr_in6_min)) |
1142 | || (err = device_create_file(dev, &dev_attr_in6_max))) | 1259 | || (err = device_create_file(dev, &dev_attr_in6_max)) |
1260 | || (err = device_create_file(dev, &dev_attr_pwm1_freq)) | ||
1261 | || (err = device_create_file(dev, &dev_attr_pwm2_freq))) | ||
1143 | goto ERROR4; | 1262 | goto ERROR4; |
1144 | 1263 | ||
1145 | if (data->type != w83697hf) | 1264 | if (data->type != w83697hf) |
@@ -1169,6 +1288,12 @@ static int __devinit w83627hf_probe(struct platform_device *pdev) | |||
1169 | if ((err = device_create_file(dev, &dev_attr_pwm3))) | 1288 | if ((err = device_create_file(dev, &dev_attr_pwm3))) |
1170 | goto ERROR4; | 1289 | goto ERROR4; |
1171 | 1290 | ||
1291 | if (data->type == w83637hf || data->type == w83687thf) | ||
1292 | if ((err = device_create_file(dev, &dev_attr_pwm1_freq)) | ||
1293 | || (err = device_create_file(dev, &dev_attr_pwm2_freq)) | ||
1294 | || (err = device_create_file(dev, &dev_attr_pwm3_freq))) | ||
1295 | goto ERROR4; | ||
1296 | |||
1172 | data->class_dev = hwmon_device_register(dev); | 1297 | data->class_dev = hwmon_device_register(dev); |
1173 | if (IS_ERR(data->class_dev)) { | 1298 | if (IS_ERR(data->class_dev)) { |
1174 | err = PTR_ERR(data->class_dev); | 1299 | err = PTR_ERR(data->class_dev); |
@@ -1181,6 +1306,7 @@ static int __devinit w83627hf_probe(struct platform_device *pdev) | |||
1181 | sysfs_remove_group(&dev->kobj, &w83627hf_group); | 1306 | sysfs_remove_group(&dev->kobj, &w83627hf_group); |
1182 | sysfs_remove_group(&dev->kobj, &w83627hf_group_opt); | 1307 | sysfs_remove_group(&dev->kobj, &w83627hf_group_opt); |
1183 | ERROR3: | 1308 | ERROR3: |
1309 | platform_set_drvdata(pdev, NULL); | ||
1184 | kfree(data); | 1310 | kfree(data); |
1185 | ERROR1: | 1311 | ERROR1: |
1186 | release_region(res->start, WINB_REGION_SIZE); | 1312 | release_region(res->start, WINB_REGION_SIZE); |
@@ -1193,11 +1319,11 @@ static int __devexit w83627hf_remove(struct platform_device *pdev) | |||
1193 | struct w83627hf_data *data = platform_get_drvdata(pdev); | 1319 | struct w83627hf_data *data = platform_get_drvdata(pdev); |
1194 | struct resource *res; | 1320 | struct resource *res; |
1195 | 1321 | ||
1196 | platform_set_drvdata(pdev, NULL); | ||
1197 | hwmon_device_unregister(data->class_dev); | 1322 | hwmon_device_unregister(data->class_dev); |
1198 | 1323 | ||
1199 | sysfs_remove_group(&pdev->dev.kobj, &w83627hf_group); | 1324 | sysfs_remove_group(&pdev->dev.kobj, &w83627hf_group); |
1200 | sysfs_remove_group(&pdev->dev.kobj, &w83627hf_group_opt); | 1325 | sysfs_remove_group(&pdev->dev.kobj, &w83627hf_group_opt); |
1326 | platform_set_drvdata(pdev, NULL); | ||
1201 | kfree(data); | 1327 | kfree(data); |
1202 | 1328 | ||
1203 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | 1329 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
@@ -1472,6 +1598,20 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev) | |||
1472 | (data->type == w83627hf || data->type == w83697hf)) | 1598 | (data->type == w83627hf || data->type == w83697hf)) |
1473 | break; | 1599 | break; |
1474 | } | 1600 | } |
1601 | if (data->type == w83627hf) { | ||
1602 | u8 tmp = w83627hf_read_value(data, | ||
1603 | W83627HF_REG_PWM_FREQ); | ||
1604 | data->pwm_freq[0] = tmp & 0x07; | ||
1605 | data->pwm_freq[1] = (tmp >> 4) & 0x07; | ||
1606 | } else if (data->type != w83627thf) { | ||
1607 | for (i = 1; i <= 3; i++) { | ||
1608 | data->pwm_freq[i - 1] = | ||
1609 | w83627hf_read_value(data, | ||
1610 | W83637HF_REG_PWM_FREQ[i - 1]); | ||
1611 | if (i == 2 && (data->type == w83697hf)) | ||
1612 | break; | ||
1613 | } | ||
1614 | } | ||
1475 | 1615 | ||
1476 | data->temp = w83627hf_read_value(data, W83781D_REG_TEMP(1)); | 1616 | data->temp = w83627hf_read_value(data, W83781D_REG_TEMP(1)); |
1477 | data->temp_max = | 1617 | data->temp_max = |
@@ -1548,15 +1688,12 @@ static int __init w83627hf_device_add(unsigned short address, | |||
1548 | goto exit_device_put; | 1688 | goto exit_device_put; |
1549 | } | 1689 | } |
1550 | 1690 | ||
1551 | pdev->dev.platform_data = kmalloc(sizeof(struct w83627hf_sio_data), | 1691 | err = platform_device_add_data(pdev, sio_data, |
1552 | GFP_KERNEL); | 1692 | sizeof(struct w83627hf_sio_data)); |
1553 | if (!pdev->dev.platform_data) { | 1693 | if (err) { |
1554 | err = -ENOMEM; | ||
1555 | printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); | 1694 | printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); |
1556 | goto exit_device_put; | 1695 | goto exit_device_put; |
1557 | } | 1696 | } |
1558 | memcpy(pdev->dev.platform_data, sio_data, | ||
1559 | sizeof(struct w83627hf_sio_data)); | ||
1560 | 1697 | ||
1561 | err = platform_device_add(pdev); | 1698 | err = platform_device_add(pdev); |
1562 | if (err) { | 1699 | if (err) { |
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 1c77e14480dc..da1647869f91 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig | |||
@@ -237,9 +237,6 @@ config I2C_IOP3XX | |||
237 | This driver can also be built as a module. If so, the module | 237 | This driver can also be built as a module. If so, the module |
238 | will be called i2c-iop3xx. | 238 | will be called i2c-iop3xx. |
239 | 239 | ||
240 | config I2C_ISA | ||
241 | tristate | ||
242 | |||
243 | config I2C_IXP4XX | 240 | config I2C_IXP4XX |
244 | tristate "IXP4xx GPIO-Based I2C Interface (DEPRECATED)" | 241 | tristate "IXP4xx GPIO-Based I2C Interface (DEPRECATED)" |
245 | depends on ARCH_IXP4XX | 242 | depends on ARCH_IXP4XX |
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index a6db4e38bda8..5b752e4e1918 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile | |||
@@ -18,7 +18,6 @@ obj-$(CONFIG_I2C_I801) += i2c-i801.o | |||
18 | obj-$(CONFIG_I2C_I810) += i2c-i810.o | 18 | obj-$(CONFIG_I2C_I810) += i2c-i810.o |
19 | obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o | 19 | obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o |
20 | obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o | 20 | obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o |
21 | obj-$(CONFIG_I2C_ISA) += i2c-isa.o | ||
22 | obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o | 21 | obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o |
23 | obj-$(CONFIG_I2C_IXP4XX) += i2c-ixp4xx.o | 22 | obj-$(CONFIG_I2C_IXP4XX) += i2c-ixp4xx.o |
24 | obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o | 23 | obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o |
diff --git a/drivers/i2c/busses/i2c-isa.c b/drivers/i2c/busses/i2c-isa.c deleted file mode 100644 index b0e1370075de..000000000000 --- a/drivers/i2c/busses/i2c-isa.c +++ /dev/null | |||
@@ -1,192 +0,0 @@ | |||
1 | /* | ||
2 | i2c-isa.c - an i2c-core-like thing for ISA hardware monitoring chips | ||
3 | Copyright (C) 2005 Jean Delvare <khali@linux-fr.org> | ||
4 | |||
5 | Based on the i2c-isa pseudo-adapter from the lm_sensors project | ||
6 | Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> | ||
7 | |||
8 | This program is free software; you can redistribute it and/or modify | ||
9 | it under the terms of the GNU General Public License as published by | ||
10 | the Free Software Foundation; either version 2 of the License, or | ||
11 | (at your option) any later version. | ||
12 | |||
13 | This program is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | GNU General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU General Public License | ||
19 | along with this program; if not, write to the Free Software | ||
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
21 | */ | ||
22 | |||
23 | /* This implements an i2c-core-like thing for ISA hardware monitoring | ||
24 | chips. Such chips are linked to the i2c subsystem for historical | ||
25 | reasons (because the early ISA hardware monitoring chips such as the | ||
26 | LM78 had both an I2C and an ISA interface). They used to be | ||
27 | registered with the main i2c-core, but as a first step in the | ||
28 | direction of a clean separation between I2C and ISA chip drivers, | ||
29 | we now have this separate core for ISA ones. It is significantly | ||
30 | more simple than the real one, of course, because we don't have to | ||
31 | handle multiple busses: there is only one (fake) ISA adapter. | ||
32 | It is worth noting that we still rely on i2c-core for some things | ||
33 | at the moment - but hopefully this won't last. */ | ||
34 | |||
35 | #include <linux/init.h> | ||
36 | #include <linux/module.h> | ||
37 | #include <linux/kernel.h> | ||
38 | #include <linux/errno.h> | ||
39 | #include <linux/i2c.h> | ||
40 | #include <linux/i2c-isa.h> | ||
41 | #include <linux/platform_device.h> | ||
42 | #include <linux/completion.h> | ||
43 | |||
44 | /* Exported by i2c-core for i2c-isa only */ | ||
45 | extern void i2c_adapter_dev_release(struct device *dev); | ||
46 | extern struct class i2c_adapter_class; | ||
47 | |||
48 | static u32 isa_func(struct i2c_adapter *adapter); | ||
49 | |||
50 | /* This is the actual algorithm we define */ | ||
51 | static const struct i2c_algorithm isa_algorithm = { | ||
52 | .functionality = isa_func, | ||
53 | }; | ||
54 | |||
55 | /* There can only be one... */ | ||
56 | static struct i2c_adapter isa_adapter = { | ||
57 | .owner = THIS_MODULE, | ||
58 | .id = I2C_HW_ISA, | ||
59 | .class = I2C_CLASS_HWMON, | ||
60 | .algo = &isa_algorithm, | ||
61 | .name = "ISA main adapter", | ||
62 | }; | ||
63 | |||
64 | /* We can't do a thing... */ | ||
65 | static u32 isa_func(struct i2c_adapter *adapter) | ||
66 | { | ||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | |||
71 | /* We implement an interface which resembles i2c_{add,del}_driver, | ||
72 | but for i2c-isa drivers. We don't have to remember and handle lists | ||
73 | of drivers and adapters so this is much more simple, of course. */ | ||
74 | |||
75 | int i2c_isa_add_driver(struct i2c_driver *driver) | ||
76 | { | ||
77 | int res; | ||
78 | |||
79 | /* Add the driver to the list of i2c drivers in the driver core */ | ||
80 | driver->driver.bus = &i2c_bus_type; | ||
81 | res = driver_register(&driver->driver); | ||
82 | if (res) | ||
83 | return res; | ||
84 | dev_dbg(&isa_adapter.dev, "Driver %s registered\n", driver->driver.name); | ||
85 | |||
86 | /* Now look for clients */ | ||
87 | res = driver->attach_adapter(&isa_adapter); | ||
88 | if (res) { | ||
89 | dev_dbg(&isa_adapter.dev, | ||
90 | "Driver %s failed to attach adapter, unregistering\n", | ||
91 | driver->driver.name); | ||
92 | driver_unregister(&driver->driver); | ||
93 | } | ||
94 | return res; | ||
95 | } | ||
96 | |||
97 | int i2c_isa_del_driver(struct i2c_driver *driver) | ||
98 | { | ||
99 | struct list_head *item, *_n; | ||
100 | struct i2c_client *client; | ||
101 | int res; | ||
102 | |||
103 | /* Detach all clients belonging to this one driver */ | ||
104 | list_for_each_safe(item, _n, &isa_adapter.clients) { | ||
105 | client = list_entry(item, struct i2c_client, list); | ||
106 | if (client->driver != driver) | ||
107 | continue; | ||
108 | dev_dbg(&isa_adapter.dev, "Detaching client %s at 0x%x\n", | ||
109 | client->name, client->addr); | ||
110 | if ((res = driver->detach_client(client))) { | ||
111 | dev_err(&isa_adapter.dev, "Failed, driver " | ||
112 | "%s not unregistered!\n", | ||
113 | driver->driver.name); | ||
114 | return res; | ||
115 | } | ||
116 | } | ||
117 | |||
118 | /* Get the driver off the core list */ | ||
119 | driver_unregister(&driver->driver); | ||
120 | dev_dbg(&isa_adapter.dev, "Driver %s unregistered\n", driver->driver.name); | ||
121 | |||
122 | return 0; | ||
123 | } | ||
124 | |||
125 | |||
126 | static int __init i2c_isa_init(void) | ||
127 | { | ||
128 | int err; | ||
129 | |||
130 | mutex_init(&isa_adapter.clist_lock); | ||
131 | INIT_LIST_HEAD(&isa_adapter.clients); | ||
132 | |||
133 | isa_adapter.nr = ANY_I2C_ISA_BUS; | ||
134 | isa_adapter.dev.parent = &platform_bus; | ||
135 | sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr); | ||
136 | isa_adapter.dev.release = &i2c_adapter_dev_release; | ||
137 | isa_adapter.dev.class = &i2c_adapter_class; | ||
138 | err = device_register(&isa_adapter.dev); | ||
139 | if (err) { | ||
140 | printk(KERN_ERR "i2c-isa: Failed to register device\n"); | ||
141 | goto exit; | ||
142 | } | ||
143 | |||
144 | dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name); | ||
145 | |||
146 | return 0; | ||
147 | |||
148 | exit: | ||
149 | return err; | ||
150 | } | ||
151 | |||
152 | static void __exit i2c_isa_exit(void) | ||
153 | { | ||
154 | #ifdef DEBUG | ||
155 | struct list_head *item, *_n; | ||
156 | struct i2c_client *client = NULL; | ||
157 | #endif | ||
158 | |||
159 | /* There should be no more active client */ | ||
160 | #ifdef DEBUG | ||
161 | dev_dbg(&isa_adapter.dev, "Looking for clients\n"); | ||
162 | list_for_each_safe(item, _n, &isa_adapter.clients) { | ||
163 | client = list_entry(item, struct i2c_client, list); | ||
164 | dev_err(&isa_adapter.dev, "Driver %s still has an active " | ||
165 | "ISA client at 0x%x\n", client->driver->driver.name, | ||
166 | client->addr); | ||
167 | } | ||
168 | if (client != NULL) | ||
169 | return; | ||
170 | #endif | ||
171 | |||
172 | /* Clean up the sysfs representation */ | ||
173 | dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n"); | ||
174 | init_completion(&isa_adapter.dev_released); | ||
175 | device_unregister(&isa_adapter.dev); | ||
176 | |||
177 | /* Wait for sysfs to drop all references */ | ||
178 | dev_dbg(&isa_adapter.dev, "Waiting for sysfs completion\n"); | ||
179 | wait_for_completion(&isa_adapter.dev_released); | ||
180 | |||
181 | dev_dbg(&isa_adapter.dev, "%s unregistered\n", isa_adapter.name); | ||
182 | } | ||
183 | |||
184 | EXPORT_SYMBOL(i2c_isa_add_driver); | ||
185 | EXPORT_SYMBOL(i2c_isa_del_driver); | ||
186 | |||
187 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); | ||
188 | MODULE_DESCRIPTION("ISA bus access through i2c"); | ||
189 | MODULE_LICENSE("GPL"); | ||
190 | |||
191 | module_init(i2c_isa_init); | ||
192 | module_exit(i2c_isa_exit); | ||
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 6971a62397db..d663e6960d93 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -288,7 +288,6 @@ void i2c_adapter_dev_release(struct device *dev) | |||
288 | struct i2c_adapter *adap = to_i2c_adapter(dev); | 288 | struct i2c_adapter *adap = to_i2c_adapter(dev); |
289 | complete(&adap->dev_released); | 289 | complete(&adap->dev_released); |
290 | } | 290 | } |
291 | EXPORT_SYMBOL_GPL(i2c_adapter_dev_release); /* exported to i2c-isa */ | ||
292 | 291 | ||
293 | static ssize_t | 292 | static ssize_t |
294 | show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf) | 293 | show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf) |
@@ -307,7 +306,6 @@ struct class i2c_adapter_class = { | |||
307 | .name = "i2c-adapter", | 306 | .name = "i2c-adapter", |
308 | .dev_attrs = i2c_adapter_attrs, | 307 | .dev_attrs = i2c_adapter_attrs, |
309 | }; | 308 | }; |
310 | EXPORT_SYMBOL_GPL(i2c_adapter_class); /* exported to i2c-isa */ | ||
311 | 309 | ||
312 | static void i2c_scan_static_board_info(struct i2c_adapter *adapter) | 310 | static void i2c_scan_static_board_info(struct i2c_adapter *adapter) |
313 | { | 311 | { |
diff --git a/drivers/ide/cris/ide-cris.c b/drivers/ide/cris/ide-cris.c index 886091bc7db0..fbfea46a34f2 100644 --- a/drivers/ide/cris/ide-cris.c +++ b/drivers/ide/cris/ide-cris.c | |||
@@ -414,12 +414,6 @@ cris_ide_reset(unsigned val) | |||
414 | #ifdef CONFIG_ETRAX_IDE_G27_RESET | 414 | #ifdef CONFIG_ETRAX_IDE_G27_RESET |
415 | REG_SHADOW_SET(R_PORT_G_DATA, port_g_data_shadow, 27, val); | 415 | REG_SHADOW_SET(R_PORT_G_DATA, port_g_data_shadow, 27, val); |
416 | #endif | 416 | #endif |
417 | #ifdef CONFIG_ETRAX_IDE_CSE1_16_RESET | ||
418 | REG_SHADOW_SET(port_cse1_addr, port_cse1_shadow, 16, val); | ||
419 | #endif | ||
420 | #ifdef CONFIG_ETRAX_IDE_CSP0_8_RESET | ||
421 | REG_SHADOW_SET(port_csp0_addr, port_csp0_shadow, 8, val); | ||
422 | #endif | ||
423 | #ifdef CONFIG_ETRAX_IDE_PB7_RESET | 417 | #ifdef CONFIG_ETRAX_IDE_PB7_RESET |
424 | port_pb_dir_shadow = port_pb_dir_shadow | | 418 | port_pb_dir_shadow = port_pb_dir_shadow | |
425 | IO_STATE(R_PORT_PB_DIR, dir7, output); | 419 | IO_STATE(R_PORT_PB_DIR, dir7, output); |
@@ -690,6 +684,8 @@ static void tune_cris_ide(ide_drive_t *drive, u8 pio) | |||
690 | { | 684 | { |
691 | int setup, strobe, hold; | 685 | int setup, strobe, hold; |
692 | 686 | ||
687 | pio = ide_get_best_pio_mode(drive, pio, 4); | ||
688 | |||
693 | switch(pio) | 689 | switch(pio) |
694 | { | 690 | { |
695 | case 0: | 691 | case 0: |
@@ -820,6 +816,7 @@ init_e100_ide (void) | |||
820 | hwif->dma_host_on = &cris_dma_on; | 816 | hwif->dma_host_on = &cris_dma_on; |
821 | hwif->dma_off_quietly = &cris_dma_off; | 817 | hwif->dma_off_quietly = &cris_dma_off; |
822 | hwif->cbl = ATA_CBL_PATA40; | 818 | hwif->cbl = ATA_CBL_PATA40; |
819 | hwif->pio_mask = ATA_PIO4, | ||
823 | hwif->ultra_mask = cris_ultra_mask; | 820 | hwif->ultra_mask = cris_ultra_mask; |
824 | hwif->mwdma_mask = 0x07; /* Multiword DMA 0-2 */ | 821 | hwif->mwdma_mask = 0x07; /* Multiword DMA 0-2 */ |
825 | hwif->autodma = 1; | 822 | hwif->autodma = 1; |
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c index a21f585b1caa..ae8e1a64b8ad 100644 --- a/drivers/ide/ide-floppy.c +++ b/drivers/ide/ide-floppy.c | |||
@@ -99,6 +99,8 @@ | |||
99 | #include <linux/bitops.h> | 99 | #include <linux/bitops.h> |
100 | #include <linux/mutex.h> | 100 | #include <linux/mutex.h> |
101 | 101 | ||
102 | #include <scsi/scsi_ioctl.h> | ||
103 | |||
102 | #include <asm/byteorder.h> | 104 | #include <asm/byteorder.h> |
103 | #include <asm/irq.h> | 105 | #include <asm/irq.h> |
104 | #include <asm/uaccess.h> | 106 | #include <asm/uaccess.h> |
@@ -2099,7 +2101,21 @@ static int idefloppy_ioctl(struct inode *inode, struct file *file, | |||
2099 | case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS: | 2101 | case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS: |
2100 | return idefloppy_get_format_progress(drive, argp); | 2102 | return idefloppy_get_format_progress(drive, argp); |
2101 | } | 2103 | } |
2102 | return generic_ide_ioctl(drive, file, bdev, cmd, arg); | 2104 | |
2105 | /* | ||
2106 | * skip SCSI_IOCTL_SEND_COMMAND (deprecated) | ||
2107 | * and CDROM_SEND_PACKET (legacy) ioctls | ||
2108 | */ | ||
2109 | if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND) | ||
2110 | err = scsi_cmd_ioctl(file, bdev->bd_disk->queue, | ||
2111 | bdev->bd_disk, cmd, argp); | ||
2112 | else | ||
2113 | err = -ENOTTY; | ||
2114 | |||
2115 | if (err == -ENOTTY) | ||
2116 | err = generic_ide_ioctl(drive, file, bdev, cmd, arg); | ||
2117 | |||
2118 | return err; | ||
2103 | } | 2119 | } |
2104 | 2120 | ||
2105 | static int idefloppy_media_changed(struct gendisk *disk) | 2121 | static int idefloppy_media_changed(struct gendisk *disk) |
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c index c5b5011da56e..484c50e71446 100644 --- a/drivers/ide/ide-io.c +++ b/drivers/ide/ide-io.c | |||
@@ -55,7 +55,7 @@ | |||
55 | #include <asm/bitops.h> | 55 | #include <asm/bitops.h> |
56 | 56 | ||
57 | static int __ide_end_request(ide_drive_t *drive, struct request *rq, | 57 | static int __ide_end_request(ide_drive_t *drive, struct request *rq, |
58 | int uptodate, int nr_sectors) | 58 | int uptodate, unsigned int nr_bytes) |
59 | { | 59 | { |
60 | int ret = 1; | 60 | int ret = 1; |
61 | 61 | ||
@@ -64,7 +64,7 @@ static int __ide_end_request(ide_drive_t *drive, struct request *rq, | |||
64 | * complete the whole request right now | 64 | * complete the whole request right now |
65 | */ | 65 | */ |
66 | if (blk_noretry_request(rq) && end_io_error(uptodate)) | 66 | if (blk_noretry_request(rq) && end_io_error(uptodate)) |
67 | nr_sectors = rq->hard_nr_sectors; | 67 | nr_bytes = rq->hard_nr_sectors << 9; |
68 | 68 | ||
69 | if (!blk_fs_request(rq) && end_io_error(uptodate) && !rq->errors) | 69 | if (!blk_fs_request(rq) && end_io_error(uptodate) && !rq->errors) |
70 | rq->errors = -EIO; | 70 | rq->errors = -EIO; |
@@ -78,7 +78,7 @@ static int __ide_end_request(ide_drive_t *drive, struct request *rq, | |||
78 | HWGROUP(drive)->hwif->ide_dma_on(drive); | 78 | HWGROUP(drive)->hwif->ide_dma_on(drive); |
79 | } | 79 | } |
80 | 80 | ||
81 | if (!end_that_request_first(rq, uptodate, nr_sectors)) { | 81 | if (!end_that_request_chunk(rq, uptodate, nr_bytes)) { |
82 | add_disk_randomness(rq->rq_disk); | 82 | add_disk_randomness(rq->rq_disk); |
83 | if (!list_empty(&rq->queuelist)) | 83 | if (!list_empty(&rq->queuelist)) |
84 | blkdev_dequeue_request(rq); | 84 | blkdev_dequeue_request(rq); |
@@ -103,6 +103,7 @@ static int __ide_end_request(ide_drive_t *drive, struct request *rq, | |||
103 | 103 | ||
104 | int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors) | 104 | int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors) |
105 | { | 105 | { |
106 | unsigned int nr_bytes = nr_sectors << 9; | ||
106 | struct request *rq; | 107 | struct request *rq; |
107 | unsigned long flags; | 108 | unsigned long flags; |
108 | int ret = 1; | 109 | int ret = 1; |
@@ -114,10 +115,14 @@ int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors) | |||
114 | spin_lock_irqsave(&ide_lock, flags); | 115 | spin_lock_irqsave(&ide_lock, flags); |
115 | rq = HWGROUP(drive)->rq; | 116 | rq = HWGROUP(drive)->rq; |
116 | 117 | ||
117 | if (!nr_sectors) | 118 | if (!nr_bytes) { |
118 | nr_sectors = rq->hard_cur_sectors; | 119 | if (blk_pc_request(rq)) |
120 | nr_bytes = rq->data_len; | ||
121 | else | ||
122 | nr_bytes = rq->hard_cur_sectors << 9; | ||
123 | } | ||
119 | 124 | ||
120 | ret = __ide_end_request(drive, rq, uptodate, nr_sectors); | 125 | ret = __ide_end_request(drive, rq, uptodate, nr_bytes); |
121 | 126 | ||
122 | spin_unlock_irqrestore(&ide_lock, flags); | 127 | spin_unlock_irqrestore(&ide_lock, flags); |
123 | return ret; | 128 | return ret; |
@@ -219,11 +224,12 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request * | |||
219 | * we could be smarter and check for current xfer_speed | 224 | * we could be smarter and check for current xfer_speed |
220 | * in struct drive etc... | 225 | * in struct drive etc... |
221 | */ | 226 | */ |
222 | if ((drive->id->capability & 1) == 0) | ||
223 | break; | ||
224 | if (drive->hwif->ide_dma_check == NULL) | 227 | if (drive->hwif->ide_dma_check == NULL) |
225 | break; | 228 | break; |
226 | drive->hwif->dma_off_quietly(drive); | 229 | drive->hwif->dma_off_quietly(drive); |
230 | /* | ||
231 | * TODO: respect ->using_dma setting | ||
232 | */ | ||
227 | ide_set_dma(drive); | 233 | ide_set_dma(drive); |
228 | break; | 234 | break; |
229 | } | 235 | } |
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c index 074bb32a4a40..92a6c7bcf527 100644 --- a/drivers/ide/ide-lib.c +++ b/drivers/ide/ide-lib.c | |||
@@ -249,12 +249,34 @@ static int ide_scan_pio_blacklist (char *model) | |||
249 | return -1; | 249 | return -1; |
250 | } | 250 | } |
251 | 251 | ||
252 | unsigned int ide_pio_cycle_time(ide_drive_t *drive, u8 pio) | ||
253 | { | ||
254 | struct hd_driveid *id = drive->id; | ||
255 | int cycle_time = 0; | ||
256 | |||
257 | if (id->field_valid & 2) { | ||
258 | if (id->capability & 8) | ||
259 | cycle_time = id->eide_pio_iordy; | ||
260 | else | ||
261 | cycle_time = id->eide_pio; | ||
262 | } | ||
263 | |||
264 | /* conservative "downgrade" for all pre-ATA2 drives */ | ||
265 | if (pio < 3) { | ||
266 | if (cycle_time && cycle_time < ide_pio_timings[pio].cycle_time) | ||
267 | cycle_time = 0; /* use standard timing */ | ||
268 | } | ||
269 | |||
270 | return cycle_time ? cycle_time : ide_pio_timings[pio].cycle_time; | ||
271 | } | ||
272 | |||
273 | EXPORT_SYMBOL_GPL(ide_pio_cycle_time); | ||
274 | |||
252 | /** | 275 | /** |
253 | * ide_get_best_pio_mode - get PIO mode from drive | 276 | * ide_get_best_pio_mode - get PIO mode from drive |
254 | * @drive: drive to consider | 277 | * @drive: drive to consider |
255 | * @mode_wanted: preferred mode | 278 | * @mode_wanted: preferred mode |
256 | * @max_mode: highest allowed mode | 279 | * @max_mode: highest allowed mode |
257 | * @d: PIO data | ||
258 | * | 280 | * |
259 | * This routine returns the recommended PIO settings for a given drive, | 281 | * This routine returns the recommended PIO settings for a given drive, |
260 | * based on the drive->id information and the ide_pio_blacklist[]. | 282 | * based on the drive->id information and the ide_pio_blacklist[]. |
@@ -263,22 +285,18 @@ static int ide_scan_pio_blacklist (char *model) | |||
263 | * This is used by most chipset support modules when "auto-tuning". | 285 | * This is used by most chipset support modules when "auto-tuning". |
264 | */ | 286 | */ |
265 | 287 | ||
266 | u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_pio_data_t *d) | 288 | u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode) |
267 | { | 289 | { |
268 | int pio_mode; | 290 | int pio_mode; |
269 | int cycle_time = 0; | ||
270 | int use_iordy = 0; | ||
271 | struct hd_driveid* id = drive->id; | 291 | struct hd_driveid* id = drive->id; |
272 | int overridden = 0; | 292 | int overridden = 0; |
273 | 293 | ||
274 | if (mode_wanted != 255) { | 294 | if (mode_wanted != 255) |
275 | pio_mode = mode_wanted; | 295 | return min_t(u8, mode_wanted, max_mode); |
276 | use_iordy = (pio_mode > 2); | 296 | |
277 | } else if (!drive->id) { | 297 | if ((drive->hwif->host_flags & IDE_HFLAG_PIO_NO_BLACKLIST) == 0 && |
278 | pio_mode = 0; | 298 | (pio_mode = ide_scan_pio_blacklist(id->model)) != -1) { |
279 | } else if ((pio_mode = ide_scan_pio_blacklist(id->model)) != -1) { | 299 | printk(KERN_INFO "%s: is on PIO blacklist\n", drive->name); |
280 | overridden = 1; | ||
281 | use_iordy = (pio_mode > 2); | ||
282 | } else { | 300 | } else { |
283 | pio_mode = id->tPIO; | 301 | pio_mode = id->tPIO; |
284 | if (pio_mode > 2) { /* 2 is maximum allowed tPIO value */ | 302 | if (pio_mode > 2) { /* 2 is maximum allowed tPIO value */ |
@@ -286,9 +304,7 @@ u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_p | |||
286 | overridden = 1; | 304 | overridden = 1; |
287 | } | 305 | } |
288 | if (id->field_valid & 2) { /* drive implements ATA2? */ | 306 | if (id->field_valid & 2) { /* drive implements ATA2? */ |
289 | if (id->capability & 8) { /* drive supports use_iordy? */ | 307 | if (id->capability & 8) { /* IORDY supported? */ |
290 | use_iordy = 1; | ||
291 | cycle_time = id->eide_pio_iordy; | ||
292 | if (id->eide_pio_modes & 7) { | 308 | if (id->eide_pio_modes & 7) { |
293 | overridden = 0; | 309 | overridden = 0; |
294 | if (id->eide_pio_modes & 4) | 310 | if (id->eide_pio_modes & 4) |
@@ -298,31 +314,27 @@ u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_p | |||
298 | else | 314 | else |
299 | pio_mode = 3; | 315 | pio_mode = 3; |
300 | } | 316 | } |
301 | } else { | ||
302 | cycle_time = id->eide_pio; | ||
303 | } | 317 | } |
304 | } | 318 | } |
305 | 319 | ||
320 | if (overridden) | ||
321 | printk(KERN_INFO "%s: tPIO > 2, assuming tPIO = 2\n", | ||
322 | drive->name); | ||
323 | |||
306 | /* | 324 | /* |
307 | * Conservative "downgrade" for all pre-ATA2 drives | 325 | * Conservative "downgrade" for all pre-ATA2 drives |
308 | */ | 326 | */ |
309 | if (pio_mode && pio_mode < 4) { | 327 | if ((drive->hwif->host_flags & IDE_HFLAG_PIO_NO_DOWNGRADE) == 0 && |
328 | pio_mode && pio_mode < 4) { | ||
310 | pio_mode--; | 329 | pio_mode--; |
311 | overridden = 1; | 330 | printk(KERN_INFO "%s: applying conservative " |
312 | if (cycle_time && cycle_time < ide_pio_timings[pio_mode].cycle_time) | 331 | "PIO \"downgrade\"\n", drive->name); |
313 | cycle_time = 0; /* use standard timing */ | ||
314 | } | 332 | } |
315 | } | 333 | } |
316 | if (pio_mode > max_mode) { | 334 | |
335 | if (pio_mode > max_mode) | ||
317 | pio_mode = max_mode; | 336 | pio_mode = max_mode; |
318 | cycle_time = 0; | 337 | |
319 | } | ||
320 | if (d) { | ||
321 | d->pio_mode = pio_mode; | ||
322 | d->cycle_time = cycle_time ? cycle_time : ide_pio_timings[pio_mode].cycle_time; | ||
323 | d->use_iordy = use_iordy; | ||
324 | d->overridden = overridden; | ||
325 | } | ||
326 | return pio_mode; | 338 | return pio_mode; |
327 | } | 339 | } |
328 | 340 | ||
diff --git a/drivers/ide/ide-timing.h b/drivers/ide/ide-timing.h index e6cb8593b5ba..daffbb9797e1 100644 --- a/drivers/ide/ide-timing.h +++ b/drivers/ide/ide-timing.h | |||
@@ -106,23 +106,6 @@ static struct ide_timing ide_timing[] = { | |||
106 | #define XFER_EPIO 0x01 | 106 | #define XFER_EPIO 0x01 |
107 | #define XFER_PIO 0x00 | 107 | #define XFER_PIO 0x00 |
108 | 108 | ||
109 | static short ide_find_best_pio_mode(ide_drive_t *drive) | ||
110 | { | ||
111 | struct hd_driveid *id = drive->id; | ||
112 | short best = 0; | ||
113 | |||
114 | if (id->field_valid & 2) { /* EIDE PIO modes */ | ||
115 | |||
116 | if ((best = (drive->id->eide_pio_modes & 4) ? XFER_PIO_5 : | ||
117 | (drive->id->eide_pio_modes & 2) ? XFER_PIO_4 : | ||
118 | (drive->id->eide_pio_modes & 1) ? XFER_PIO_3 : 0)) return best; | ||
119 | } | ||
120 | |||
121 | return (drive->id->tPIO == 2) ? XFER_PIO_2 : | ||
122 | (drive->id->tPIO == 1) ? XFER_PIO_1 : | ||
123 | (drive->id->tPIO == 0) ? XFER_PIO_0 : XFER_PIO_SLOW; | ||
124 | } | ||
125 | |||
126 | static void ide_timing_quantize(struct ide_timing *t, struct ide_timing *q, int T, int UT) | 109 | static void ide_timing_quantize(struct ide_timing *t, struct ide_timing *q, int T, int UT) |
127 | { | 110 | { |
128 | q->setup = EZ(t->setup * 1000, T); | 111 | q->setup = EZ(t->setup * 1000, T); |
@@ -212,7 +195,8 @@ static int ide_timing_compute(ide_drive_t *drive, short speed, struct ide_timing | |||
212 | */ | 195 | */ |
213 | 196 | ||
214 | if ((speed & XFER_MODE) != XFER_PIO) { | 197 | if ((speed & XFER_MODE) != XFER_PIO) { |
215 | ide_timing_compute(drive, ide_find_best_pio_mode(drive), &p, T, UT); | 198 | u8 pio = ide_get_best_pio_mode(drive, 255, 5); |
199 | ide_timing_compute(drive, XFER_PIO_0 + pio, &p, T, UT); | ||
216 | ide_timing_merge(&p, t, t, IDE_TIMING_ALL); | 200 | ide_timing_merge(&p, t, t, IDE_TIMING_ALL); |
217 | } | 201 | } |
218 | 202 | ||
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c index 077fb674a96d..5e88a060df06 100644 --- a/drivers/ide/ide.c +++ b/drivers/ide/ide.c | |||
@@ -16,10 +16,6 @@ | |||
16 | * (usually 14 & 15). | 16 | * (usually 14 & 15). |
17 | * There can be up to two drives per interface, as per the ATA-2 spec. | 17 | * There can be up to two drives per interface, as per the ATA-2 spec. |
18 | * | 18 | * |
19 | * Primary: ide0, port 0x1f0; major=3; hda is minor=0; hdb is minor=64 | ||
20 | * Secondary: ide1, port 0x170; major=22; hdc is minor=0; hdd is minor=64 | ||
21 | * Tertiary: ide2, port 0x???; major=33; hde is minor=0; hdf is minor=64 | ||
22 | * Quaternary: ide3, port 0x???; major=34; hdg is minor=0; hdh is minor=64 | ||
23 | * ... | 19 | * ... |
24 | * | 20 | * |
25 | * From hd.c: | 21 | * From hd.c: |
@@ -47,80 +43,6 @@ | |||
47 | * This was a rewrite of just about everything from hd.c, though some original | 43 | * This was a rewrite of just about everything from hd.c, though some original |
48 | * code is still sprinkled about. Think of it as a major evolution, with | 44 | * code is still sprinkled about. Think of it as a major evolution, with |
49 | * inspiration from lots of linux users, esp. hamish@zot.apana.org.au | 45 | * inspiration from lots of linux users, esp. hamish@zot.apana.org.au |
50 | * | ||
51 | * Version 1.0 ALPHA initial code, primary i/f working okay | ||
52 | * Version 1.3 BETA dual i/f on shared irq tested & working! | ||
53 | * Version 1.4 BETA added auto probing for irq(s) | ||
54 | * Version 1.5 BETA added ALPHA (untested) support for IDE cd-roms, | ||
55 | * ... | ||
56 | * Version 5.50 allow values as small as 20 for idebus= | ||
57 | * Version 5.51 force non io_32bit in drive_cmd_intr() | ||
58 | * change delay_10ms() to delay_50ms() to fix problems | ||
59 | * Version 5.52 fix incorrect invalidation of removable devices | ||
60 | * add "hdx=slow" command line option | ||
61 | * Version 5.60 start to modularize the driver; the disk and ATAPI | ||
62 | * drivers can be compiled as loadable modules. | ||
63 | * move IDE probe code to ide-probe.c | ||
64 | * move IDE disk code to ide-disk.c | ||
65 | * add support for generic IDE device subdrivers | ||
66 | * add m68k code from Geert Uytterhoeven | ||
67 | * probe all interfaces by default | ||
68 | * add ioctl to (re)probe an interface | ||
69 | * Version 6.00 use per device request queues | ||
70 | * attempt to optimize shared hwgroup performance | ||
71 | * add ioctl to manually adjust bandwidth algorithms | ||
72 | * add kerneld support for the probe module | ||
73 | * fix bug in ide_error() | ||
74 | * fix bug in the first ide_get_lock() call for Atari | ||
75 | * don't flush leftover data for ATAPI devices | ||
76 | * Version 6.01 clear hwgroup->active while the hwgroup sleeps | ||
77 | * support HDIO_GETGEO for floppies | ||
78 | * Version 6.02 fix ide_ack_intr() call | ||
79 | * check partition table on floppies | ||
80 | * Version 6.03 handle bad status bit sequencing in ide_wait_stat() | ||
81 | * Version 6.10 deleted old entries from this list of updates | ||
82 | * replaced triton.c with ide-dma.c generic PCI DMA | ||
83 | * added support for BIOS-enabled UltraDMA | ||
84 | * rename all "promise" things to "pdc4030" | ||
85 | * fix EZ-DRIVE handling on small disks | ||
86 | * Version 6.11 fix probe error in ide_scan_devices() | ||
87 | * fix ancient "jiffies" polling bugs | ||
88 | * mask all hwgroup interrupts on each irq entry | ||
89 | * Version 6.12 integrate ioctl and proc interfaces | ||
90 | * fix parsing of "idex=" command line parameter | ||
91 | * Version 6.13 add support for ide4/ide5 courtesy rjones@orchestream.com | ||
92 | * Version 6.14 fixed IRQ sharing among PCI devices | ||
93 | * Version 6.15 added SMP awareness to IDE drivers | ||
94 | * Version 6.16 fixed various bugs; even more SMP friendly | ||
95 | * Version 6.17 fix for newest EZ-Drive problem | ||
96 | * Version 6.18 default unpartitioned-disk translation now "BIOS LBA" | ||
97 | * Version 6.19 Re-design for a UNIFORM driver for all platforms, | ||
98 | * model based on suggestions from Russell King and | ||
99 | * Geert Uytterhoeven | ||
100 | * Promise DC4030VL now supported. | ||
101 | * add support for ide6/ide7 | ||
102 | * delay_50ms() changed to ide_delay_50ms() and exported. | ||
103 | * Version 6.20 Added/Fixed Generic ATA-66 support and hwif detection. | ||
104 | * Added hdx=flash to allow for second flash disk | ||
105 | * detection w/o the hang loop. | ||
106 | * Added support for ide8/ide9 | ||
107 | * Added idex=ata66 for the quirky chipsets that are | ||
108 | * ATA-66 compliant, but have yet to determine a method | ||
109 | * of verification of the 80c cable presence. | ||
110 | * Specifically Promise's PDC20262 chipset. | ||
111 | * Version 6.21 Fixing/Fixed SMP spinlock issue with insight from an old | ||
112 | * hat that clarified original low level driver design. | ||
113 | * Version 6.30 Added SMP support; fixed multmode issues. -ml | ||
114 | * Version 6.31 Debug Share INTR's and request queue streaming | ||
115 | * Native ATA-100 support | ||
116 | * Prep for Cascades Project | ||
117 | * Version 7.00alpha First named revision of ide rearrange | ||
118 | * | ||
119 | * Some additional driver compile-time options are in ./include/linux/ide.h | ||
120 | * | ||
121 | * To do, in likely order of completion: | ||
122 | * - modify kernel to obtain BIOS geometry for drives on 2nd/3rd/4th i/f | ||
123 | * | ||
124 | */ | 46 | */ |
125 | 47 | ||
126 | #define REVISION "Revision: 7.00alpha2" | 48 | #define REVISION "Revision: 7.00alpha2" |
@@ -455,6 +377,10 @@ static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif) | |||
455 | hwif->straight8 = tmp_hwif->straight8; | 377 | hwif->straight8 = tmp_hwif->straight8; |
456 | hwif->bus_state = tmp_hwif->bus_state; | 378 | hwif->bus_state = tmp_hwif->bus_state; |
457 | 379 | ||
380 | hwif->host_flags = tmp_hwif->host_flags; | ||
381 | |||
382 | hwif->pio_mask = tmp_hwif->pio_mask; | ||
383 | |||
458 | hwif->atapi_dma = tmp_hwif->atapi_dma; | 384 | hwif->atapi_dma = tmp_hwif->atapi_dma; |
459 | hwif->ultra_mask = tmp_hwif->ultra_mask; | 385 | hwif->ultra_mask = tmp_hwif->ultra_mask; |
460 | hwif->mwdma_mask = tmp_hwif->mwdma_mask; | 386 | hwif->mwdma_mask = tmp_hwif->mwdma_mask; |
@@ -1171,10 +1097,6 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device | |||
1171 | return 0; | 1097 | return 0; |
1172 | } | 1098 | } |
1173 | 1099 | ||
1174 | case CDROMEJECT: | ||
1175 | case CDROMCLOSETRAY: | ||
1176 | return scsi_cmd_ioctl(file, bdev->bd_disk->queue, bdev->bd_disk, cmd, p); | ||
1177 | |||
1178 | case HDIO_GET_BUSSTATE: | 1100 | case HDIO_GET_BUSSTATE: |
1179 | if (!capable(CAP_SYS_ADMIN)) | 1101 | if (!capable(CAP_SYS_ADMIN)) |
1180 | return -EACCES; | 1102 | return -EACCES; |
diff --git a/drivers/ide/legacy/ali14xx.c b/drivers/ide/legacy/ali14xx.c index df17ed68c0bc..9b9c4761cb7d 100644 --- a/drivers/ide/legacy/ali14xx.c +++ b/drivers/ide/legacy/ali14xx.c | |||
@@ -115,13 +115,12 @@ static void ali14xx_tune_drive (ide_drive_t *drive, u8 pio) | |||
115 | int time1, time2; | 115 | int time1, time2; |
116 | u8 param1, param2, param3, param4; | 116 | u8 param1, param2, param3, param4; |
117 | unsigned long flags; | 117 | unsigned long flags; |
118 | ide_pio_data_t d; | ||
119 | int bus_speed = system_bus_clock(); | 118 | int bus_speed = system_bus_clock(); |
120 | 119 | ||
121 | pio = ide_get_best_pio_mode(drive, pio, ALI_MAX_PIO, &d); | 120 | pio = ide_get_best_pio_mode(drive, pio, ALI_MAX_PIO); |
122 | 121 | ||
123 | /* calculate timing, according to PIO mode */ | 122 | /* calculate timing, according to PIO mode */ |
124 | time1 = d.cycle_time; | 123 | time1 = ide_pio_cycle_time(drive, pio); |
125 | time2 = ide_pio_timings[pio].active_time; | 124 | time2 = ide_pio_timings[pio].active_time; |
126 | param3 = param1 = (time2 * bus_speed + 999) / 1000; | 125 | param3 = param1 = (time2 * bus_speed + 999) / 1000; |
127 | param4 = param2 = (time1 * bus_speed + 999) / 1000 - param1; | 126 | param4 = param2 = (time1 * bus_speed + 999) / 1000 - param1; |
@@ -212,10 +211,12 @@ static int __init ali14xx_probe(void) | |||
212 | mate = &ide_hwifs[1]; | 211 | mate = &ide_hwifs[1]; |
213 | 212 | ||
214 | hwif->chipset = ide_ali14xx; | 213 | hwif->chipset = ide_ali14xx; |
214 | hwif->pio_mask = ATA_PIO4; | ||
215 | hwif->tuneproc = &ali14xx_tune_drive; | 215 | hwif->tuneproc = &ali14xx_tune_drive; |
216 | hwif->mate = mate; | 216 | hwif->mate = mate; |
217 | 217 | ||
218 | mate->chipset = ide_ali14xx; | 218 | mate->chipset = ide_ali14xx; |
219 | mate->pio_mask = ATA_PIO4; | ||
219 | mate->tuneproc = &ali14xx_tune_drive; | 220 | mate->tuneproc = &ali14xx_tune_drive; |
220 | mate->mate = hwif; | 221 | mate->mate = hwif; |
221 | mate->channel = 1; | 222 | mate->channel = 1; |
diff --git a/drivers/ide/legacy/dtc2278.c b/drivers/ide/legacy/dtc2278.c index 36a3f0ac6162..6c01d951d074 100644 --- a/drivers/ide/legacy/dtc2278.c +++ b/drivers/ide/legacy/dtc2278.c | |||
@@ -71,7 +71,7 @@ static void tune_dtc2278 (ide_drive_t *drive, u8 pio) | |||
71 | { | 71 | { |
72 | unsigned long flags; | 72 | unsigned long flags; |
73 | 73 | ||
74 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | 74 | pio = ide_get_best_pio_mode(drive, pio, 4); |
75 | 75 | ||
76 | if (pio >= 3) { | 76 | if (pio >= 3) { |
77 | spin_lock_irqsave(&ide_lock, flags); | 77 | spin_lock_irqsave(&ide_lock, flags); |
@@ -123,6 +123,7 @@ static int __init dtc2278_probe(void) | |||
123 | 123 | ||
124 | hwif->serialized = 1; | 124 | hwif->serialized = 1; |
125 | hwif->chipset = ide_dtc2278; | 125 | hwif->chipset = ide_dtc2278; |
126 | hwif->pio_mask = ATA_PIO4; | ||
126 | hwif->tuneproc = &tune_dtc2278; | 127 | hwif->tuneproc = &tune_dtc2278; |
127 | hwif->drives[0].no_unmask = 1; | 128 | hwif->drives[0].no_unmask = 1; |
128 | hwif->drives[1].no_unmask = 1; | 129 | hwif->drives[1].no_unmask = 1; |
diff --git a/drivers/ide/legacy/falconide.c b/drivers/ide/legacy/falconide.c index e1e9d9d6893f..f0829b83e970 100644 --- a/drivers/ide/legacy/falconide.c +++ b/drivers/ide/legacy/falconide.c | |||
@@ -8,6 +8,7 @@ | |||
8 | * more details. | 8 | * more details. |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/module.h> | ||
11 | #include <linux/types.h> | 12 | #include <linux/types.h> |
12 | #include <linux/mm.h> | 13 | #include <linux/mm.h> |
13 | #include <linux/interrupt.h> | 14 | #include <linux/interrupt.h> |
@@ -54,6 +55,7 @@ static int falconide_offsets[IDE_NR_PORTS] __initdata = { | |||
54 | */ | 55 | */ |
55 | 56 | ||
56 | int falconide_intr_lock; | 57 | int falconide_intr_lock; |
58 | EXPORT_SYMBOL(falconide_intr_lock); | ||
57 | 59 | ||
58 | 60 | ||
59 | /* | 61 | /* |
diff --git a/drivers/ide/legacy/ht6560b.c b/drivers/ide/legacy/ht6560b.c index c8f353b1296f..bfaa2025173b 100644 --- a/drivers/ide/legacy/ht6560b.c +++ b/drivers/ide/legacy/ht6560b.c | |||
@@ -203,19 +203,21 @@ static u8 ht_pio2timings(ide_drive_t *drive, u8 pio) | |||
203 | { | 203 | { |
204 | int active_time, recovery_time; | 204 | int active_time, recovery_time; |
205 | int active_cycles, recovery_cycles; | 205 | int active_cycles, recovery_cycles; |
206 | ide_pio_data_t d; | ||
207 | int bus_speed = system_bus_clock(); | 206 | int bus_speed = system_bus_clock(); |
208 | 207 | ||
209 | if (pio) { | 208 | if (pio) { |
210 | pio = ide_get_best_pio_mode(drive, pio, 5, &d); | 209 | unsigned int cycle_time; |
211 | 210 | ||
211 | pio = ide_get_best_pio_mode(drive, pio, 5); | ||
212 | cycle_time = ide_pio_cycle_time(drive, pio); | ||
213 | |||
212 | /* | 214 | /* |
213 | * Just like opti621.c we try to calculate the | 215 | * Just like opti621.c we try to calculate the |
214 | * actual cycle time for recovery and activity | 216 | * actual cycle time for recovery and activity |
215 | * according system bus speed. | 217 | * according system bus speed. |
216 | */ | 218 | */ |
217 | active_time = ide_pio_timings[pio].active_time; | 219 | active_time = ide_pio_timings[pio].active_time; |
218 | recovery_time = d.cycle_time | 220 | recovery_time = cycle_time |
219 | - active_time | 221 | - active_time |
220 | - ide_pio_timings[pio].setup_time; | 222 | - ide_pio_timings[pio].setup_time; |
221 | /* | 223 | /* |
@@ -331,12 +333,14 @@ int __init ht6560b_init(void) | |||
331 | 333 | ||
332 | hwif->chipset = ide_ht6560b; | 334 | hwif->chipset = ide_ht6560b; |
333 | hwif->selectproc = &ht6560b_selectproc; | 335 | hwif->selectproc = &ht6560b_selectproc; |
336 | hwif->pio_mask = ATA_PIO5; | ||
334 | hwif->tuneproc = &tune_ht6560b; | 337 | hwif->tuneproc = &tune_ht6560b; |
335 | hwif->serialized = 1; /* is this needed? */ | 338 | hwif->serialized = 1; /* is this needed? */ |
336 | hwif->mate = mate; | 339 | hwif->mate = mate; |
337 | 340 | ||
338 | mate->chipset = ide_ht6560b; | 341 | mate->chipset = ide_ht6560b; |
339 | mate->selectproc = &ht6560b_selectproc; | 342 | mate->selectproc = &ht6560b_selectproc; |
343 | mate->pio_mask = ATA_PIO5; | ||
340 | mate->tuneproc = &tune_ht6560b; | 344 | mate->tuneproc = &tune_ht6560b; |
341 | mate->serialized = 1; /* is this needed? */ | 345 | mate->serialized = 1; /* is this needed? */ |
342 | mate->mate = hwif; | 346 | mate->mate = hwif; |
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c index 2f3977f195b7..4cdb519f9832 100644 --- a/drivers/ide/legacy/ide-cs.c +++ b/drivers/ide/legacy/ide-cs.c | |||
@@ -386,6 +386,7 @@ static struct pcmcia_device_id ide_ids[] = { | |||
386 | PCMCIA_DEVICE_PROD_ID12("HITACHI", "microdrive", 0xf4f43949, 0xa6d76178), | 386 | PCMCIA_DEVICE_PROD_ID12("HITACHI", "microdrive", 0xf4f43949, 0xa6d76178), |
387 | PCMCIA_DEVICE_PROD_ID12("IBM", "microdrive", 0xb569a6e5, 0xa6d76178), | 387 | PCMCIA_DEVICE_PROD_ID12("IBM", "microdrive", 0xb569a6e5, 0xa6d76178), |
388 | PCMCIA_DEVICE_PROD_ID12("IBM", "IBM17JSSFP20", 0xb569a6e5, 0xf2508753), | 388 | PCMCIA_DEVICE_PROD_ID12("IBM", "IBM17JSSFP20", 0xb569a6e5, 0xf2508753), |
389 | PCMCIA_DEVICE_PROD_ID12("KINGSTON", "CF8GB", 0x2e6d1829, 0xacbe682e), | ||
389 | PCMCIA_DEVICE_PROD_ID12("IO DATA", "CBIDE2 ", 0x547e66dc, 0x8671043b), | 390 | PCMCIA_DEVICE_PROD_ID12("IO DATA", "CBIDE2 ", 0x547e66dc, 0x8671043b), |
390 | PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDE", 0x547e66dc, 0x5c5ab149), | 391 | PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDE", 0x547e66dc, 0x5c5ab149), |
391 | PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDEII", 0x547e66dc, 0xb3662674), | 392 | PCMCIA_DEVICE_PROD_ID12("IO DATA", "PCIDEII", 0x547e66dc, 0xb3662674), |
diff --git a/drivers/ide/legacy/qd65xx.c b/drivers/ide/legacy/qd65xx.c index 7783745dd167..8b87a424094a 100644 --- a/drivers/ide/legacy/qd65xx.c +++ b/drivers/ide/legacy/qd65xx.c | |||
@@ -252,38 +252,38 @@ static void qd6500_tune_drive (ide_drive_t *drive, u8 pio) | |||
252 | 252 | ||
253 | static void qd6580_tune_drive (ide_drive_t *drive, u8 pio) | 253 | static void qd6580_tune_drive (ide_drive_t *drive, u8 pio) |
254 | { | 254 | { |
255 | ide_pio_data_t d; | ||
256 | int base = HWIF(drive)->select_data; | 255 | int base = HWIF(drive)->select_data; |
256 | unsigned int cycle_time; | ||
257 | int active_time = 175; | 257 | int active_time = 175; |
258 | int recovery_time = 415; /* worst case values from the dos driver */ | 258 | int recovery_time = 415; /* worst case values from the dos driver */ |
259 | 259 | ||
260 | if (drive->id && !qd_find_disk_type(drive, &active_time, &recovery_time)) { | 260 | if (drive->id && !qd_find_disk_type(drive, &active_time, &recovery_time)) { |
261 | pio = ide_get_best_pio_mode(drive, pio, 4, &d); | 261 | pio = ide_get_best_pio_mode(drive, pio, 4); |
262 | cycle_time = ide_pio_cycle_time(drive, pio); | ||
262 | 263 | ||
263 | switch (pio) { | 264 | switch (pio) { |
264 | case 0: break; | 265 | case 0: break; |
265 | case 3: | 266 | case 3: |
266 | if (d.cycle_time >= 110) { | 267 | if (cycle_time >= 110) { |
267 | active_time = 86; | 268 | active_time = 86; |
268 | recovery_time = d.cycle_time - 102; | 269 | recovery_time = cycle_time - 102; |
269 | } else | 270 | } else |
270 | printk(KERN_WARNING "%s: Strange recovery time !\n",drive->name); | 271 | printk(KERN_WARNING "%s: Strange recovery time !\n",drive->name); |
271 | break; | 272 | break; |
272 | case 4: | 273 | case 4: |
273 | if (d.cycle_time >= 69) { | 274 | if (cycle_time >= 69) { |
274 | active_time = 70; | 275 | active_time = 70; |
275 | recovery_time = d.cycle_time - 61; | 276 | recovery_time = cycle_time - 61; |
276 | } else | 277 | } else |
277 | printk(KERN_WARNING "%s: Strange recovery time !\n",drive->name); | 278 | printk(KERN_WARNING "%s: Strange recovery time !\n",drive->name); |
278 | break; | 279 | break; |
279 | default: | 280 | default: |
280 | if (d.cycle_time >= 180) { | 281 | if (cycle_time >= 180) { |
281 | active_time = 110; | 282 | active_time = 110; |
282 | recovery_time = d.cycle_time - 120; | 283 | recovery_time = cycle_time - 120; |
283 | } else { | 284 | } else { |
284 | active_time = ide_pio_timings[pio].active_time; | 285 | active_time = ide_pio_timings[pio].active_time; |
285 | recovery_time = d.cycle_time | 286 | recovery_time = cycle_time - active_time; |
286 | -active_time; | ||
287 | } | 287 | } |
288 | } | 288 | } |
289 | printk(KERN_INFO "%s: PIO mode%d\n", drive->name,pio); | 289 | printk(KERN_INFO "%s: PIO mode%d\n", drive->name,pio); |
@@ -346,6 +346,7 @@ static void __init qd_setup(ide_hwif_t *hwif, int base, int config, | |||
346 | hwif->drives[1].drive_data = data1; | 346 | hwif->drives[1].drive_data = data1; |
347 | hwif->drives[0].io_32bit = | 347 | hwif->drives[0].io_32bit = |
348 | hwif->drives[1].io_32bit = 1; | 348 | hwif->drives[1].io_32bit = 1; |
349 | hwif->pio_mask = ATA_PIO4; | ||
349 | hwif->tuneproc = tuneproc; | 350 | hwif->tuneproc = tuneproc; |
350 | probe_hwif_init(hwif); | 351 | probe_hwif_init(hwif); |
351 | } | 352 | } |
diff --git a/drivers/ide/legacy/umc8672.c b/drivers/ide/legacy/umc8672.c index ddc403a0bd82..d2862e638bc5 100644 --- a/drivers/ide/legacy/umc8672.c +++ b/drivers/ide/legacy/umc8672.c | |||
@@ -110,7 +110,7 @@ static void tune_umc (ide_drive_t *drive, u8 pio) | |||
110 | unsigned long flags; | 110 | unsigned long flags; |
111 | ide_hwgroup_t *hwgroup = ide_hwifs[HWIF(drive)->index^1].hwgroup; | 111 | ide_hwgroup_t *hwgroup = ide_hwifs[HWIF(drive)->index^1].hwgroup; |
112 | 112 | ||
113 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | 113 | pio = ide_get_best_pio_mode(drive, pio, 4); |
114 | printk("%s: setting umc8672 to PIO mode%d (speed %d)\n", | 114 | printk("%s: setting umc8672 to PIO mode%d (speed %d)\n", |
115 | drive->name, pio, pio_to_umc[pio]); | 115 | drive->name, pio, pio_to_umc[pio]); |
116 | spin_lock_irqsave(&ide_lock, flags); | 116 | spin_lock_irqsave(&ide_lock, flags); |
@@ -149,10 +149,12 @@ static int __init umc8672_probe(void) | |||
149 | mate = &ide_hwifs[1]; | 149 | mate = &ide_hwifs[1]; |
150 | 150 | ||
151 | hwif->chipset = ide_umc8672; | 151 | hwif->chipset = ide_umc8672; |
152 | hwif->pio_mask = ATA_PIO4; | ||
152 | hwif->tuneproc = &tune_umc; | 153 | hwif->tuneproc = &tune_umc; |
153 | hwif->mate = mate; | 154 | hwif->mate = mate; |
154 | 155 | ||
155 | mate->chipset = ide_umc8672; | 156 | mate->chipset = ide_umc8672; |
157 | mate->pio_mask = ATA_PIO4; | ||
156 | mate->tuneproc = &tune_umc; | 158 | mate->tuneproc = &tune_umc; |
157 | mate->mate = hwif; | 159 | mate->mate = hwif; |
158 | mate->channel = 1; | 160 | mate->channel = 1; |
diff --git a/drivers/ide/mips/au1xxx-ide.c b/drivers/ide/mips/au1xxx-ide.c index 2e7013a2a7f6..2ba6a054b861 100644 --- a/drivers/ide/mips/au1xxx-ide.c +++ b/drivers/ide/mips/au1xxx-ide.c | |||
@@ -106,7 +106,7 @@ static void auide_tune_drive(ide_drive_t *drive, byte pio) | |||
106 | u8 speed; | 106 | u8 speed; |
107 | 107 | ||
108 | /* get the best pio mode for the drive */ | 108 | /* get the best pio mode for the drive */ |
109 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | 109 | pio = ide_get_best_pio_mode(drive, pio, 4); |
110 | 110 | ||
111 | printk(KERN_INFO "%s: setting Au1XXX IDE to PIO mode%d\n", | 111 | printk(KERN_INFO "%s: setting Au1XXX IDE to PIO mode%d\n", |
112 | drive->name, pio); | 112 | drive->name, pio); |
@@ -692,6 +692,8 @@ static int au_ide_probe(struct device *dev) | |||
692 | hwif->swdma_mask = 0x0; | 692 | hwif->swdma_mask = 0x0; |
693 | #endif | 693 | #endif |
694 | 694 | ||
695 | hwif->pio_mask = ATA_PIO4; | ||
696 | |||
695 | hwif->noprobe = 0; | 697 | hwif->noprobe = 0; |
696 | hwif->drives[0].unmask = 1; | 698 | hwif->drives[0].unmask = 1; |
697 | hwif->drives[1].unmask = 1; | 699 | hwif->drives[1].unmask = 1; |
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/pci/aec62xx.c index e5d09367627e..74432830abf7 100644 --- a/drivers/ide/pci/aec62xx.c +++ b/drivers/ide/pci/aec62xx.c | |||
@@ -142,7 +142,7 @@ static int aec6260_tune_chipset (ide_drive_t *drive, u8 xferspeed) | |||
142 | 142 | ||
143 | static void aec62xx_tune_drive (ide_drive_t *drive, u8 pio) | 143 | static void aec62xx_tune_drive (ide_drive_t *drive, u8 pio) |
144 | { | 144 | { |
145 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | 145 | pio = ide_get_best_pio_mode(drive, pio, 4); |
146 | (void) HWIF(drive)->speedproc(drive, pio + XFER_PIO_0); | 146 | (void) HWIF(drive)->speedproc(drive, pio + XFER_PIO_0); |
147 | } | 147 | } |
148 | 148 | ||
@@ -174,12 +174,6 @@ static unsigned int __devinit init_chipset_aec62xx(struct pci_dev *dev, const ch | |||
174 | { | 174 | { |
175 | int bus_speed = system_bus_clock(); | 175 | int bus_speed = system_bus_clock(); |
176 | 176 | ||
177 | if (dev->resource[PCI_ROM_RESOURCE].start) { | ||
178 | pci_write_config_dword(dev, PCI_ROM_ADDRESS, dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE); | ||
179 | printk(KERN_INFO "%s: ROM enabled at 0x%08lx\n", name, | ||
180 | (unsigned long)dev->resource[PCI_ROM_RESOURCE].start); | ||
181 | } | ||
182 | |||
183 | if (bus_speed <= 33) | 177 | if (bus_speed <= 33) |
184 | pci_set_drvdata(dev, (void *) aec6xxx_33_base); | 178 | pci_set_drvdata(dev, (void *) aec6xxx_33_base); |
185 | else | 179 | else |
@@ -271,48 +265,48 @@ static ide_pci_device_t aec62xx_chipsets[] __devinitdata = { | |||
271 | .init_setup = init_setup_aec62xx, | 265 | .init_setup = init_setup_aec62xx, |
272 | .init_chipset = init_chipset_aec62xx, | 266 | .init_chipset = init_chipset_aec62xx, |
273 | .init_hwif = init_hwif_aec62xx, | 267 | .init_hwif = init_hwif_aec62xx, |
274 | .channels = 2, | ||
275 | .autodma = AUTODMA, | 268 | .autodma = AUTODMA, |
276 | .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, | 269 | .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, |
277 | .bootable = OFF_BOARD, | 270 | .bootable = OFF_BOARD, |
271 | .pio_mask = ATA_PIO4, | ||
278 | .udma_mask = 0x07, /* udma0-2 */ | 272 | .udma_mask = 0x07, /* udma0-2 */ |
279 | },{ /* 1 */ | 273 | },{ /* 1 */ |
280 | .name = "AEC6260", | 274 | .name = "AEC6260", |
281 | .init_setup = init_setup_aec62xx, | 275 | .init_setup = init_setup_aec62xx, |
282 | .init_chipset = init_chipset_aec62xx, | 276 | .init_chipset = init_chipset_aec62xx, |
283 | .init_hwif = init_hwif_aec62xx, | 277 | .init_hwif = init_hwif_aec62xx, |
284 | .channels = 2, | ||
285 | .autodma = NOAUTODMA, | 278 | .autodma = NOAUTODMA, |
286 | .bootable = OFF_BOARD, | 279 | .bootable = OFF_BOARD, |
280 | .pio_mask = ATA_PIO4, | ||
287 | .udma_mask = 0x1f, /* udma0-4 */ | 281 | .udma_mask = 0x1f, /* udma0-4 */ |
288 | },{ /* 2 */ | 282 | },{ /* 2 */ |
289 | .name = "AEC6260R", | 283 | .name = "AEC6260R", |
290 | .init_setup = init_setup_aec62xx, | 284 | .init_setup = init_setup_aec62xx, |
291 | .init_chipset = init_chipset_aec62xx, | 285 | .init_chipset = init_chipset_aec62xx, |
292 | .init_hwif = init_hwif_aec62xx, | 286 | .init_hwif = init_hwif_aec62xx, |
293 | .channels = 2, | ||
294 | .autodma = AUTODMA, | 287 | .autodma = AUTODMA, |
295 | .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, | 288 | .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, |
296 | .bootable = NEVER_BOARD, | 289 | .bootable = NEVER_BOARD, |
290 | .pio_mask = ATA_PIO4, | ||
297 | .udma_mask = 0x1f, /* udma0-4 */ | 291 | .udma_mask = 0x1f, /* udma0-4 */ |
298 | },{ /* 3 */ | 292 | },{ /* 3 */ |
299 | .name = "AEC6280", | 293 | .name = "AEC6280", |
300 | .init_setup = init_setup_aec6x80, | 294 | .init_setup = init_setup_aec6x80, |
301 | .init_chipset = init_chipset_aec62xx, | 295 | .init_chipset = init_chipset_aec62xx, |
302 | .init_hwif = init_hwif_aec62xx, | 296 | .init_hwif = init_hwif_aec62xx, |
303 | .channels = 2, | ||
304 | .autodma = AUTODMA, | 297 | .autodma = AUTODMA, |
305 | .bootable = OFF_BOARD, | 298 | .bootable = OFF_BOARD, |
299 | .pio_mask = ATA_PIO4, | ||
306 | .udma_mask = 0x3f, /* udma0-5 */ | 300 | .udma_mask = 0x3f, /* udma0-5 */ |
307 | },{ /* 4 */ | 301 | },{ /* 4 */ |
308 | .name = "AEC6280R", | 302 | .name = "AEC6280R", |
309 | .init_setup = init_setup_aec6x80, | 303 | .init_setup = init_setup_aec6x80, |
310 | .init_chipset = init_chipset_aec62xx, | 304 | .init_chipset = init_chipset_aec62xx, |
311 | .init_hwif = init_hwif_aec62xx, | 305 | .init_hwif = init_hwif_aec62xx, |
312 | .channels = 2, | ||
313 | .autodma = AUTODMA, | 306 | .autodma = AUTODMA, |
314 | .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, | 307 | .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, |
315 | .bootable = OFF_BOARD, | 308 | .bootable = OFF_BOARD, |
309 | .pio_mask = ATA_PIO4, | ||
316 | .udma_mask = 0x3f, /* udma0-5 */ | 310 | .udma_mask = 0x3f, /* udma0-5 */ |
317 | } | 311 | } |
318 | }; | 312 | }; |
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c index ba0fb92b0417..5511c86733dc 100644 --- a/drivers/ide/pci/alim15x3.c +++ b/drivers/ide/pci/alim15x3.c | |||
@@ -295,7 +295,6 @@ static int ali_get_info (char *buffer, char **addr, off_t offset, int count) | |||
295 | 295 | ||
296 | static u8 ali15x3_tune_pio (ide_drive_t *drive, u8 pio) | 296 | static u8 ali15x3_tune_pio (ide_drive_t *drive, u8 pio) |
297 | { | 297 | { |
298 | ide_pio_data_t d; | ||
299 | ide_hwif_t *hwif = HWIF(drive); | 298 | ide_hwif_t *hwif = HWIF(drive); |
300 | struct pci_dev *dev = hwif->pci_dev; | 299 | struct pci_dev *dev = hwif->pci_dev; |
301 | int s_time, a_time, c_time; | 300 | int s_time, a_time, c_time; |
@@ -307,7 +306,7 @@ static u8 ali15x3_tune_pio (ide_drive_t *drive, u8 pio) | |||
307 | u8 cd_dma_fifo = 0; | 306 | u8 cd_dma_fifo = 0; |
308 | int unit = drive->select.b.unit & 1; | 307 | int unit = drive->select.b.unit & 1; |
309 | 308 | ||
310 | pio = ide_get_best_pio_mode(drive, pio, 5, &d); | 309 | pio = ide_get_best_pio_mode(drive, pio, 5); |
311 | s_time = ide_pio_timings[pio].setup_time; | 310 | s_time = ide_pio_timings[pio].setup_time; |
312 | a_time = ide_pio_timings[pio].active_time; | 311 | a_time = ide_pio_timings[pio].active_time; |
313 | if ((s_clc = (s_time * bus_speed + 999) / 1000) >= 8) | 312 | if ((s_clc = (s_time * bus_speed + 999) / 1000) >= 8) |
@@ -817,9 +816,9 @@ static ide_pci_device_t ali15x3_chipset __devinitdata = { | |||
817 | .init_chipset = init_chipset_ali15x3, | 816 | .init_chipset = init_chipset_ali15x3, |
818 | .init_hwif = init_hwif_ali15x3, | 817 | .init_hwif = init_hwif_ali15x3, |
819 | .init_dma = init_dma_ali15x3, | 818 | .init_dma = init_dma_ali15x3, |
820 | .channels = 2, | ||
821 | .autodma = AUTODMA, | 819 | .autodma = AUTODMA, |
822 | .bootable = ON_BOARD, | 820 | .bootable = ON_BOARD, |
821 | .pio_mask = ATA_PIO5, | ||
823 | }; | 822 | }; |
824 | 823 | ||
825 | /** | 824 | /** |
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/pci/amd74xx.c index 8d30b99a54d8..06c15a6a3e7d 100644 --- a/drivers/ide/pci/amd74xx.c +++ b/drivers/ide/pci/amd74xx.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Version 2.20 | 2 | * Version 2.21 |
3 | * | 3 | * |
4 | * AMD 755/756/766/8111 and nVidia nForce/2/2s/3/3s/CK804/MCP04 | 4 | * AMD 755/756/766/8111 and nVidia nForce/2/2s/3/3s/CK804/MCP04 |
5 | * IDE driver for Linux. | 5 | * IDE driver for Linux. |
@@ -272,10 +272,8 @@ static int amd_set_drive(ide_drive_t *drive, u8 speed) | |||
272 | 272 | ||
273 | static void amd74xx_tune_drive(ide_drive_t *drive, u8 pio) | 273 | static void amd74xx_tune_drive(ide_drive_t *drive, u8 pio) |
274 | { | 274 | { |
275 | if (pio == 255) { | 275 | if (pio == 255) |
276 | amd_set_drive(drive, ide_find_best_pio_mode(drive)); | 276 | pio = ide_get_best_pio_mode(drive, 255, 5); |
277 | return; | ||
278 | } | ||
279 | 277 | ||
280 | amd_set_drive(drive, XFER_PIO_0 + min_t(byte, pio, 5)); | 278 | amd_set_drive(drive, XFER_PIO_0 + min_t(byte, pio, 5)); |
281 | } | 279 | } |
@@ -284,12 +282,14 @@ static int amd74xx_ide_dma_check(ide_drive_t *drive) | |||
284 | { | 282 | { |
285 | u8 speed = ide_max_dma_mode(drive); | 283 | u8 speed = ide_max_dma_mode(drive); |
286 | 284 | ||
287 | if (speed == 0) | 285 | if (speed == 0) { |
288 | speed = ide_find_best_pio_mode(drive); | 286 | amd74xx_tune_drive(drive, 255); |
287 | return -1; | ||
288 | } | ||
289 | 289 | ||
290 | amd_set_drive(drive, speed); | 290 | amd_set_drive(drive, speed); |
291 | 291 | ||
292 | if (drive->autodma && (speed & XFER_MODE) != XFER_PIO) | 292 | if (drive->autodma) |
293 | return 0; | 293 | return 0; |
294 | 294 | ||
295 | return -1; | 295 | return -1; |
@@ -448,10 +448,12 @@ static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif) | |||
448 | .name = name_str, \ | 448 | .name = name_str, \ |
449 | .init_chipset = init_chipset_amd74xx, \ | 449 | .init_chipset = init_chipset_amd74xx, \ |
450 | .init_hwif = init_hwif_amd74xx, \ | 450 | .init_hwif = init_hwif_amd74xx, \ |
451 | .channels = 2, \ | ||
452 | .autodma = AUTODMA, \ | 451 | .autodma = AUTODMA, \ |
453 | .enablebits = {{0x40,0x02,0x02}, {0x40,0x01,0x01}}, \ | 452 | .enablebits = {{0x40,0x02,0x02}, {0x40,0x01,0x01}}, \ |
454 | .bootable = ON_BOARD, \ | 453 | .bootable = ON_BOARD, \ |
454 | .host_flags = IDE_HFLAG_PIO_NO_BLACKLIST \ | ||
455 | | IDE_HFLAG_PIO_NO_DOWNGRADE, \ | ||
456 | .pio_mask = ATA_PIO5, \ | ||
455 | } | 457 | } |
456 | 458 | ||
457 | #define DECLARE_NV_DEV(name_str) \ | 459 | #define DECLARE_NV_DEV(name_str) \ |
@@ -459,10 +461,12 @@ static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif) | |||
459 | .name = name_str, \ | 461 | .name = name_str, \ |
460 | .init_chipset = init_chipset_amd74xx, \ | 462 | .init_chipset = init_chipset_amd74xx, \ |
461 | .init_hwif = init_hwif_amd74xx, \ | 463 | .init_hwif = init_hwif_amd74xx, \ |
462 | .channels = 2, \ | ||
463 | .autodma = AUTODMA, \ | 464 | .autodma = AUTODMA, \ |
464 | .enablebits = {{0x50,0x02,0x02}, {0x50,0x01,0x01}}, \ | 465 | .enablebits = {{0x50,0x02,0x02}, {0x50,0x01,0x01}}, \ |
465 | .bootable = ON_BOARD, \ | 466 | .bootable = ON_BOARD, \ |
467 | .host_flags = IDE_HFLAG_PIO_NO_BLACKLIST \ | ||
468 | | IDE_HFLAG_PIO_NO_DOWNGRADE, \ | ||
469 | .pio_mask = ATA_PIO5, \ | ||
466 | } | 470 | } |
467 | 471 | ||
468 | static ide_pci_device_t amd74xx_chipsets[] __devinitdata = { | 472 | static ide_pci_device_t amd74xx_chipsets[] __devinitdata = { |
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/pci/atiixp.c index 2761510309b3..1725aa402d98 100644 --- a/drivers/ide/pci/atiixp.c +++ b/drivers/ide/pci/atiixp.c | |||
@@ -1,9 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * linux/drivers/ide/pci/atiixp.c Version 0.01-bart2 Feb. 26, 2004 | 2 | * linux/drivers/ide/pci/atiixp.c Version 0.02 Jun 16 2007 |
3 | * | 3 | * |
4 | * Copyright (C) 2003 ATI Inc. <hyu@ati.com> | 4 | * Copyright (C) 2003 ATI Inc. <hyu@ati.com> |
5 | * Copyright (C) 2004 Bartlomiej Zolnierkiewicz | 5 | * Copyright (C) 2004,2007 Bartlomiej Zolnierkiewicz |
6 | * | ||
7 | */ | 6 | */ |
8 | 7 | ||
9 | #include <linux/types.h> | 8 | #include <linux/types.h> |
@@ -123,14 +122,14 @@ static void atiixp_dma_host_off(ide_drive_t *drive) | |||
123 | } | 122 | } |
124 | 123 | ||
125 | /** | 124 | /** |
126 | * atiixp_tune_drive - tune a drive attached to a ATIIXP | 125 | * atiixp_tune_pio - tune a drive attached to a ATIIXP |
127 | * @drive: drive to tune | 126 | * @drive: drive to tune |
128 | * @pio: desired PIO mode | 127 | * @pio: desired PIO mode |
129 | * | 128 | * |
130 | * Set the interface PIO mode. | 129 | * Set the interface PIO mode. |
131 | */ | 130 | */ |
132 | 131 | ||
133 | static void atiixp_tuneproc(ide_drive_t *drive, u8 pio) | 132 | static void atiixp_tune_pio(ide_drive_t *drive, u8 pio) |
134 | { | 133 | { |
135 | struct pci_dev *dev = drive->hwif->pci_dev; | 134 | struct pci_dev *dev = drive->hwif->pci_dev; |
136 | unsigned long flags; | 135 | unsigned long flags; |
@@ -154,6 +153,13 @@ static void atiixp_tuneproc(ide_drive_t *drive, u8 pio) | |||
154 | spin_unlock_irqrestore(&atiixp_lock, flags); | 153 | spin_unlock_irqrestore(&atiixp_lock, flags); |
155 | } | 154 | } |
156 | 155 | ||
156 | static void atiixp_tuneproc(ide_drive_t *drive, u8 pio) | ||
157 | { | ||
158 | pio = ide_get_best_pio_mode(drive, pio, 4); | ||
159 | atiixp_tune_pio(drive, pio); | ||
160 | (void)ide_config_drive_speed(drive, XFER_PIO_0 + pio); | ||
161 | } | ||
162 | |||
157 | /** | 163 | /** |
158 | * atiixp_tune_chipset - tune a ATIIXP interface | 164 | * atiixp_tune_chipset - tune a ATIIXP interface |
159 | * @drive: IDE drive to tune | 165 | * @drive: IDE drive to tune |
@@ -175,6 +181,11 @@ static int atiixp_speedproc(ide_drive_t *drive, u8 xferspeed) | |||
175 | 181 | ||
176 | speed = ide_rate_filter(drive, xferspeed); | 182 | speed = ide_rate_filter(drive, xferspeed); |
177 | 183 | ||
184 | if (speed >= XFER_PIO_0 && speed <= XFER_PIO_4) { | ||
185 | atiixp_tune_pio(drive, speed - XFER_PIO_0); | ||
186 | return ide_config_drive_speed(drive, speed); | ||
187 | } | ||
188 | |||
178 | spin_lock_irqsave(&atiixp_lock, flags); | 189 | spin_lock_irqsave(&atiixp_lock, flags); |
179 | 190 | ||
180 | save_mdma_mode[drive->dn] = 0; | 191 | save_mdma_mode[drive->dn] = 0; |
@@ -201,7 +212,7 @@ static int atiixp_speedproc(ide_drive_t *drive, u8 xferspeed) | |||
201 | else | 212 | else |
202 | pio = speed - XFER_PIO_0; | 213 | pio = speed - XFER_PIO_0; |
203 | 214 | ||
204 | atiixp_tuneproc(drive, pio); | 215 | atiixp_tune_pio(drive, pio); |
205 | 216 | ||
206 | return ide_config_drive_speed(drive, speed); | 217 | return ide_config_drive_speed(drive, speed); |
207 | } | 218 | } |
@@ -216,18 +227,13 @@ static int atiixp_speedproc(ide_drive_t *drive, u8 xferspeed) | |||
216 | 227 | ||
217 | static int atiixp_dma_check(ide_drive_t *drive) | 228 | static int atiixp_dma_check(ide_drive_t *drive) |
218 | { | 229 | { |
219 | u8 tspeed, speed; | ||
220 | |||
221 | drive->init_speed = 0; | 230 | drive->init_speed = 0; |
222 | 231 | ||
223 | if (ide_tune_dma(drive)) | 232 | if (ide_tune_dma(drive)) |
224 | return 0; | 233 | return 0; |
225 | 234 | ||
226 | if (ide_use_fast_pio(drive)) { | 235 | if (ide_use_fast_pio(drive)) |
227 | tspeed = ide_get_best_pio_mode(drive, 255, 5, NULL); | 236 | atiixp_tuneproc(drive, 255); |
228 | speed = atiixp_dma_2_pio(XFER_PIO_0 + tspeed) + XFER_PIO_0; | ||
229 | atiixp_speedproc(drive, speed); | ||
230 | } | ||
231 | 237 | ||
232 | return -1; | 238 | return -1; |
233 | } | 239 | } |
@@ -285,17 +291,18 @@ static ide_pci_device_t atiixp_pci_info[] __devinitdata = { | |||
285 | { /* 0 */ | 291 | { /* 0 */ |
286 | .name = "ATIIXP", | 292 | .name = "ATIIXP", |
287 | .init_hwif = init_hwif_atiixp, | 293 | .init_hwif = init_hwif_atiixp, |
288 | .channels = 2, | ||
289 | .autodma = AUTODMA, | 294 | .autodma = AUTODMA, |
290 | .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}}, | 295 | .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}}, |
291 | .bootable = ON_BOARD, | 296 | .bootable = ON_BOARD, |
297 | .pio_mask = ATA_PIO4, | ||
292 | },{ /* 1 */ | 298 | },{ /* 1 */ |
293 | .name = "SB600_PATA", | 299 | .name = "SB600_PATA", |
294 | .init_hwif = init_hwif_atiixp, | 300 | .init_hwif = init_hwif_atiixp, |
295 | .channels = 1, | ||
296 | .autodma = AUTODMA, | 301 | .autodma = AUTODMA, |
297 | .enablebits = {{0x48,0x01,0x00}, {0x00,0x00,0x00}}, | 302 | .enablebits = {{0x48,0x01,0x00}, {0x00,0x00,0x00}}, |
298 | .bootable = ON_BOARD, | 303 | .bootable = ON_BOARD, |
304 | .host_flags = IDE_HFLAG_SINGLE, | ||
305 | .pio_mask = ATA_PIO4, | ||
299 | }, | 306 | }, |
300 | }; | 307 | }; |
301 | 308 | ||
diff --git a/drivers/ide/pci/cmd640.c b/drivers/ide/pci/cmd640.c index dc43f009acab..9689494efa24 100644 --- a/drivers/ide/pci/cmd640.c +++ b/drivers/ide/pci/cmd640.c | |||
@@ -633,9 +633,8 @@ static void cmd640_set_mode (unsigned int index, u8 pio_mode, unsigned int cycle | |||
633 | */ | 633 | */ |
634 | static void cmd640_tune_drive (ide_drive_t *drive, u8 mode_wanted) | 634 | static void cmd640_tune_drive (ide_drive_t *drive, u8 mode_wanted) |
635 | { | 635 | { |
636 | unsigned int index = 0, cycle_time; | ||
636 | u8 b; | 637 | u8 b; |
637 | ide_pio_data_t d; | ||
638 | unsigned int index = 0; | ||
639 | 638 | ||
640 | while (drive != cmd_drives[index]) { | 639 | while (drive != cmd_drives[index]) { |
641 | if (++index > 3) { | 640 | if (++index > 3) { |
@@ -662,16 +661,14 @@ static void cmd640_tune_drive (ide_drive_t *drive, u8 mode_wanted) | |||
662 | return; | 661 | return; |
663 | } | 662 | } |
664 | 663 | ||
665 | (void) ide_get_best_pio_mode (drive, mode_wanted, 5, &d); | 664 | mode_wanted = ide_get_best_pio_mode(drive, mode_wanted, 5); |
666 | cmd640_set_mode (index, d.pio_mode, d.cycle_time); | 665 | cycle_time = ide_pio_cycle_time(drive, mode_wanted); |
666 | cmd640_set_mode(index, mode_wanted, cycle_time); | ||
667 | |||
668 | printk("%s: selected cmd640 PIO mode%d (%dns)", | ||
669 | drive->name, mode_wanted, cycle_time); | ||
667 | 670 | ||
668 | printk ("%s: selected cmd640 PIO mode%d (%dns)%s", | ||
669 | drive->name, | ||
670 | d.pio_mode, | ||
671 | d.cycle_time, | ||
672 | d.overridden ? " (overriding vendor mode)" : ""); | ||
673 | display_clocks(index); | 671 | display_clocks(index); |
674 | return; | ||
675 | } | 672 | } |
676 | 673 | ||
677 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ | 674 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ |
@@ -769,6 +766,7 @@ int __init ide_probe_for_cmd640x (void) | |||
769 | cmd_hwif0->name, 'a' + cmd640_chip_version - 1, bus_type, cfr); | 766 | cmd_hwif0->name, 'a' + cmd640_chip_version - 1, bus_type, cfr); |
770 | cmd_hwif0->chipset = ide_cmd640; | 767 | cmd_hwif0->chipset = ide_cmd640; |
771 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED | 768 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED |
769 | cmd_hwif0->pio_mask = ATA_PIO5; | ||
772 | cmd_hwif0->tuneproc = &cmd640_tune_drive; | 770 | cmd_hwif0->tuneproc = &cmd640_tune_drive; |
773 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ | 771 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ |
774 | 772 | ||
@@ -824,6 +822,7 @@ int __init ide_probe_for_cmd640x (void) | |||
824 | cmd_hwif1->mate = cmd_hwif0; | 822 | cmd_hwif1->mate = cmd_hwif0; |
825 | cmd_hwif1->channel = 1; | 823 | cmd_hwif1->channel = 1; |
826 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED | 824 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED |
825 | cmd_hwif1->pio_mask = ATA_PIO5; | ||
827 | cmd_hwif1->tuneproc = &cmd640_tune_drive; | 826 | cmd_hwif1->tuneproc = &cmd640_tune_drive; |
828 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ | 827 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ |
829 | } | 828 | } |
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c index 1e89dd6e5bbf..19633c5aba15 100644 --- a/drivers/ide/pci/cmd64x.c +++ b/drivers/ide/pci/cmd64x.c | |||
@@ -221,17 +221,18 @@ static u8 cmd64x_tune_pio (ide_drive_t *drive, u8 mode_wanted) | |||
221 | { | 221 | { |
222 | ide_hwif_t *hwif = HWIF(drive); | 222 | ide_hwif_t *hwif = HWIF(drive); |
223 | struct pci_dev *dev = hwif->pci_dev; | 223 | struct pci_dev *dev = hwif->pci_dev; |
224 | ide_pio_data_t pio; | 224 | unsigned int cycle_time; |
225 | u8 pio_mode, setup_count, arttim = 0; | 225 | u8 pio_mode, setup_count, arttim = 0; |
226 | static const u8 setup_values[] = {0x40, 0x40, 0x40, 0x80, 0, 0xc0}; | 226 | static const u8 setup_values[] = {0x40, 0x40, 0x40, 0x80, 0, 0xc0}; |
227 | static const u8 arttim_regs[4] = {ARTTIM0, ARTTIM1, ARTTIM23, ARTTIM23}; | 227 | static const u8 arttim_regs[4] = {ARTTIM0, ARTTIM1, ARTTIM23, ARTTIM23}; |
228 | pio_mode = ide_get_best_pio_mode(drive, mode_wanted, 5, &pio); | ||
229 | 228 | ||
230 | cmdprintk("%s: PIO mode wanted %d, selected %d (%d ns)%s\n", | 229 | pio_mode = ide_get_best_pio_mode(drive, mode_wanted, 5); |
231 | drive->name, mode_wanted, pio_mode, pio.cycle_time, | 230 | cycle_time = ide_pio_cycle_time(drive, pio_mode); |
232 | pio.overridden ? " (overriding vendor mode)" : ""); | ||
233 | 231 | ||
234 | program_cycle_times(drive, pio.cycle_time, | 232 | cmdprintk("%s: PIO mode wanted %d, selected %d (%d ns)\n", |
233 | drive->name, mode_wanted, pio_mode, cycle_time); | ||
234 | |||
235 | program_cycle_times(drive, cycle_time, | ||
235 | ide_pio_timings[pio_mode].active_time); | 236 | ide_pio_timings[pio_mode].active_time); |
236 | 237 | ||
237 | setup_count = quantize_timing(ide_pio_timings[pio_mode].setup_time, | 238 | setup_count = quantize_timing(ide_pio_timings[pio_mode].setup_time, |
@@ -618,40 +619,40 @@ static ide_pci_device_t cmd64x_chipsets[] __devinitdata = { | |||
618 | .init_setup = init_setup_cmd64x, | 619 | .init_setup = init_setup_cmd64x, |
619 | .init_chipset = init_chipset_cmd64x, | 620 | .init_chipset = init_chipset_cmd64x, |
620 | .init_hwif = init_hwif_cmd64x, | 621 | .init_hwif = init_hwif_cmd64x, |
621 | .channels = 2, | ||
622 | .autodma = AUTODMA, | 622 | .autodma = AUTODMA, |
623 | .enablebits = {{0x00,0x00,0x00}, {0x51,0x08,0x08}}, | 623 | .enablebits = {{0x00,0x00,0x00}, {0x51,0x08,0x08}}, |
624 | .bootable = ON_BOARD, | 624 | .bootable = ON_BOARD, |
625 | .pio_mask = ATA_PIO5, | ||
625 | .udma_mask = 0x00, /* no udma */ | 626 | .udma_mask = 0x00, /* no udma */ |
626 | },{ /* 1 */ | 627 | },{ /* 1 */ |
627 | .name = "CMD646", | 628 | .name = "CMD646", |
628 | .init_setup = init_setup_cmd646, | 629 | .init_setup = init_setup_cmd646, |
629 | .init_chipset = init_chipset_cmd64x, | 630 | .init_chipset = init_chipset_cmd64x, |
630 | .init_hwif = init_hwif_cmd64x, | 631 | .init_hwif = init_hwif_cmd64x, |
631 | .channels = 2, | ||
632 | .autodma = AUTODMA, | 632 | .autodma = AUTODMA, |
633 | .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, | 633 | .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, |
634 | .bootable = ON_BOARD, | 634 | .bootable = ON_BOARD, |
635 | .pio_mask = ATA_PIO5, | ||
635 | .udma_mask = 0x07, /* udma0-2 */ | 636 | .udma_mask = 0x07, /* udma0-2 */ |
636 | },{ /* 2 */ | 637 | },{ /* 2 */ |
637 | .name = "CMD648", | 638 | .name = "CMD648", |
638 | .init_setup = init_setup_cmd64x, | 639 | .init_setup = init_setup_cmd64x, |
639 | .init_chipset = init_chipset_cmd64x, | 640 | .init_chipset = init_chipset_cmd64x, |
640 | .init_hwif = init_hwif_cmd64x, | 641 | .init_hwif = init_hwif_cmd64x, |
641 | .channels = 2, | ||
642 | .autodma = AUTODMA, | 642 | .autodma = AUTODMA, |
643 | .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, | 643 | .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, |
644 | .bootable = ON_BOARD, | 644 | .bootable = ON_BOARD, |
645 | .pio_mask = ATA_PIO5, | ||
645 | .udma_mask = 0x1f, /* udma0-4 */ | 646 | .udma_mask = 0x1f, /* udma0-4 */ |
646 | },{ /* 3 */ | 647 | },{ /* 3 */ |
647 | .name = "CMD649", | 648 | .name = "CMD649", |
648 | .init_setup = init_setup_cmd64x, | 649 | .init_setup = init_setup_cmd64x, |
649 | .init_chipset = init_chipset_cmd64x, | 650 | .init_chipset = init_chipset_cmd64x, |
650 | .init_hwif = init_hwif_cmd64x, | 651 | .init_hwif = init_hwif_cmd64x, |
651 | .channels = 2, | ||
652 | .autodma = AUTODMA, | 652 | .autodma = AUTODMA, |
653 | .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, | 653 | .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, |
654 | .bootable = ON_BOARD, | 654 | .bootable = ON_BOARD, |
655 | .pio_mask = ATA_PIO5, | ||
655 | .udma_mask = 0x3f, /* udma0-5 */ | 656 | .udma_mask = 0x3f, /* udma0-5 */ |
656 | } | 657 | } |
657 | }; | 658 | }; |
diff --git a/drivers/ide/pci/cs5520.c b/drivers/ide/pci/cs5520.c index 3b88a3a56116..bccedf9b8b28 100644 --- a/drivers/ide/pci/cs5520.c +++ b/drivers/ide/pci/cs5520.c | |||
@@ -126,7 +126,7 @@ static int cs5520_tune_chipset(ide_drive_t *drive, u8 xferspeed) | |||
126 | 126 | ||
127 | static void cs5520_tune_drive(ide_drive_t *drive, u8 pio) | 127 | static void cs5520_tune_drive(ide_drive_t *drive, u8 pio) |
128 | { | 128 | { |
129 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | 129 | pio = ide_get_best_pio_mode(drive, pio, 4); |
130 | cs5520_tune_chipset(drive, (XFER_PIO_0 + pio)); | 130 | cs5520_tune_chipset(drive, (XFER_PIO_0 + pio)); |
131 | } | 131 | } |
132 | 132 | ||
@@ -194,10 +194,10 @@ static void __devinit init_hwif_cs5520(ide_hwif_t *hwif) | |||
194 | .name = name_str, \ | 194 | .name = name_str, \ |
195 | .init_setup_dma = cs5520_init_setup_dma, \ | 195 | .init_setup_dma = cs5520_init_setup_dma, \ |
196 | .init_hwif = init_hwif_cs5520, \ | 196 | .init_hwif = init_hwif_cs5520, \ |
197 | .channels = 2, \ | ||
198 | .autodma = AUTODMA, \ | 197 | .autodma = AUTODMA, \ |
199 | .bootable = ON_BOARD, \ | 198 | .bootable = ON_BOARD, \ |
200 | .flags = IDEPCI_FLAG_ISA_PORTS, \ | 199 | .host_flags = IDE_HFLAG_ISA_PORTS, \ |
200 | .pio_mask = ATA_PIO4, \ | ||
201 | } | 201 | } |
202 | 202 | ||
203 | static ide_pci_device_t cyrix_chipsets[] __devinitdata = { | 203 | static ide_pci_device_t cyrix_chipsets[] __devinitdata = { |
diff --git a/drivers/ide/pci/cs5530.c b/drivers/ide/pci/cs5530.c index b5c00d15a704..acaf71fd4c09 100644 --- a/drivers/ide/pci/cs5530.c +++ b/drivers/ide/pci/cs5530.c | |||
@@ -82,7 +82,7 @@ static void cs5530_tunepio(ide_drive_t *drive, u8 pio) | |||
82 | 82 | ||
83 | static void cs5530_tuneproc (ide_drive_t *drive, u8 pio) /* pio=255 means "autotune" */ | 83 | static void cs5530_tuneproc (ide_drive_t *drive, u8 pio) /* pio=255 means "autotune" */ |
84 | { | 84 | { |
85 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | 85 | pio = ide_get_best_pio_mode(drive, pio, 4); |
86 | 86 | ||
87 | if (cs5530_set_xfer_mode(drive, XFER_PIO_0 + pio) == 0) | 87 | if (cs5530_set_xfer_mode(drive, XFER_PIO_0 + pio) == 0) |
88 | cs5530_tunepio(drive, pio); | 88 | cs5530_tunepio(drive, pio); |
@@ -341,9 +341,9 @@ static ide_pci_device_t cs5530_chipset __devinitdata = { | |||
341 | .name = "CS5530", | 341 | .name = "CS5530", |
342 | .init_chipset = init_chipset_cs5530, | 342 | .init_chipset = init_chipset_cs5530, |
343 | .init_hwif = init_hwif_cs5530, | 343 | .init_hwif = init_hwif_cs5530, |
344 | .channels = 2, | ||
345 | .autodma = AUTODMA, | 344 | .autodma = AUTODMA, |
346 | .bootable = ON_BOARD, | 345 | .bootable = ON_BOARD, |
346 | .pio_mask = ATA_PIO4, | ||
347 | }; | 347 | }; |
348 | 348 | ||
349 | static int __devinit cs5530_init_one(struct pci_dev *dev, const struct pci_device_id *id) | 349 | static int __devinit cs5530_init_one(struct pci_dev *dev, const struct pci_device_id *id) |
diff --git a/drivers/ide/pci/cs5535.c b/drivers/ide/pci/cs5535.c index 10f61f38243c..ce44e38390aa 100644 --- a/drivers/ide/pci/cs5535.c +++ b/drivers/ide/pci/cs5535.c | |||
@@ -89,7 +89,7 @@ static void cs5535_set_speed(ide_drive_t *drive, u8 speed) | |||
89 | 89 | ||
90 | pioa = speed - XFER_PIO_0; | 90 | pioa = speed - XFER_PIO_0; |
91 | piob = ide_get_best_pio_mode(&(drive->hwif->drives[!unit]), | 91 | piob = ide_get_best_pio_mode(&(drive->hwif->drives[!unit]), |
92 | 255, 4, NULL); | 92 | 255, 4); |
93 | cmd = pioa < piob ? pioa : piob; | 93 | cmd = pioa < piob ? pioa : piob; |
94 | 94 | ||
95 | /* Write the speed of the current drive */ | 95 | /* Write the speed of the current drive */ |
@@ -159,7 +159,7 @@ static void cs5535_tuneproc(ide_drive_t *drive, u8 xferspeed) | |||
159 | /* cs5535 max pio is pio 4, best_pio will check the blacklist. | 159 | /* cs5535 max pio is pio 4, best_pio will check the blacklist. |
160 | i think we don't need to rate_filter the incoming xferspeed | 160 | i think we don't need to rate_filter the incoming xferspeed |
161 | since we know we're only going to choose pio */ | 161 | since we know we're only going to choose pio */ |
162 | xferspeed = ide_get_best_pio_mode(drive, xferspeed, 4, NULL); | 162 | xferspeed = ide_get_best_pio_mode(drive, xferspeed, 4); |
163 | ide_config_drive_speed(drive, modes[xferspeed]); | 163 | ide_config_drive_speed(drive, modes[xferspeed]); |
164 | cs5535_set_speed(drive, xferspeed); | 164 | cs5535_set_speed(drive, xferspeed); |
165 | } | 165 | } |
@@ -174,7 +174,7 @@ static int cs5535_dma_check(ide_drive_t *drive) | |||
174 | return 0; | 174 | return 0; |
175 | 175 | ||
176 | if (ide_use_fast_pio(drive)) { | 176 | if (ide_use_fast_pio(drive)) { |
177 | speed = ide_get_best_pio_mode(drive, 255, 4, NULL); | 177 | speed = ide_get_best_pio_mode(drive, 255, 4); |
178 | cs5535_set_drive(drive, speed); | 178 | cs5535_set_drive(drive, speed); |
179 | } | 179 | } |
180 | 180 | ||
@@ -228,9 +228,10 @@ static void __devinit init_hwif_cs5535(ide_hwif_t *hwif) | |||
228 | static ide_pci_device_t cs5535_chipset __devinitdata = { | 228 | static ide_pci_device_t cs5535_chipset __devinitdata = { |
229 | .name = "CS5535", | 229 | .name = "CS5535", |
230 | .init_hwif = init_hwif_cs5535, | 230 | .init_hwif = init_hwif_cs5535, |
231 | .channels = 1, | ||
232 | .autodma = AUTODMA, | 231 | .autodma = AUTODMA, |
233 | .bootable = ON_BOARD, | 232 | .bootable = ON_BOARD, |
233 | .host_flags = IDE_HFLAG_SINGLE, | ||
234 | .pio_mask = ATA_PIO4, | ||
234 | }; | 235 | }; |
235 | 236 | ||
236 | static int __devinit cs5535_init_one(struct pci_dev *dev, | 237 | static int __devinit cs5535_init_one(struct pci_dev *dev, |
diff --git a/drivers/ide/pci/cy82c693.c b/drivers/ide/pci/cy82c693.c index 103b9db97853..daa36fcbc8ef 100644 --- a/drivers/ide/pci/cy82c693.c +++ b/drivers/ide/pci/cy82c693.c | |||
@@ -330,7 +330,7 @@ static void cy82c693_tune_drive (ide_drive_t *drive, u8 pio) | |||
330 | #endif /* CY82C693_DEBUG_LOGS */ | 330 | #endif /* CY82C693_DEBUG_LOGS */ |
331 | 331 | ||
332 | /* first let's calc the pio modes */ | 332 | /* first let's calc the pio modes */ |
333 | pio = ide_get_best_pio_mode(drive, pio, CY82C693_MAX_PIO, NULL); | 333 | pio = ide_get_best_pio_mode(drive, pio, CY82C693_MAX_PIO); |
334 | 334 | ||
335 | #if CY82C693_DEBUG_INFO | 335 | #if CY82C693_DEBUG_INFO |
336 | printk (KERN_INFO "%s: Selected PIO mode %d\n", drive->name, pio); | 336 | printk (KERN_INFO "%s: Selected PIO mode %d\n", drive->name, pio); |
@@ -483,9 +483,10 @@ static ide_pci_device_t cy82c693_chipset __devinitdata = { | |||
483 | .init_chipset = init_chipset_cy82c693, | 483 | .init_chipset = init_chipset_cy82c693, |
484 | .init_iops = init_iops_cy82c693, | 484 | .init_iops = init_iops_cy82c693, |
485 | .init_hwif = init_hwif_cy82c693, | 485 | .init_hwif = init_hwif_cy82c693, |
486 | .channels = 1, | ||
487 | .autodma = AUTODMA, | 486 | .autodma = AUTODMA, |
488 | .bootable = ON_BOARD, | 487 | .bootable = ON_BOARD, |
488 | .host_flags = IDE_HFLAG_SINGLE, | ||
489 | .pio_mask = ATA_PIO4, | ||
489 | }; | 490 | }; |
490 | 491 | ||
491 | static int __devinit cy82c693_init_one(struct pci_dev *dev, const struct pci_device_id *id) | 492 | static int __devinit cy82c693_init_one(struct pci_dev *dev, const struct pci_device_id *id) |
diff --git a/drivers/ide/pci/generic.c b/drivers/ide/pci/generic.c index 0d51a11e81da..48caa468b762 100644 --- a/drivers/ide/pci/generic.c +++ b/drivers/ide/pci/generic.c | |||
@@ -95,92 +95,77 @@ static ide_pci_device_t generic_chipsets[] __devinitdata = { | |||
95 | { /* 0 */ | 95 | { /* 0 */ |
96 | .name = "Unknown", | 96 | .name = "Unknown", |
97 | .init_hwif = init_hwif_generic, | 97 | .init_hwif = init_hwif_generic, |
98 | .channels = 2, | ||
99 | .autodma = AUTODMA, | 98 | .autodma = AUTODMA, |
100 | .bootable = ON_BOARD, | 99 | .bootable = ON_BOARD, |
101 | },{ /* 1 */ | 100 | },{ /* 1 */ |
102 | .name = "NS87410", | 101 | .name = "NS87410", |
103 | .init_hwif = init_hwif_generic, | 102 | .init_hwif = init_hwif_generic, |
104 | .channels = 2, | ||
105 | .autodma = AUTODMA, | 103 | .autodma = AUTODMA, |
106 | .enablebits = {{0x43,0x08,0x08}, {0x47,0x08,0x08}}, | 104 | .enablebits = {{0x43,0x08,0x08}, {0x47,0x08,0x08}}, |
107 | .bootable = ON_BOARD, | 105 | .bootable = ON_BOARD, |
108 | },{ /* 2 */ | 106 | },{ /* 2 */ |
109 | .name = "SAMURAI", | 107 | .name = "SAMURAI", |
110 | .init_hwif = init_hwif_generic, | 108 | .init_hwif = init_hwif_generic, |
111 | .channels = 2, | ||
112 | .autodma = AUTODMA, | 109 | .autodma = AUTODMA, |
113 | .bootable = ON_BOARD, | 110 | .bootable = ON_BOARD, |
114 | },{ /* 3 */ | 111 | },{ /* 3 */ |
115 | .name = "HT6565", | 112 | .name = "HT6565", |
116 | .init_hwif = init_hwif_generic, | 113 | .init_hwif = init_hwif_generic, |
117 | .channels = 2, | ||
118 | .autodma = AUTODMA, | 114 | .autodma = AUTODMA, |
119 | .bootable = ON_BOARD, | 115 | .bootable = ON_BOARD, |
120 | },{ /* 4 */ | 116 | },{ /* 4 */ |
121 | .name = "UM8673F", | 117 | .name = "UM8673F", |
122 | .init_hwif = init_hwif_generic, | 118 | .init_hwif = init_hwif_generic, |
123 | .channels = 2, | ||
124 | .autodma = NODMA, | 119 | .autodma = NODMA, |
125 | .bootable = ON_BOARD, | 120 | .bootable = ON_BOARD, |
126 | },{ /* 5 */ | 121 | },{ /* 5 */ |
127 | .name = "UM8886A", | 122 | .name = "UM8886A", |
128 | .init_hwif = init_hwif_generic, | 123 | .init_hwif = init_hwif_generic, |
129 | .channels = 2, | ||
130 | .autodma = NODMA, | 124 | .autodma = NODMA, |
131 | .bootable = ON_BOARD, | 125 | .bootable = ON_BOARD, |
132 | },{ /* 6 */ | 126 | },{ /* 6 */ |
133 | .name = "UM8886BF", | 127 | .name = "UM8886BF", |
134 | .init_hwif = init_hwif_generic, | 128 | .init_hwif = init_hwif_generic, |
135 | .channels = 2, | ||
136 | .autodma = NODMA, | 129 | .autodma = NODMA, |
137 | .bootable = ON_BOARD, | 130 | .bootable = ON_BOARD, |
138 | },{ /* 7 */ | 131 | },{ /* 7 */ |
139 | .name = "HINT_IDE", | 132 | .name = "HINT_IDE", |
140 | .init_hwif = init_hwif_generic, | 133 | .init_hwif = init_hwif_generic, |
141 | .channels = 2, | ||
142 | .autodma = AUTODMA, | 134 | .autodma = AUTODMA, |
143 | .bootable = ON_BOARD, | 135 | .bootable = ON_BOARD, |
144 | },{ /* 8 */ | 136 | },{ /* 8 */ |
145 | .name = "VIA_IDE", | 137 | .name = "VIA_IDE", |
146 | .init_hwif = init_hwif_generic, | 138 | .init_hwif = init_hwif_generic, |
147 | .channels = 2, | ||
148 | .autodma = NOAUTODMA, | 139 | .autodma = NOAUTODMA, |
149 | .bootable = ON_BOARD, | 140 | .bootable = ON_BOARD, |
150 | },{ /* 9 */ | 141 | },{ /* 9 */ |
151 | .name = "OPTI621V", | 142 | .name = "OPTI621V", |
152 | .init_hwif = init_hwif_generic, | 143 | .init_hwif = init_hwif_generic, |
153 | .channels = 2, | ||
154 | .autodma = NOAUTODMA, | 144 | .autodma = NOAUTODMA, |
155 | .bootable = ON_BOARD, | 145 | .bootable = ON_BOARD, |
156 | },{ /* 10 */ | 146 | },{ /* 10 */ |
157 | .name = "VIA8237SATA", | 147 | .name = "VIA8237SATA", |
158 | .init_hwif = init_hwif_generic, | 148 | .init_hwif = init_hwif_generic, |
159 | .channels = 2, | ||
160 | .autodma = AUTODMA, | 149 | .autodma = AUTODMA, |
161 | .bootable = OFF_BOARD, | 150 | .bootable = OFF_BOARD, |
162 | },{ /* 11 */ | 151 | },{ /* 11 */ |
163 | .name = "Piccolo0102", | 152 | .name = "Piccolo0102", |
164 | .init_hwif = init_hwif_generic, | 153 | .init_hwif = init_hwif_generic, |
165 | .channels = 2, | ||
166 | .autodma = NOAUTODMA, | 154 | .autodma = NOAUTODMA, |
167 | .bootable = ON_BOARD, | 155 | .bootable = ON_BOARD, |
168 | },{ /* 12 */ | 156 | },{ /* 12 */ |
169 | .name = "Piccolo0103", | 157 | .name = "Piccolo0103", |
170 | .init_hwif = init_hwif_generic, | 158 | .init_hwif = init_hwif_generic, |
171 | .channels = 2, | ||
172 | .autodma = NOAUTODMA, | 159 | .autodma = NOAUTODMA, |
173 | .bootable = ON_BOARD, | 160 | .bootable = ON_BOARD, |
174 | },{ /* 13 */ | 161 | },{ /* 13 */ |
175 | .name = "Piccolo0105", | 162 | .name = "Piccolo0105", |
176 | .init_hwif = init_hwif_generic, | 163 | .init_hwif = init_hwif_generic, |
177 | .channels = 2, | ||
178 | .autodma = NOAUTODMA, | 164 | .autodma = NOAUTODMA, |
179 | .bootable = ON_BOARD, | 165 | .bootable = ON_BOARD, |
180 | },{ /* 14 */ | 166 | },{ /* 14 */ |
181 | .name = "Revolution", | 167 | .name = "Revolution", |
182 | .init_hwif = init_hwif_generic, | 168 | .init_hwif = init_hwif_generic, |
183 | .channels = 2, | ||
184 | .autodma = AUTODMA, | 169 | .autodma = AUTODMA, |
185 | .bootable = OFF_BOARD, | 170 | .bootable = OFF_BOARD, |
186 | } | 171 | } |
diff --git a/drivers/ide/pci/hpt34x.c b/drivers/ide/pci/hpt34x.c index 2c24c3de8846..19778c5fe711 100644 --- a/drivers/ide/pci/hpt34x.c +++ b/drivers/ide/pci/hpt34x.c | |||
@@ -80,7 +80,7 @@ static int hpt34x_tune_chipset (ide_drive_t *drive, u8 xferspeed) | |||
80 | 80 | ||
81 | static void hpt34x_tune_drive (ide_drive_t *drive, u8 pio) | 81 | static void hpt34x_tune_drive (ide_drive_t *drive, u8 pio) |
82 | { | 82 | { |
83 | pio = ide_get_best_pio_mode(drive, pio, 5, NULL); | 83 | pio = ide_get_best_pio_mode(drive, pio, 5); |
84 | (void) hpt34x_tune_chipset(drive, (XFER_PIO_0 + pio)); | 84 | (void) hpt34x_tune_chipset(drive, (XFER_PIO_0 + pio)); |
85 | } | 85 | } |
86 | 86 | ||
@@ -120,17 +120,10 @@ static unsigned int __devinit init_chipset_hpt34x(struct pci_dev *dev, const cha | |||
120 | pci_write_config_byte(dev, HPT34X_PCI_INIT_REG, 0x00); | 120 | pci_write_config_byte(dev, HPT34X_PCI_INIT_REG, 0x00); |
121 | pci_read_config_word(dev, PCI_COMMAND, &cmd); | 121 | pci_read_config_word(dev, PCI_COMMAND, &cmd); |
122 | 122 | ||
123 | if (cmd & PCI_COMMAND_MEMORY) { | 123 | if (cmd & PCI_COMMAND_MEMORY) |
124 | if (pci_resource_start(dev, PCI_ROM_RESOURCE)) { | ||
125 | pci_write_config_dword(dev, PCI_ROM_ADDRESS, | ||
126 | dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE); | ||
127 | printk(KERN_INFO "HPT345: ROM enabled at 0x%08lx\n", | ||
128 | (unsigned long)dev->resource[PCI_ROM_RESOURCE].start); | ||
129 | } | ||
130 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0xF0); | 124 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0xF0); |
131 | } else { | 125 | else |
132 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20); | 126 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20); |
133 | } | ||
134 | 127 | ||
135 | /* | 128 | /* |
136 | * Since 20-23 can be assigned and are R/W, we correct them. | 129 | * Since 20-23 can be assigned and are R/W, we correct them. |
@@ -182,10 +175,10 @@ static ide_pci_device_t hpt34x_chipset __devinitdata = { | |||
182 | .name = "HPT34X", | 175 | .name = "HPT34X", |
183 | .init_chipset = init_chipset_hpt34x, | 176 | .init_chipset = init_chipset_hpt34x, |
184 | .init_hwif = init_hwif_hpt34x, | 177 | .init_hwif = init_hwif_hpt34x, |
185 | .channels = 2, | ||
186 | .autodma = NOAUTODMA, | 178 | .autodma = NOAUTODMA, |
187 | .bootable = NEVER_BOARD, | 179 | .bootable = NEVER_BOARD, |
188 | .extra = 16 | 180 | .extra = 16, |
181 | .pio_mask = ATA_PIO5, | ||
189 | }; | 182 | }; |
190 | 183 | ||
191 | static int __devinit hpt34x_init_one(struct pci_dev *dev, const struct pci_device_id *id) | 184 | static int __devinit hpt34x_init_one(struct pci_dev *dev, const struct pci_device_id *id) |
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c index e9b07a97c340..2cd74c345a6c 100644 --- a/drivers/ide/pci/hpt366.c +++ b/drivers/ide/pci/hpt366.c | |||
@@ -652,7 +652,7 @@ static int hpt3xx_tune_chipset(ide_drive_t *drive, u8 speed) | |||
652 | 652 | ||
653 | static void hpt3xx_tune_drive(ide_drive_t *drive, u8 pio) | 653 | static void hpt3xx_tune_drive(ide_drive_t *drive, u8 pio) |
654 | { | 654 | { |
655 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | 655 | pio = ide_get_best_pio_mode(drive, pio, 4); |
656 | (void) hpt3xx_tune_chipset (drive, XFER_PIO_0 + pio); | 656 | (void) hpt3xx_tune_chipset (drive, XFER_PIO_0 + pio); |
657 | } | 657 | } |
658 | 658 | ||
@@ -994,14 +994,6 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha | |||
994 | */ | 994 | */ |
995 | *info = *(struct hpt_info *)pci_get_drvdata(dev); | 995 | *info = *(struct hpt_info *)pci_get_drvdata(dev); |
996 | 996 | ||
997 | /* | ||
998 | * FIXME: Not portable. Also, why do we enable the ROM in the first place? | ||
999 | * We don't seem to be using it. | ||
1000 | */ | ||
1001 | if (dev->resource[PCI_ROM_RESOURCE].start) | ||
1002 | pci_write_config_dword(dev, PCI_ROM_ADDRESS, | ||
1003 | dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE); | ||
1004 | |||
1005 | pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4)); | 997 | pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4)); |
1006 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78); | 998 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78); |
1007 | pci_write_config_byte(dev, PCI_MIN_GNT, 0x08); | 999 | pci_write_config_byte(dev, PCI_MIN_GNT, 0x08); |
@@ -1491,7 +1483,7 @@ static int __devinit init_setup_hpt366(struct pci_dev *dev, ide_pci_device_t *d) | |||
1491 | * to both functions -- really stupid design decision... :-( | 1483 | * to both functions -- really stupid design decision... :-( |
1492 | * Bit 4 is for the primary channel, bit 5 for the secondary. | 1484 | * Bit 4 is for the primary channel, bit 5 for the secondary. |
1493 | */ | 1485 | */ |
1494 | d->channels = 1; | 1486 | d->host_flags |= IDE_HFLAG_SINGLE; |
1495 | d->enablebits[0].mask = d->enablebits[0].val = 0x10; | 1487 | d->enablebits[0].mask = d->enablebits[0].val = 0x10; |
1496 | 1488 | ||
1497 | d->udma_mask = HPT366_ALLOW_ATA66_3 ? | 1489 | d->udma_mask = HPT366_ALLOW_ATA66_3 ? |
@@ -1554,71 +1546,71 @@ static ide_pci_device_t hpt366_chipsets[] __devinitdata = { | |||
1554 | .init_chipset = init_chipset_hpt366, | 1546 | .init_chipset = init_chipset_hpt366, |
1555 | .init_hwif = init_hwif_hpt366, | 1547 | .init_hwif = init_hwif_hpt366, |
1556 | .init_dma = init_dma_hpt366, | 1548 | .init_dma = init_dma_hpt366, |
1557 | .channels = 2, | ||
1558 | .autodma = AUTODMA, | 1549 | .autodma = AUTODMA, |
1559 | .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, | 1550 | .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, |
1560 | .bootable = OFF_BOARD, | 1551 | .bootable = OFF_BOARD, |
1561 | .extra = 240 | 1552 | .extra = 240, |
1553 | .pio_mask = ATA_PIO4, | ||
1562 | },{ /* 1 */ | 1554 | },{ /* 1 */ |
1563 | .name = "HPT372A", | 1555 | .name = "HPT372A", |
1564 | .init_setup = init_setup_hpt372a, | 1556 | .init_setup = init_setup_hpt372a, |
1565 | .init_chipset = init_chipset_hpt366, | 1557 | .init_chipset = init_chipset_hpt366, |
1566 | .init_hwif = init_hwif_hpt366, | 1558 | .init_hwif = init_hwif_hpt366, |
1567 | .init_dma = init_dma_hpt366, | 1559 | .init_dma = init_dma_hpt366, |
1568 | .channels = 2, | ||
1569 | .autodma = AUTODMA, | 1560 | .autodma = AUTODMA, |
1570 | .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, | 1561 | .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, |
1571 | .udma_mask = HPT372_ALLOW_ATA133_6 ? 0x7f : 0x3f, | 1562 | .udma_mask = HPT372_ALLOW_ATA133_6 ? 0x7f : 0x3f, |
1572 | .bootable = OFF_BOARD, | 1563 | .bootable = OFF_BOARD, |
1573 | .extra = 240 | 1564 | .extra = 240, |
1565 | .pio_mask = ATA_PIO4, | ||
1574 | },{ /* 2 */ | 1566 | },{ /* 2 */ |
1575 | .name = "HPT302", | 1567 | .name = "HPT302", |
1576 | .init_setup = init_setup_hpt302, | 1568 | .init_setup = init_setup_hpt302, |
1577 | .init_chipset = init_chipset_hpt366, | 1569 | .init_chipset = init_chipset_hpt366, |
1578 | .init_hwif = init_hwif_hpt366, | 1570 | .init_hwif = init_hwif_hpt366, |
1579 | .init_dma = init_dma_hpt366, | 1571 | .init_dma = init_dma_hpt366, |
1580 | .channels = 2, | ||
1581 | .autodma = AUTODMA, | 1572 | .autodma = AUTODMA, |
1582 | .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, | 1573 | .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, |
1583 | .udma_mask = HPT302_ALLOW_ATA133_6 ? 0x7f : 0x3f, | 1574 | .udma_mask = HPT302_ALLOW_ATA133_6 ? 0x7f : 0x3f, |
1584 | .bootable = OFF_BOARD, | 1575 | .bootable = OFF_BOARD, |
1585 | .extra = 240 | 1576 | .extra = 240, |
1577 | .pio_mask = ATA_PIO4, | ||
1586 | },{ /* 3 */ | 1578 | },{ /* 3 */ |
1587 | .name = "HPT371", | 1579 | .name = "HPT371", |
1588 | .init_setup = init_setup_hpt371, | 1580 | .init_setup = init_setup_hpt371, |
1589 | .init_chipset = init_chipset_hpt366, | 1581 | .init_chipset = init_chipset_hpt366, |
1590 | .init_hwif = init_hwif_hpt366, | 1582 | .init_hwif = init_hwif_hpt366, |
1591 | .init_dma = init_dma_hpt366, | 1583 | .init_dma = init_dma_hpt366, |
1592 | .channels = 2, | ||
1593 | .autodma = AUTODMA, | 1584 | .autodma = AUTODMA, |
1594 | .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, | 1585 | .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, |
1595 | .udma_mask = HPT371_ALLOW_ATA133_6 ? 0x7f : 0x3f, | 1586 | .udma_mask = HPT371_ALLOW_ATA133_6 ? 0x7f : 0x3f, |
1596 | .bootable = OFF_BOARD, | 1587 | .bootable = OFF_BOARD, |
1597 | .extra = 240 | 1588 | .extra = 240, |
1589 | .pio_mask = ATA_PIO4, | ||
1598 | },{ /* 4 */ | 1590 | },{ /* 4 */ |
1599 | .name = "HPT374", | 1591 | .name = "HPT374", |
1600 | .init_setup = init_setup_hpt374, | 1592 | .init_setup = init_setup_hpt374, |
1601 | .init_chipset = init_chipset_hpt366, | 1593 | .init_chipset = init_chipset_hpt366, |
1602 | .init_hwif = init_hwif_hpt366, | 1594 | .init_hwif = init_hwif_hpt366, |
1603 | .init_dma = init_dma_hpt366, | 1595 | .init_dma = init_dma_hpt366, |
1604 | .channels = 2, /* 4 */ | ||
1605 | .autodma = AUTODMA, | 1596 | .autodma = AUTODMA, |
1606 | .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, | 1597 | .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, |
1607 | .udma_mask = 0x3f, | 1598 | .udma_mask = 0x3f, |
1608 | .bootable = OFF_BOARD, | 1599 | .bootable = OFF_BOARD, |
1609 | .extra = 240 | 1600 | .extra = 240, |
1601 | .pio_mask = ATA_PIO4, | ||
1610 | },{ /* 5 */ | 1602 | },{ /* 5 */ |
1611 | .name = "HPT372N", | 1603 | .name = "HPT372N", |
1612 | .init_setup = init_setup_hpt372n, | 1604 | .init_setup = init_setup_hpt372n, |
1613 | .init_chipset = init_chipset_hpt366, | 1605 | .init_chipset = init_chipset_hpt366, |
1614 | .init_hwif = init_hwif_hpt366, | 1606 | .init_hwif = init_hwif_hpt366, |
1615 | .init_dma = init_dma_hpt366, | 1607 | .init_dma = init_dma_hpt366, |
1616 | .channels = 2, /* 4 */ | ||
1617 | .autodma = AUTODMA, | 1608 | .autodma = AUTODMA, |
1618 | .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, | 1609 | .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}}, |
1619 | .udma_mask = HPT372_ALLOW_ATA133_6 ? 0x7f : 0x3f, | 1610 | .udma_mask = HPT372_ALLOW_ATA133_6 ? 0x7f : 0x3f, |
1620 | .bootable = OFF_BOARD, | 1611 | .bootable = OFF_BOARD, |
1621 | .extra = 240 | 1612 | .extra = 240, |
1613 | .pio_mask = ATA_PIO4, | ||
1622 | } | 1614 | } |
1623 | }; | 1615 | }; |
1624 | 1616 | ||
diff --git a/drivers/ide/pci/it8213.c b/drivers/ide/pci/it8213.c index ff48c23e571e..95dbed7e6022 100644 --- a/drivers/ide/pci/it8213.c +++ b/drivers/ide/pci/it8213.c | |||
@@ -82,7 +82,7 @@ static void it8213_tuneproc (ide_drive_t *drive, u8 pio) | |||
82 | { 2, 1 }, | 82 | { 2, 1 }, |
83 | { 2, 3 }, }; | 83 | { 2, 3 }, }; |
84 | 84 | ||
85 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | 85 | pio = ide_get_best_pio_mode(drive, pio, 4); |
86 | 86 | ||
87 | spin_lock_irqsave(&tune_lock, flags); | 87 | spin_lock_irqsave(&tune_lock, flags); |
88 | pci_read_config_word(dev, master_port, &master_data); | 88 | pci_read_config_word(dev, master_port, &master_data); |
@@ -214,7 +214,7 @@ static int it8213_config_drive_for_dma (ide_drive_t *drive) | |||
214 | if (ide_tune_dma(drive)) | 214 | if (ide_tune_dma(drive)) |
215 | return 0; | 215 | return 0; |
216 | 216 | ||
217 | pio = ide_get_best_pio_mode(drive, 255, 4, NULL); | 217 | pio = ide_get_best_pio_mode(drive, 255, 4); |
218 | it8213_tune_chipset(drive, XFER_PIO_0 + pio); | 218 | it8213_tune_chipset(drive, XFER_PIO_0 + pio); |
219 | 219 | ||
220 | return -1; | 220 | return -1; |
@@ -272,10 +272,11 @@ static void __devinit init_hwif_it8213(ide_hwif_t *hwif) | |||
272 | { \ | 272 | { \ |
273 | .name = name_str, \ | 273 | .name = name_str, \ |
274 | .init_hwif = init_hwif_it8213, \ | 274 | .init_hwif = init_hwif_it8213, \ |
275 | .channels = 1, \ | ||
276 | .autodma = AUTODMA, \ | 275 | .autodma = AUTODMA, \ |
277 | .enablebits = {{0x41,0x80,0x80}}, \ | 276 | .enablebits = {{0x41,0x80,0x80}}, \ |
278 | .bootable = ON_BOARD, \ | 277 | .bootable = ON_BOARD, \ |
278 | .host_flags = IDE_HFLAG_SINGLE, \ | ||
279 | .pio_mask = ATA_PIO4, \ | ||
279 | } | 280 | } |
280 | 281 | ||
281 | static ide_pci_device_t it8213_chipsets[] __devinitdata = { | 282 | static ide_pci_device_t it8213_chipsets[] __devinitdata = { |
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/pci/it821x.c index 8197b653ba1e..9286c99e2ff0 100644 --- a/drivers/ide/pci/it821x.c +++ b/drivers/ide/pci/it821x.c | |||
@@ -255,7 +255,7 @@ static int it821x_tunepio(ide_drive_t *drive, u8 set_pio) | |||
255 | * on the cable. | 255 | * on the cable. |
256 | */ | 256 | */ |
257 | if (pair) { | 257 | if (pair) { |
258 | u8 pair_pio = ide_get_best_pio_mode(pair, 255, 4, NULL); | 258 | u8 pair_pio = ide_get_best_pio_mode(pair, 255, 4); |
259 | /* trim PIO to the slowest of the master/slave */ | 259 | /* trim PIO to the slowest of the master/slave */ |
260 | if (pair_pio < set_pio) | 260 | if (pair_pio < set_pio) |
261 | set_pio = pair_pio; | 261 | set_pio = pair_pio; |
@@ -276,7 +276,7 @@ static int it821x_tunepio(ide_drive_t *drive, u8 set_pio) | |||
276 | 276 | ||
277 | static void it821x_tuneproc(ide_drive_t *drive, u8 pio) | 277 | static void it821x_tuneproc(ide_drive_t *drive, u8 pio) |
278 | { | 278 | { |
279 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | 279 | pio = ide_get_best_pio_mode(drive, pio, 4); |
280 | (void)it821x_tunepio(drive, pio); | 280 | (void)it821x_tunepio(drive, pio); |
281 | } | 281 | } |
282 | 282 | ||
@@ -718,10 +718,10 @@ static unsigned int __devinit init_chipset_it821x(struct pci_dev *dev, const cha | |||
718 | .name = name_str, \ | 718 | .name = name_str, \ |
719 | .init_chipset = init_chipset_it821x, \ | 719 | .init_chipset = init_chipset_it821x, \ |
720 | .init_hwif = init_hwif_it821x, \ | 720 | .init_hwif = init_hwif_it821x, \ |
721 | .channels = 2, \ | ||
722 | .autodma = AUTODMA, \ | 721 | .autodma = AUTODMA, \ |
723 | .bootable = ON_BOARD, \ | 722 | .bootable = ON_BOARD, \ |
724 | .fixup = it821x_fixups \ | 723 | .fixup = it821x_fixups, \ |
724 | .pio_mask = ATA_PIO4, \ | ||
725 | } | 725 | } |
726 | 726 | ||
727 | static ide_pci_device_t it821x_chipsets[] __devinitdata = { | 727 | static ide_pci_device_t it821x_chipsets[] __devinitdata = { |
diff --git a/drivers/ide/pci/jmicron.c b/drivers/ide/pci/jmicron.c index a6008f63e71e..d7ce9dd8de16 100644 --- a/drivers/ide/pci/jmicron.c +++ b/drivers/ide/pci/jmicron.c | |||
@@ -97,7 +97,7 @@ static void jmicron_tuneproc (ide_drive_t *drive, byte mode_wanted) | |||
97 | 97 | ||
98 | static void config_jmicron_chipset_for_pio (ide_drive_t *drive, byte set_speed) | 98 | static void config_jmicron_chipset_for_pio (ide_drive_t *drive, byte set_speed) |
99 | { | 99 | { |
100 | u8 speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5, NULL); | 100 | u8 speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5); |
101 | if (set_speed) | 101 | if (set_speed) |
102 | (void) ide_config_drive_speed(drive, speed); | 102 | (void) ide_config_drive_speed(drive, speed); |
103 | } | 103 | } |
@@ -177,10 +177,10 @@ fallback: | |||
177 | { \ | 177 | { \ |
178 | .name = name_str, \ | 178 | .name = name_str, \ |
179 | .init_hwif = init_hwif_jmicron, \ | 179 | .init_hwif = init_hwif_jmicron, \ |
180 | .channels = 2, \ | ||
181 | .autodma = AUTODMA, \ | 180 | .autodma = AUTODMA, \ |
182 | .bootable = ON_BOARD, \ | 181 | .bootable = ON_BOARD, \ |
183 | .enablebits = { {0x40, 1, 1}, {0x40, 0x10, 0x10} }, \ | 182 | .enablebits = { {0x40, 1, 1}, {0x40, 0x10, 0x10} }, \ |
183 | .pio_mask = ATA_PIO5, \ | ||
184 | } | 184 | } |
185 | 185 | ||
186 | static ide_pci_device_t jmicron_chipsets[] __devinitdata = { | 186 | static ide_pci_device_t jmicron_chipsets[] __devinitdata = { |
diff --git a/drivers/ide/pci/ns87415.c b/drivers/ide/pci/ns87415.c index b310c4f51077..09941f37d635 100644 --- a/drivers/ide/pci/ns87415.c +++ b/drivers/ide/pci/ns87415.c | |||
@@ -281,7 +281,6 @@ static ide_pci_device_t ns87415_chipset __devinitdata = { | |||
281 | .init_iops = init_iops_ns87415, | 281 | .init_iops = init_iops_ns87415, |
282 | #endif | 282 | #endif |
283 | .init_hwif = init_hwif_ns87415, | 283 | .init_hwif = init_hwif_ns87415, |
284 | .channels = 2, | ||
285 | .autodma = AUTODMA, | 284 | .autodma = AUTODMA, |
286 | .bootable = ON_BOARD, | 285 | .bootable = ON_BOARD, |
287 | }; | 286 | }; |
diff --git a/drivers/ide/pci/opti621.c b/drivers/ide/pci/opti621.c index aede7eee9246..3a2bb2723515 100644 --- a/drivers/ide/pci/opti621.c +++ b/drivers/ide/pci/opti621.c | |||
@@ -147,12 +147,12 @@ static void compute_pios(ide_drive_t *drive, u8 pio) | |||
147 | int d; | 147 | int d; |
148 | ide_hwif_t *hwif = HWIF(drive); | 148 | ide_hwif_t *hwif = HWIF(drive); |
149 | 149 | ||
150 | drive->drive_data = ide_get_best_pio_mode(drive, pio, OPTI621_MAX_PIO, NULL); | 150 | drive->drive_data = ide_get_best_pio_mode(drive, pio, OPTI621_MAX_PIO); |
151 | for (d = 0; d < 2; ++d) { | 151 | for (d = 0; d < 2; ++d) { |
152 | drive = &hwif->drives[d]; | 152 | drive = &hwif->drives[d]; |
153 | if (drive->present) { | 153 | if (drive->present) { |
154 | if (drive->drive_data == PIO_DONT_KNOW) | 154 | if (drive->drive_data == PIO_DONT_KNOW) |
155 | drive->drive_data = ide_get_best_pio_mode(drive, 255, OPTI621_MAX_PIO, NULL); | 155 | drive->drive_data = ide_get_best_pio_mode(drive, 255, OPTI621_MAX_PIO); |
156 | #ifdef OPTI621_DEBUG | 156 | #ifdef OPTI621_DEBUG |
157 | printk("%s: Selected PIO mode %d\n", | 157 | printk("%s: Selected PIO mode %d\n", |
158 | drive->name, drive->drive_data); | 158 | drive->name, drive->drive_data); |
@@ -350,17 +350,17 @@ static ide_pci_device_t opti621_chipsets[] __devinitdata = { | |||
350 | { /* 0 */ | 350 | { /* 0 */ |
351 | .name = "OPTI621", | 351 | .name = "OPTI621", |
352 | .init_hwif = init_hwif_opti621, | 352 | .init_hwif = init_hwif_opti621, |
353 | .channels = 2, | ||
354 | .autodma = AUTODMA, | 353 | .autodma = AUTODMA, |
355 | .enablebits = {{0x45,0x80,0x00}, {0x40,0x08,0x00}}, | 354 | .enablebits = {{0x45,0x80,0x00}, {0x40,0x08,0x00}}, |
356 | .bootable = ON_BOARD, | 355 | .bootable = ON_BOARD, |
356 | .pio_mask = ATA_PIO3, | ||
357 | },{ /* 1 */ | 357 | },{ /* 1 */ |
358 | .name = "OPTI621X", | 358 | .name = "OPTI621X", |
359 | .init_hwif = init_hwif_opti621, | 359 | .init_hwif = init_hwif_opti621, |
360 | .channels = 2, | ||
361 | .autodma = AUTODMA, | 360 | .autodma = AUTODMA, |
362 | .enablebits = {{0x45,0x80,0x00}, {0x40,0x08,0x00}}, | 361 | .enablebits = {{0x45,0x80,0x00}, {0x40,0x08,0x00}}, |
363 | .bootable = ON_BOARD, | 362 | .bootable = ON_BOARD, |
363 | .pio_mask = ATA_PIO3, | ||
364 | } | 364 | } |
365 | }; | 365 | }; |
366 | 366 | ||
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pci/pdc202xx_new.c index ee5020df005d..8a66a2871b3a 100644 --- a/drivers/ide/pci/pdc202xx_new.c +++ b/drivers/ide/pci/pdc202xx_new.c | |||
@@ -219,7 +219,7 @@ static int pdcnew_tune_chipset(ide_drive_t *drive, u8 speed) | |||
219 | 219 | ||
220 | static void pdcnew_tune_drive(ide_drive_t *drive, u8 pio) | 220 | static void pdcnew_tune_drive(ide_drive_t *drive, u8 pio) |
221 | { | 221 | { |
222 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | 222 | pio = ide_get_best_pio_mode(drive, pio, 4); |
223 | (void)pdcnew_tune_chipset(drive, XFER_PIO_0 + pio); | 223 | (void)pdcnew_tune_chipset(drive, XFER_PIO_0 + pio); |
224 | } | 224 | } |
225 | 225 | ||
@@ -378,13 +378,6 @@ static unsigned int __devinit init_chipset_pdcnew(struct pci_dev *dev, const cha | |||
378 | int f, r; | 378 | int f, r; |
379 | u8 pll_ctl0, pll_ctl1; | 379 | u8 pll_ctl0, pll_ctl1; |
380 | 380 | ||
381 | if (dev->resource[PCI_ROM_RESOURCE].start) { | ||
382 | pci_write_config_dword(dev, PCI_ROM_ADDRESS, | ||
383 | dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE); | ||
384 | printk(KERN_INFO "%s: ROM enabled at 0x%08lx\n", name, | ||
385 | (unsigned long)dev->resource[PCI_ROM_RESOURCE].start); | ||
386 | } | ||
387 | |||
388 | #ifdef CONFIG_PPC_PMAC | 381 | #ifdef CONFIG_PPC_PMAC |
389 | apple_kiwi_init(dev); | 382 | apple_kiwi_init(dev); |
390 | #endif | 383 | #endif |
@@ -573,63 +566,63 @@ static ide_pci_device_t pdcnew_chipsets[] __devinitdata = { | |||
573 | .init_setup = init_setup_pdcnew, | 566 | .init_setup = init_setup_pdcnew, |
574 | .init_chipset = init_chipset_pdcnew, | 567 | .init_chipset = init_chipset_pdcnew, |
575 | .init_hwif = init_hwif_pdc202new, | 568 | .init_hwif = init_hwif_pdc202new, |
576 | .channels = 2, | ||
577 | .autodma = AUTODMA, | 569 | .autodma = AUTODMA, |
578 | .bootable = OFF_BOARD, | 570 | .bootable = OFF_BOARD, |
571 | .pio_mask = ATA_PIO4, | ||
579 | .udma_mask = 0x3f, /* udma0-5 */ | 572 | .udma_mask = 0x3f, /* udma0-5 */ |
580 | },{ /* 1 */ | 573 | },{ /* 1 */ |
581 | .name = "PDC20269", | 574 | .name = "PDC20269", |
582 | .init_setup = init_setup_pdcnew, | 575 | .init_setup = init_setup_pdcnew, |
583 | .init_chipset = init_chipset_pdcnew, | 576 | .init_chipset = init_chipset_pdcnew, |
584 | .init_hwif = init_hwif_pdc202new, | 577 | .init_hwif = init_hwif_pdc202new, |
585 | .channels = 2, | ||
586 | .autodma = AUTODMA, | 578 | .autodma = AUTODMA, |
587 | .bootable = OFF_BOARD, | 579 | .bootable = OFF_BOARD, |
580 | .pio_mask = ATA_PIO4, | ||
588 | .udma_mask = 0x7f, /* udma0-6*/ | 581 | .udma_mask = 0x7f, /* udma0-6*/ |
589 | },{ /* 2 */ | 582 | },{ /* 2 */ |
590 | .name = "PDC20270", | 583 | .name = "PDC20270", |
591 | .init_setup = init_setup_pdc20270, | 584 | .init_setup = init_setup_pdc20270, |
592 | .init_chipset = init_chipset_pdcnew, | 585 | .init_chipset = init_chipset_pdcnew, |
593 | .init_hwif = init_hwif_pdc202new, | 586 | .init_hwif = init_hwif_pdc202new, |
594 | .channels = 2, | ||
595 | .autodma = AUTODMA, | 587 | .autodma = AUTODMA, |
596 | .bootable = OFF_BOARD, | 588 | .bootable = OFF_BOARD, |
589 | .pio_mask = ATA_PIO4, | ||
597 | .udma_mask = 0x3f, /* udma0-5 */ | 590 | .udma_mask = 0x3f, /* udma0-5 */ |
598 | },{ /* 3 */ | 591 | },{ /* 3 */ |
599 | .name = "PDC20271", | 592 | .name = "PDC20271", |
600 | .init_setup = init_setup_pdcnew, | 593 | .init_setup = init_setup_pdcnew, |
601 | .init_chipset = init_chipset_pdcnew, | 594 | .init_chipset = init_chipset_pdcnew, |
602 | .init_hwif = init_hwif_pdc202new, | 595 | .init_hwif = init_hwif_pdc202new, |
603 | .channels = 2, | ||
604 | .autodma = AUTODMA, | 596 | .autodma = AUTODMA, |
605 | .bootable = OFF_BOARD, | 597 | .bootable = OFF_BOARD, |
598 | .pio_mask = ATA_PIO4, | ||
606 | .udma_mask = 0x7f, /* udma0-6*/ | 599 | .udma_mask = 0x7f, /* udma0-6*/ |
607 | },{ /* 4 */ | 600 | },{ /* 4 */ |
608 | .name = "PDC20275", | 601 | .name = "PDC20275", |
609 | .init_setup = init_setup_pdcnew, | 602 | .init_setup = init_setup_pdcnew, |
610 | .init_chipset = init_chipset_pdcnew, | 603 | .init_chipset = init_chipset_pdcnew, |
611 | .init_hwif = init_hwif_pdc202new, | 604 | .init_hwif = init_hwif_pdc202new, |
612 | .channels = 2, | ||
613 | .autodma = AUTODMA, | 605 | .autodma = AUTODMA, |
614 | .bootable = OFF_BOARD, | 606 | .bootable = OFF_BOARD, |
607 | .pio_mask = ATA_PIO4, | ||
615 | .udma_mask = 0x7f, /* udma0-6*/ | 608 | .udma_mask = 0x7f, /* udma0-6*/ |
616 | },{ /* 5 */ | 609 | },{ /* 5 */ |
617 | .name = "PDC20276", | 610 | .name = "PDC20276", |
618 | .init_setup = init_setup_pdc20276, | 611 | .init_setup = init_setup_pdc20276, |
619 | .init_chipset = init_chipset_pdcnew, | 612 | .init_chipset = init_chipset_pdcnew, |
620 | .init_hwif = init_hwif_pdc202new, | 613 | .init_hwif = init_hwif_pdc202new, |
621 | .channels = 2, | ||
622 | .autodma = AUTODMA, | 614 | .autodma = AUTODMA, |
623 | .bootable = OFF_BOARD, | 615 | .bootable = OFF_BOARD, |
616 | .pio_mask = ATA_PIO4, | ||
624 | .udma_mask = 0x7f, /* udma0-6*/ | 617 | .udma_mask = 0x7f, /* udma0-6*/ |
625 | },{ /* 6 */ | 618 | },{ /* 6 */ |
626 | .name = "PDC20277", | 619 | .name = "PDC20277", |
627 | .init_setup = init_setup_pdcnew, | 620 | .init_setup = init_setup_pdcnew, |
628 | .init_chipset = init_chipset_pdcnew, | 621 | .init_chipset = init_chipset_pdcnew, |
629 | .init_hwif = init_hwif_pdc202new, | 622 | .init_hwif = init_hwif_pdc202new, |
630 | .channels = 2, | ||
631 | .autodma = AUTODMA, | 623 | .autodma = AUTODMA, |
632 | .bootable = OFF_BOARD, | 624 | .bootable = OFF_BOARD, |
625 | .pio_mask = ATA_PIO4, | ||
633 | .udma_mask = 0x7f, /* udma0-6*/ | 626 | .udma_mask = 0x7f, /* udma0-6*/ |
634 | } | 627 | } |
635 | }; | 628 | }; |
diff --git a/drivers/ide/pci/pdc202xx_old.c b/drivers/ide/pci/pdc202xx_old.c index 41ac4a94959f..fbcb0bb9c956 100644 --- a/drivers/ide/pci/pdc202xx_old.c +++ b/drivers/ide/pci/pdc202xx_old.c | |||
@@ -145,7 +145,7 @@ static int pdc202xx_tune_chipset (ide_drive_t *drive, u8 xferspeed) | |||
145 | 145 | ||
146 | static void pdc202xx_tune_drive(ide_drive_t *drive, u8 pio) | 146 | static void pdc202xx_tune_drive(ide_drive_t *drive, u8 pio) |
147 | { | 147 | { |
148 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | 148 | pio = ide_get_best_pio_mode(drive, pio, 4); |
149 | pdc202xx_tune_chipset(drive, XFER_PIO_0 + pio); | 149 | pdc202xx_tune_chipset(drive, XFER_PIO_0 + pio); |
150 | } | 150 | } |
151 | 151 | ||
@@ -316,14 +316,6 @@ static void pdc202xx_reset (ide_drive_t *drive) | |||
316 | static unsigned int __devinit init_chipset_pdc202xx(struct pci_dev *dev, | 316 | static unsigned int __devinit init_chipset_pdc202xx(struct pci_dev *dev, |
317 | const char *name) | 317 | const char *name) |
318 | { | 318 | { |
319 | /* This doesn't appear needed */ | ||
320 | if (dev->resource[PCI_ROM_RESOURCE].start) { | ||
321 | pci_write_config_dword(dev, PCI_ROM_ADDRESS, | ||
322 | dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE); | ||
323 | printk(KERN_INFO "%s: ROM enabled at 0x%08lx\n", name, | ||
324 | (unsigned long)dev->resource[PCI_ROM_RESOURCE].start); | ||
325 | } | ||
326 | |||
327 | return dev->irq; | 319 | return dev->irq; |
328 | } | 320 | } |
329 | 321 | ||
@@ -449,10 +441,10 @@ static ide_pci_device_t pdc202xx_chipsets[] __devinitdata = { | |||
449 | .init_chipset = init_chipset_pdc202xx, | 441 | .init_chipset = init_chipset_pdc202xx, |
450 | .init_hwif = init_hwif_pdc202xx, | 442 | .init_hwif = init_hwif_pdc202xx, |
451 | .init_dma = init_dma_pdc202xx, | 443 | .init_dma = init_dma_pdc202xx, |
452 | .channels = 2, | ||
453 | .autodma = AUTODMA, | 444 | .autodma = AUTODMA, |
454 | .bootable = OFF_BOARD, | 445 | .bootable = OFF_BOARD, |
455 | .extra = 16, | 446 | .extra = 16, |
447 | .pio_mask = ATA_PIO4, | ||
456 | .udma_mask = 0x07, /* udma0-2 */ | 448 | .udma_mask = 0x07, /* udma0-2 */ |
457 | },{ /* 1 */ | 449 | },{ /* 1 */ |
458 | .name = "PDC20262", | 450 | .name = "PDC20262", |
@@ -460,10 +452,10 @@ static ide_pci_device_t pdc202xx_chipsets[] __devinitdata = { | |||
460 | .init_chipset = init_chipset_pdc202xx, | 452 | .init_chipset = init_chipset_pdc202xx, |
461 | .init_hwif = init_hwif_pdc202xx, | 453 | .init_hwif = init_hwif_pdc202xx, |
462 | .init_dma = init_dma_pdc202xx, | 454 | .init_dma = init_dma_pdc202xx, |
463 | .channels = 2, | ||
464 | .autodma = AUTODMA, | 455 | .autodma = AUTODMA, |
465 | .bootable = OFF_BOARD, | 456 | .bootable = OFF_BOARD, |
466 | .extra = 48, | 457 | .extra = 48, |
458 | .pio_mask = ATA_PIO4, | ||
467 | .udma_mask = 0x1f, /* udma0-4 */ | 459 | .udma_mask = 0x1f, /* udma0-4 */ |
468 | },{ /* 2 */ | 460 | },{ /* 2 */ |
469 | .name = "PDC20263", | 461 | .name = "PDC20263", |
@@ -471,10 +463,10 @@ static ide_pci_device_t pdc202xx_chipsets[] __devinitdata = { | |||
471 | .init_chipset = init_chipset_pdc202xx, | 463 | .init_chipset = init_chipset_pdc202xx, |
472 | .init_hwif = init_hwif_pdc202xx, | 464 | .init_hwif = init_hwif_pdc202xx, |
473 | .init_dma = init_dma_pdc202xx, | 465 | .init_dma = init_dma_pdc202xx, |
474 | .channels = 2, | ||
475 | .autodma = AUTODMA, | 466 | .autodma = AUTODMA, |
476 | .bootable = OFF_BOARD, | 467 | .bootable = OFF_BOARD, |
477 | .extra = 48, | 468 | .extra = 48, |
469 | .pio_mask = ATA_PIO4, | ||
478 | .udma_mask = 0x1f, /* udma0-4 */ | 470 | .udma_mask = 0x1f, /* udma0-4 */ |
479 | },{ /* 3 */ | 471 | },{ /* 3 */ |
480 | .name = "PDC20265", | 472 | .name = "PDC20265", |
@@ -482,10 +474,10 @@ static ide_pci_device_t pdc202xx_chipsets[] __devinitdata = { | |||
482 | .init_chipset = init_chipset_pdc202xx, | 474 | .init_chipset = init_chipset_pdc202xx, |
483 | .init_hwif = init_hwif_pdc202xx, | 475 | .init_hwif = init_hwif_pdc202xx, |
484 | .init_dma = init_dma_pdc202xx, | 476 | .init_dma = init_dma_pdc202xx, |
485 | .channels = 2, | ||
486 | .autodma = AUTODMA, | 477 | .autodma = AUTODMA, |
487 | .bootable = OFF_BOARD, | 478 | .bootable = OFF_BOARD, |
488 | .extra = 48, | 479 | .extra = 48, |
480 | .pio_mask = ATA_PIO4, | ||
489 | .udma_mask = 0x3f, /* udma0-5 */ | 481 | .udma_mask = 0x3f, /* udma0-5 */ |
490 | },{ /* 4 */ | 482 | },{ /* 4 */ |
491 | .name = "PDC20267", | 483 | .name = "PDC20267", |
@@ -493,10 +485,10 @@ static ide_pci_device_t pdc202xx_chipsets[] __devinitdata = { | |||
493 | .init_chipset = init_chipset_pdc202xx, | 485 | .init_chipset = init_chipset_pdc202xx, |
494 | .init_hwif = init_hwif_pdc202xx, | 486 | .init_hwif = init_hwif_pdc202xx, |
495 | .init_dma = init_dma_pdc202xx, | 487 | .init_dma = init_dma_pdc202xx, |
496 | .channels = 2, | ||
497 | .autodma = AUTODMA, | 488 | .autodma = AUTODMA, |
498 | .bootable = OFF_BOARD, | 489 | .bootable = OFF_BOARD, |
499 | .extra = 48, | 490 | .extra = 48, |
491 | .pio_mask = ATA_PIO4, | ||
500 | .udma_mask = 0x3f, /* udma0-5 */ | 492 | .udma_mask = 0x3f, /* udma0-5 */ |
501 | } | 493 | } |
502 | }; | 494 | }; |
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c index 1372c35be035..4f69cd067e5e 100644 --- a/drivers/ide/pci/piix.c +++ b/drivers/ide/pci/piix.c | |||
@@ -219,7 +219,7 @@ static void piix_tune_pio (ide_drive_t *drive, u8 pio) | |||
219 | */ | 219 | */ |
220 | static void piix_tune_drive (ide_drive_t *drive, u8 pio) | 220 | static void piix_tune_drive (ide_drive_t *drive, u8 pio) |
221 | { | 221 | { |
222 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | 222 | pio = ide_get_best_pio_mode(drive, pio, 4); |
223 | piix_tune_pio(drive, pio); | 223 | piix_tune_pio(drive, pio); |
224 | (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio); | 224 | (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio); |
225 | } | 225 | } |
@@ -495,10 +495,10 @@ static void __devinit init_hwif_piix(ide_hwif_t *hwif) | |||
495 | .name = name_str, \ | 495 | .name = name_str, \ |
496 | .init_chipset = init_chipset_piix, \ | 496 | .init_chipset = init_chipset_piix, \ |
497 | .init_hwif = init_hwif_piix, \ | 497 | .init_hwif = init_hwif_piix, \ |
498 | .channels = 2, \ | ||
499 | .autodma = AUTODMA, \ | 498 | .autodma = AUTODMA, \ |
500 | .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \ | 499 | .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \ |
501 | .bootable = ON_BOARD, \ | 500 | .bootable = ON_BOARD, \ |
501 | .pio_mask = ATA_PIO4, \ | ||
502 | .udma_mask = udma, \ | 502 | .udma_mask = udma, \ |
503 | } | 503 | } |
504 | 504 | ||
@@ -514,11 +514,11 @@ static ide_pci_device_t piix_pci_info[] __devinitdata = { | |||
514 | */ | 514 | */ |
515 | .name = "MPIIX", | 515 | .name = "MPIIX", |
516 | .init_hwif = init_hwif_piix, | 516 | .init_hwif = init_hwif_piix, |
517 | .channels = 2, | ||
518 | .autodma = NODMA, | 517 | .autodma = NODMA, |
519 | .enablebits = {{0x6d,0xc0,0x80}, {0x6d,0xc0,0xc0}}, | 518 | .enablebits = {{0x6d,0xc0,0x80}, {0x6d,0xc0,0xc0}}, |
520 | .bootable = ON_BOARD, | 519 | .bootable = ON_BOARD, |
521 | .flags = IDEPCI_FLAG_ISA_PORTS | 520 | .host_flags = IDE_HFLAG_ISA_PORTS, |
521 | .pio_mask = ATA_PIO4, | ||
522 | }, | 522 | }, |
523 | 523 | ||
524 | /* 3 */ DECLARE_PIIX_DEV("PIIX3", 0x00), /* no udma */ | 524 | /* 3 */ DECLARE_PIIX_DEV("PIIX3", 0x00), /* no udma */ |
diff --git a/drivers/ide/pci/rz1000.c b/drivers/ide/pci/rz1000.c index f8c954690142..10e1ae7a4a02 100644 --- a/drivers/ide/pci/rz1000.c +++ b/drivers/ide/pci/rz1000.c | |||
@@ -52,7 +52,6 @@ static void __devinit init_hwif_rz1000 (ide_hwif_t *hwif) | |||
52 | static ide_pci_device_t rz1000_chipset __devinitdata = { | 52 | static ide_pci_device_t rz1000_chipset __devinitdata = { |
53 | .name = "RZ100x", | 53 | .name = "RZ100x", |
54 | .init_hwif = init_hwif_rz1000, | 54 | .init_hwif = init_hwif_rz1000, |
55 | .channels = 2, | ||
56 | .autodma = NODMA, | 55 | .autodma = NODMA, |
57 | .bootable = ON_BOARD, | 56 | .bootable = ON_BOARD, |
58 | }; | 57 | }; |
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c index 523363c93794..9bdc9694d50d 100644 --- a/drivers/ide/pci/sc1200.c +++ b/drivers/ide/pci/sc1200.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * linux/drivers/ide/pci/sc1200.c Version 0.94 Mar 10 2007 | 2 | * linux/drivers/ide/pci/sc1200.c Version 0.95 Jun 16 2007 |
3 | * | 3 | * |
4 | * Copyright (C) 2000-2002 Mark Lord <mlord@pobox.com> | 4 | * Copyright (C) 2000-2002 Mark Lord <mlord@pobox.com> |
5 | * Copyright (C) 2007 Bartlomiej Zolnierkiewicz | 5 | * Copyright (C) 2007 Bartlomiej Zolnierkiewicz |
@@ -304,7 +304,7 @@ static void sc1200_tuneproc (ide_drive_t *drive, byte pio) /* mode=255 means "au | |||
304 | return; | 304 | return; |
305 | } | 305 | } |
306 | 306 | ||
307 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | 307 | pio = ide_get_best_pio_mode(drive, pio, 4); |
308 | printk("SC1200: %s: setting PIO mode%d\n", drive->name, pio); | 308 | printk("SC1200: %s: setting PIO mode%d\n", drive->name, pio); |
309 | 309 | ||
310 | if (sc1200_set_xfer_mode(drive, XFER_PIO_0 + pio) == 0) | 310 | if (sc1200_set_xfer_mode(drive, XFER_PIO_0 + pio) == 0) |
@@ -390,7 +390,7 @@ static int sc1200_resume (struct pci_dev *dev) | |||
390 | // loop over all interfaces that are part of this pci device: | 390 | // loop over all interfaces that are part of this pci device: |
391 | // | 391 | // |
392 | while ((hwif = lookup_pci_dev(hwif, dev)) != NULL) { | 392 | while ((hwif = lookup_pci_dev(hwif, dev)) != NULL) { |
393 | unsigned int basereg, r, d, format; | 393 | unsigned int basereg, r; |
394 | sc1200_saved_state_t *ss = (sc1200_saved_state_t *)hwif->config_data; | 394 | sc1200_saved_state_t *ss = (sc1200_saved_state_t *)hwif->config_data; |
395 | 395 | ||
396 | // | 396 | // |
@@ -402,41 +402,6 @@ static int sc1200_resume (struct pci_dev *dev) | |||
402 | pci_write_config_dword(hwif->pci_dev, basereg + (r<<2), ss->regs[r]); | 402 | pci_write_config_dword(hwif->pci_dev, basereg + (r<<2), ss->regs[r]); |
403 | } | 403 | } |
404 | } | 404 | } |
405 | // | ||
406 | // Re-program drive PIO modes | ||
407 | // | ||
408 | pci_read_config_dword(hwif->pci_dev, basereg+4, &format); | ||
409 | format = (format >> 31) & 1; | ||
410 | if (format) | ||
411 | format += sc1200_get_pci_clock(); | ||
412 | for (d = 0; d < 2; ++d) { | ||
413 | ide_drive_t *drive = &(hwif->drives[d]); | ||
414 | if (drive->present) { | ||
415 | unsigned int pio, timings; | ||
416 | pci_read_config_dword(hwif->pci_dev, basereg+(drive->select.b.unit << 3), &timings); | ||
417 | for (pio = 0; pio <= 4; ++pio) { | ||
418 | if (sc1200_pio_timings[format][pio] == timings) | ||
419 | break; | ||
420 | } | ||
421 | if (pio > 4) | ||
422 | pio = 255; /* autotune */ | ||
423 | (void)sc1200_tuneproc(drive, pio); | ||
424 | } | ||
425 | } | ||
426 | // | ||
427 | // Re-program drive DMA modes | ||
428 | // | ||
429 | for (d = 0; d < MAX_DRIVES; ++d) { | ||
430 | ide_drive_t *drive = &(hwif->drives[d]); | ||
431 | if (drive->present && !__ide_dma_bad_drive(drive)) { | ||
432 | int enable_dma = drive->using_dma; | ||
433 | hwif->dma_off_quietly(drive); | ||
434 | if (sc1200_config_dma(drive)) | ||
435 | enable_dma = 0; | ||
436 | if (enable_dma) | ||
437 | hwif->dma_host_on(drive); | ||
438 | } | ||
439 | } | ||
440 | } | 405 | } |
441 | return 0; | 406 | return 0; |
442 | } | 407 | } |
@@ -471,9 +436,9 @@ static void __devinit init_hwif_sc1200 (ide_hwif_t *hwif) | |||
471 | static ide_pci_device_t sc1200_chipset __devinitdata = { | 436 | static ide_pci_device_t sc1200_chipset __devinitdata = { |
472 | .name = "SC1200", | 437 | .name = "SC1200", |
473 | .init_hwif = init_hwif_sc1200, | 438 | .init_hwif = init_hwif_sc1200, |
474 | .channels = 2, | ||
475 | .autodma = AUTODMA, | 439 | .autodma = AUTODMA, |
476 | .bootable = ON_BOARD, | 440 | .bootable = ON_BOARD, |
441 | .pio_mask = ATA_PIO4, | ||
477 | }; | 442 | }; |
478 | 443 | ||
479 | static int __devinit sc1200_init_one(struct pci_dev *dev, const struct pci_device_id *id) | 444 | static int __devinit sc1200_init_one(struct pci_dev *dev, const struct pci_device_id *id) |
diff --git a/drivers/ide/pci/scc_pata.c b/drivers/ide/pci/scc_pata.c index 7b87488e3daa..f668d235e6be 100644 --- a/drivers/ide/pci/scc_pata.c +++ b/drivers/ide/pci/scc_pata.c | |||
@@ -165,9 +165,9 @@ scc_ide_outbsync(ide_drive_t * drive, u8 addr, unsigned long port) | |||
165 | ide_hwif_t *hwif = HWIF(drive); | 165 | ide_hwif_t *hwif = HWIF(drive); |
166 | 166 | ||
167 | out_be32((void*)port, addr); | 167 | out_be32((void*)port, addr); |
168 | __asm__ __volatile__("eieio":::"memory"); | 168 | eieio(); |
169 | in_be32((void*)(hwif->dma_base + 0x01c)); | 169 | in_be32((void*)(hwif->dma_base + 0x01c)); |
170 | __asm__ __volatile__("eieio":::"memory"); | 170 | eieio(); |
171 | } | 171 | } |
172 | 172 | ||
173 | static void | 173 | static void |
@@ -210,7 +210,7 @@ static void scc_tuneproc(ide_drive_t *drive, byte mode_wanted) | |||
210 | unsigned char speed = XFER_PIO_0; | 210 | unsigned char speed = XFER_PIO_0; |
211 | int offset; | 211 | int offset; |
212 | 212 | ||
213 | mode_wanted = ide_get_best_pio_mode(drive, mode_wanted, 4, NULL); | 213 | mode_wanted = ide_get_best_pio_mode(drive, mode_wanted, 4); |
214 | switch (mode_wanted) { | 214 | switch (mode_wanted) { |
215 | case 4: | 215 | case 4: |
216 | speed = XFER_PIO_4; | 216 | speed = XFER_PIO_4; |
@@ -401,6 +401,33 @@ static int scc_ide_dma_end(ide_drive_t * drive) | |||
401 | ide_hwif_t *hwif = HWIF(drive); | 401 | ide_hwif_t *hwif = HWIF(drive); |
402 | unsigned long intsts_port = hwif->dma_base + 0x014; | 402 | unsigned long intsts_port = hwif->dma_base + 0x014; |
403 | u32 reg; | 403 | u32 reg; |
404 | int dma_stat, data_loss = 0; | ||
405 | static int retry = 0; | ||
406 | |||
407 | /* errata A308 workaround: Step5 (check data loss) */ | ||
408 | /* We don't check non ide_disk because it is limited to UDMA4 */ | ||
409 | if (!(in_be32((void __iomem *)IDE_ALTSTATUS_REG) & ERR_STAT) && | ||
410 | drive->media == ide_disk && drive->current_speed > XFER_UDMA_4) { | ||
411 | reg = in_be32((void __iomem *)intsts_port); | ||
412 | if (!(reg & INTSTS_ACTEINT)) { | ||
413 | printk(KERN_WARNING "%s: operation failed (transfer data loss)\n", | ||
414 | drive->name); | ||
415 | data_loss = 1; | ||
416 | if (retry++) { | ||
417 | struct request *rq = HWGROUP(drive)->rq; | ||
418 | int unit; | ||
419 | /* ERROR_RESET and drive->crc_count are needed | ||
420 | * to reduce DMA transfer mode in retry process. | ||
421 | */ | ||
422 | if (rq) | ||
423 | rq->errors |= ERROR_RESET; | ||
424 | for (unit = 0; unit < MAX_DRIVES; unit++) { | ||
425 | ide_drive_t *drive = &hwif->drives[unit]; | ||
426 | drive->crc_count++; | ||
427 | } | ||
428 | } | ||
429 | } | ||
430 | } | ||
404 | 431 | ||
405 | while (1) { | 432 | while (1) { |
406 | reg = in_be32((void __iomem *)intsts_port); | 433 | reg = in_be32((void __iomem *)intsts_port); |
@@ -469,27 +496,25 @@ static int scc_ide_dma_end(ide_drive_t * drive) | |||
469 | break; | 496 | break; |
470 | } | 497 | } |
471 | 498 | ||
472 | return __ide_dma_end(drive); | 499 | dma_stat = __ide_dma_end(drive); |
500 | if (data_loss) | ||
501 | dma_stat |= 2; /* emulate DMA error (to retry command) */ | ||
502 | return dma_stat; | ||
473 | } | 503 | } |
474 | 504 | ||
475 | /* returns 1 if dma irq issued, 0 otherwise */ | 505 | /* returns 1 if dma irq issued, 0 otherwise */ |
476 | static int scc_dma_test_irq(ide_drive_t *drive) | 506 | static int scc_dma_test_irq(ide_drive_t *drive) |
477 | { | 507 | { |
478 | ide_hwif_t *hwif = HWIF(drive); | 508 | ide_hwif_t *hwif = HWIF(drive); |
479 | u8 dma_stat = hwif->INB(hwif->dma_status); | 509 | u32 int_stat = in_be32((void __iomem *)hwif->dma_base + 0x014); |
480 | 510 | ||
481 | /* return 1 if INTR asserted */ | 511 | /* SCC errata A252,A308 workaround: Step4 */ |
482 | if ((dma_stat & 4) == 4) | 512 | if ((in_be32((void __iomem *)IDE_ALTSTATUS_REG) & ERR_STAT) && |
513 | (int_stat & INTSTS_INTRQ)) | ||
483 | return 1; | 514 | return 1; |
484 | 515 | ||
485 | /* Workaround for PTERADD: emulate DMA_INTR when | 516 | /* SCC errata A308 workaround: Step5 (polling IOIRQS) */ |
486 | * - IDE_STATUS[ERR] = 1 | 517 | if (int_stat & INTSTS_IOIRQS) |
487 | * - INT_STATUS[INTRQ] = 1 | ||
488 | * - DMA_STATUS[IORACTA] = 1 | ||
489 | */ | ||
490 | if (in_be32((void __iomem *)IDE_ALTSTATUS_REG) & ERR_STAT && | ||
491 | in_be32((void __iomem *)(hwif->dma_base + 0x014)) & INTSTS_INTRQ && | ||
492 | dma_stat & 1) | ||
493 | return 1; | 518 | return 1; |
494 | 519 | ||
495 | if (!drive->waiting_for_dma) | 520 | if (!drive->waiting_for_dma) |
@@ -498,6 +523,21 @@ static int scc_dma_test_irq(ide_drive_t *drive) | |||
498 | return 0; | 523 | return 0; |
499 | } | 524 | } |
500 | 525 | ||
526 | static u8 scc_udma_filter(ide_drive_t *drive) | ||
527 | { | ||
528 | ide_hwif_t *hwif = drive->hwif; | ||
529 | u8 mask = hwif->ultra_mask; | ||
530 | |||
531 | /* errata A308 workaround: limit non ide_disk drive to UDMA4 */ | ||
532 | if ((drive->media != ide_disk) && (mask & 0xE0)) { | ||
533 | printk(KERN_INFO "%s: limit %s to UDMA4\n", | ||
534 | SCC_PATA_NAME, drive->name); | ||
535 | mask = 0x1F; | ||
536 | } | ||
537 | |||
538 | return mask; | ||
539 | } | ||
540 | |||
501 | /** | 541 | /** |
502 | * setup_mmio_scc - map CTRL/BMID region | 542 | * setup_mmio_scc - map CTRL/BMID region |
503 | * @dev: PCI device we are configuring | 543 | * @dev: PCI device we are configuring |
@@ -702,6 +742,7 @@ static void __devinit init_hwif_scc(ide_hwif_t *hwif) | |||
702 | hwif->tuneproc = scc_tuneproc; | 742 | hwif->tuneproc = scc_tuneproc; |
703 | hwif->ide_dma_check = scc_config_drive_for_dma; | 743 | hwif->ide_dma_check = scc_config_drive_for_dma; |
704 | hwif->ide_dma_test_irq = scc_dma_test_irq; | 744 | hwif->ide_dma_test_irq = scc_dma_test_irq; |
745 | hwif->udma_filter = scc_udma_filter; | ||
705 | 746 | ||
706 | hwif->drives[0].autotune = IDE_TUNE_AUTO; | 747 | hwif->drives[0].autotune = IDE_TUNE_AUTO; |
707 | hwif->drives[1].autotune = IDE_TUNE_AUTO; | 748 | hwif->drives[1].autotune = IDE_TUNE_AUTO; |
@@ -731,9 +772,10 @@ static void __devinit init_hwif_scc(ide_hwif_t *hwif) | |||
731 | .init_setup = init_setup_scc, \ | 772 | .init_setup = init_setup_scc, \ |
732 | .init_iops = init_iops_scc, \ | 773 | .init_iops = init_iops_scc, \ |
733 | .init_hwif = init_hwif_scc, \ | 774 | .init_hwif = init_hwif_scc, \ |
734 | .channels = 1, \ | ||
735 | .autodma = AUTODMA, \ | 775 | .autodma = AUTODMA, \ |
736 | .bootable = ON_BOARD, \ | 776 | .bootable = ON_BOARD, \ |
777 | .host_flags = IDE_HFLAG_SINGLE, \ | ||
778 | .pio_mask = ATA_PIO4, \ | ||
737 | } | 779 | } |
738 | 780 | ||
739 | static ide_pci_device_t scc_chipsets[] __devinitdata = { | 781 | static ide_pci_device_t scc_chipsets[] __devinitdata = { |
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c index ed04e0c8dd4c..9fead2e7d4c8 100644 --- a/drivers/ide/pci/serverworks.c +++ b/drivers/ide/pci/serverworks.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * linux/drivers/ide/pci/serverworks.c Version 0.20 Jun 3 2007 | 2 | * linux/drivers/ide/pci/serverworks.c Version 0.22 Jun 27 2007 |
3 | * | 3 | * |
4 | * Copyright (C) 1998-2000 Michel Aubry | 4 | * Copyright (C) 1998-2000 Michel Aubry |
5 | * Copyright (C) 1998-2000 Andrzej Krzysztofowicz | 5 | * Copyright (C) 1998-2000 Andrzej Krzysztofowicz |
@@ -123,23 +123,45 @@ static u8 svwks_csb_check (struct pci_dev *dev) | |||
123 | } | 123 | } |
124 | return 0; | 124 | return 0; |
125 | } | 125 | } |
126 | |||
127 | static void svwks_tune_pio(ide_drive_t *drive, const u8 pio) | ||
128 | { | ||
129 | static const u8 pio_modes[] = { 0x5d, 0x47, 0x34, 0x22, 0x20 }; | ||
130 | static const u8 drive_pci[] = { 0x41, 0x40, 0x43, 0x42 }; | ||
131 | |||
132 | struct pci_dev *dev = drive->hwif->pci_dev; | ||
133 | |||
134 | pci_write_config_byte(dev, drive_pci[drive->dn], pio_modes[pio]); | ||
135 | |||
136 | if (svwks_csb_check(dev)) { | ||
137 | u16 csb_pio = 0; | ||
138 | |||
139 | pci_read_config_word(dev, 0x4a, &csb_pio); | ||
140 | |||
141 | csb_pio &= ~(0x0f << (4 * drive->dn)); | ||
142 | csb_pio |= (pio << (4 * drive->dn)); | ||
143 | |||
144 | pci_write_config_word(dev, 0x4a, csb_pio); | ||
145 | } | ||
146 | } | ||
147 | |||
126 | static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed) | 148 | static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed) |
127 | { | 149 | { |
128 | static const u8 udma_modes[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 }; | 150 | static const u8 udma_modes[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 }; |
129 | static const u8 dma_modes[] = { 0x77, 0x21, 0x20 }; | 151 | static const u8 dma_modes[] = { 0x77, 0x21, 0x20 }; |
130 | static const u8 pio_modes[] = { 0x5d, 0x47, 0x34, 0x22, 0x20 }; | ||
131 | static const u8 drive_pci[] = { 0x41, 0x40, 0x43, 0x42 }; | ||
132 | static const u8 drive_pci2[] = { 0x45, 0x44, 0x47, 0x46 }; | 152 | static const u8 drive_pci2[] = { 0x45, 0x44, 0x47, 0x46 }; |
133 | 153 | ||
134 | ide_hwif_t *hwif = HWIF(drive); | 154 | ide_hwif_t *hwif = HWIF(drive); |
135 | struct pci_dev *dev = hwif->pci_dev; | 155 | struct pci_dev *dev = hwif->pci_dev; |
136 | u8 speed = ide_rate_filter(drive, xferspeed); | 156 | u8 speed = ide_rate_filter(drive, xferspeed); |
137 | u8 pio = ide_get_best_pio_mode(drive, 255, 4, NULL); | ||
138 | u8 unit = (drive->select.b.unit & 0x01); | 157 | u8 unit = (drive->select.b.unit & 0x01); |
139 | u8 csb5 = svwks_csb_check(dev); | 158 | |
140 | u8 ultra_enable = 0, ultra_timing = 0; | 159 | u8 ultra_enable = 0, ultra_timing = 0, dma_timing = 0; |
141 | u8 dma_timing = 0, pio_timing = 0; | 160 | |
142 | u16 csb5_pio = 0; | 161 | if (speed >= XFER_PIO_0 && speed <= XFER_PIO_4) { |
162 | svwks_tune_pio(drive, speed - XFER_PIO_0); | ||
163 | return ide_config_drive_speed(drive, speed); | ||
164 | } | ||
143 | 165 | ||
144 | /* If we are about to put a disk into UDMA mode we screwed up. | 166 | /* If we are about to put a disk into UDMA mode we screwed up. |
145 | Our code assumes we never _ever_ do this on an OSB4 */ | 167 | Our code assumes we never _ever_ do this on an OSB4 */ |
@@ -149,31 +171,15 @@ static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed) | |||
149 | BUG(); | 171 | BUG(); |
150 | 172 | ||
151 | pci_read_config_byte(dev, (0x56|hwif->channel), &ultra_timing); | 173 | pci_read_config_byte(dev, (0x56|hwif->channel), &ultra_timing); |
152 | pci_read_config_word(dev, 0x4A, &csb5_pio); | ||
153 | pci_read_config_byte(dev, 0x54, &ultra_enable); | 174 | pci_read_config_byte(dev, 0x54, &ultra_enable); |
154 | 175 | ||
155 | ultra_timing &= ~(0x0F << (4*unit)); | 176 | ultra_timing &= ~(0x0F << (4*unit)); |
156 | ultra_enable &= ~(0x01 << drive->dn); | 177 | ultra_enable &= ~(0x01 << drive->dn); |
157 | csb5_pio &= ~(0x0F << (4*drive->dn)); | ||
158 | 178 | ||
159 | switch(speed) { | 179 | switch(speed) { |
160 | case XFER_PIO_4: | ||
161 | case XFER_PIO_3: | ||
162 | case XFER_PIO_2: | ||
163 | case XFER_PIO_1: | ||
164 | case XFER_PIO_0: | ||
165 | pio_timing |= pio_modes[speed - XFER_PIO_0]; | ||
166 | csb5_pio |= ((speed - XFER_PIO_0) << (4*drive->dn)); | ||
167 | break; | ||
168 | |||
169 | case XFER_MW_DMA_2: | 180 | case XFER_MW_DMA_2: |
170 | case XFER_MW_DMA_1: | 181 | case XFER_MW_DMA_1: |
171 | case XFER_MW_DMA_0: | 182 | case XFER_MW_DMA_0: |
172 | /* | ||
173 | * TODO: always setup PIO mode so this won't be needed | ||
174 | */ | ||
175 | pio_timing |= pio_modes[pio]; | ||
176 | csb5_pio |= (pio << (4*drive->dn)); | ||
177 | dma_timing |= dma_modes[speed - XFER_MW_DMA_0]; | 183 | dma_timing |= dma_modes[speed - XFER_MW_DMA_0]; |
178 | break; | 184 | break; |
179 | 185 | ||
@@ -183,11 +189,6 @@ static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed) | |||
183 | case XFER_UDMA_2: | 189 | case XFER_UDMA_2: |
184 | case XFER_UDMA_1: | 190 | case XFER_UDMA_1: |
185 | case XFER_UDMA_0: | 191 | case XFER_UDMA_0: |
186 | /* | ||
187 | * TODO: always setup PIO mode so this won't be needed | ||
188 | */ | ||
189 | pio_timing |= pio_modes[pio]; | ||
190 | csb5_pio |= (pio << (4*drive->dn)); | ||
191 | dma_timing |= dma_modes[2]; | 192 | dma_timing |= dma_modes[2]; |
192 | ultra_timing |= ((udma_modes[speed - XFER_UDMA_0]) << (4*unit)); | 193 | ultra_timing |= ((udma_modes[speed - XFER_UDMA_0]) << (4*unit)); |
193 | ultra_enable |= (0x01 << drive->dn); | 194 | ultra_enable |= (0x01 << drive->dn); |
@@ -195,10 +196,6 @@ static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed) | |||
195 | break; | 196 | break; |
196 | } | 197 | } |
197 | 198 | ||
198 | pci_write_config_byte(dev, drive_pci[drive->dn], pio_timing); | ||
199 | if (csb5) | ||
200 | pci_write_config_word(dev, 0x4A, csb5_pio); | ||
201 | |||
202 | pci_write_config_byte(dev, drive_pci2[drive->dn], dma_timing); | 199 | pci_write_config_byte(dev, drive_pci2[drive->dn], dma_timing); |
203 | pci_write_config_byte(dev, (0x56|hwif->channel), ultra_timing); | 200 | pci_write_config_byte(dev, (0x56|hwif->channel), ultra_timing); |
204 | pci_write_config_byte(dev, 0x54, ultra_enable); | 201 | pci_write_config_byte(dev, 0x54, ultra_enable); |
@@ -208,8 +205,9 @@ static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed) | |||
208 | 205 | ||
209 | static void svwks_tune_drive (ide_drive_t *drive, u8 pio) | 206 | static void svwks_tune_drive (ide_drive_t *drive, u8 pio) |
210 | { | 207 | { |
211 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | 208 | pio = ide_get_best_pio_mode(drive, pio, 4); |
212 | (void)svwks_tune_chipset(drive, XFER_PIO_0 + pio); | 209 | svwks_tune_pio(drive, pio); |
210 | (void)ide_config_drive_speed(drive, XFER_PIO_0 + pio); | ||
213 | } | 211 | } |
214 | 212 | ||
215 | static int svwks_config_drive_xfer_rate (ide_drive_t *drive) | 213 | static int svwks_config_drive_xfer_rate (ide_drive_t *drive) |
@@ -389,8 +387,6 @@ static u8 __devinit ata66_svwks(ide_hwif_t *hwif) | |||
389 | 387 | ||
390 | static void __devinit init_hwif_svwks (ide_hwif_t *hwif) | 388 | static void __devinit init_hwif_svwks (ide_hwif_t *hwif) |
391 | { | 389 | { |
392 | u8 dma_stat = 0; | ||
393 | |||
394 | if (!hwif->irq) | 390 | if (!hwif->irq) |
395 | hwif->irq = hwif->channel ? 15 : 14; | 391 | hwif->irq = hwif->channel ? 15 : 14; |
396 | 392 | ||
@@ -407,11 +403,11 @@ static void __devinit init_hwif_svwks (ide_hwif_t *hwif) | |||
407 | 403 | ||
408 | hwif->autodma = 0; | 404 | hwif->autodma = 0; |
409 | 405 | ||
410 | if (!hwif->dma_base) { | 406 | hwif->drives[0].autotune = 1; |
411 | hwif->drives[0].autotune = 1; | 407 | hwif->drives[1].autotune = 1; |
412 | hwif->drives[1].autotune = 1; | 408 | |
409 | if (!hwif->dma_base) | ||
413 | return; | 410 | return; |
414 | } | ||
415 | 411 | ||
416 | hwif->ide_dma_check = &svwks_config_drive_xfer_rate; | 412 | hwif->ide_dma_check = &svwks_config_drive_xfer_rate; |
417 | if (hwif->pci_dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) { | 413 | if (hwif->pci_dev->device != PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) { |
@@ -421,11 +417,7 @@ static void __devinit init_hwif_svwks (ide_hwif_t *hwif) | |||
421 | if (!noautodma) | 417 | if (!noautodma) |
422 | hwif->autodma = 1; | 418 | hwif->autodma = 1; |
423 | 419 | ||
424 | dma_stat = inb(hwif->dma_status); | 420 | hwif->drives[0].autodma = hwif->drives[1].autodma = 1; |
425 | hwif->drives[0].autodma = (dma_stat & 0x20); | ||
426 | hwif->drives[1].autodma = (dma_stat & 0x40); | ||
427 | hwif->drives[0].autotune = (!(dma_stat & 0x20)); | ||
428 | hwif->drives[1].autotune = (!(dma_stat & 0x40)); | ||
429 | } | 421 | } |
430 | 422 | ||
431 | static int __devinit init_setup_svwks (struct pci_dev *dev, ide_pci_device_t *d) | 423 | static int __devinit init_setup_svwks (struct pci_dev *dev, ide_pci_device_t *d) |
@@ -441,9 +433,12 @@ static int __devinit init_setup_csb6 (struct pci_dev *dev, ide_pci_device_t *d) | |||
441 | d->bootable = ON_BOARD; | 433 | d->bootable = ON_BOARD; |
442 | } | 434 | } |
443 | 435 | ||
444 | d->channels = ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE || | 436 | if ((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE || |
445 | dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2) && | 437 | dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2) && |
446 | (!(PCI_FUNC(dev->devfn) & 1))) ? 1 : 2; | 438 | (!(PCI_FUNC(dev->devfn) & 1))) |
439 | d->host_flags |= IDE_HFLAG_SINGLE; | ||
440 | else | ||
441 | d->host_flags &= ~IDE_HFLAG_SINGLE; | ||
447 | 442 | ||
448 | return ide_setup_pci_device(dev, d); | 443 | return ide_setup_pci_device(dev, d); |
449 | } | 444 | } |
@@ -454,41 +449,43 @@ static ide_pci_device_t serverworks_chipsets[] __devinitdata = { | |||
454 | .init_setup = init_setup_svwks, | 449 | .init_setup = init_setup_svwks, |
455 | .init_chipset = init_chipset_svwks, | 450 | .init_chipset = init_chipset_svwks, |
456 | .init_hwif = init_hwif_svwks, | 451 | .init_hwif = init_hwif_svwks, |
457 | .channels = 2, | ||
458 | .autodma = AUTODMA, | 452 | .autodma = AUTODMA, |
459 | .bootable = ON_BOARD, | 453 | .bootable = ON_BOARD, |
454 | .pio_mask = ATA_PIO4, | ||
460 | },{ /* 1 */ | 455 | },{ /* 1 */ |
461 | .name = "SvrWks CSB5", | 456 | .name = "SvrWks CSB5", |
462 | .init_setup = init_setup_svwks, | 457 | .init_setup = init_setup_svwks, |
463 | .init_chipset = init_chipset_svwks, | 458 | .init_chipset = init_chipset_svwks, |
464 | .init_hwif = init_hwif_svwks, | 459 | .init_hwif = init_hwif_svwks, |
465 | .channels = 2, | ||
466 | .autodma = AUTODMA, | 460 | .autodma = AUTODMA, |
467 | .bootable = ON_BOARD, | 461 | .bootable = ON_BOARD, |
462 | .pio_mask = ATA_PIO4, | ||
468 | },{ /* 2 */ | 463 | },{ /* 2 */ |
469 | .name = "SvrWks CSB6", | 464 | .name = "SvrWks CSB6", |
470 | .init_setup = init_setup_csb6, | 465 | .init_setup = init_setup_csb6, |
471 | .init_chipset = init_chipset_svwks, | 466 | .init_chipset = init_chipset_svwks, |
472 | .init_hwif = init_hwif_svwks, | 467 | .init_hwif = init_hwif_svwks, |
473 | .channels = 2, | ||
474 | .autodma = AUTODMA, | 468 | .autodma = AUTODMA, |
475 | .bootable = ON_BOARD, | 469 | .bootable = ON_BOARD, |
470 | .pio_mask = ATA_PIO4, | ||
476 | },{ /* 3 */ | 471 | },{ /* 3 */ |
477 | .name = "SvrWks CSB6", | 472 | .name = "SvrWks CSB6", |
478 | .init_setup = init_setup_csb6, | 473 | .init_setup = init_setup_csb6, |
479 | .init_chipset = init_chipset_svwks, | 474 | .init_chipset = init_chipset_svwks, |
480 | .init_hwif = init_hwif_svwks, | 475 | .init_hwif = init_hwif_svwks, |
481 | .channels = 1, /* 2 */ | ||
482 | .autodma = AUTODMA, | 476 | .autodma = AUTODMA, |
483 | .bootable = ON_BOARD, | 477 | .bootable = ON_BOARD, |
478 | .host_flags = IDE_HFLAG_SINGLE, | ||
479 | .pio_mask = ATA_PIO4, | ||
484 | },{ /* 4 */ | 480 | },{ /* 4 */ |
485 | .name = "SvrWks HT1000", | 481 | .name = "SvrWks HT1000", |
486 | .init_setup = init_setup_svwks, | 482 | .init_setup = init_setup_svwks, |
487 | .init_chipset = init_chipset_svwks, | 483 | .init_chipset = init_chipset_svwks, |
488 | .init_hwif = init_hwif_svwks, | 484 | .init_hwif = init_hwif_svwks, |
489 | .channels = 1, /* 2 */ | ||
490 | .autodma = AUTODMA, | 485 | .autodma = AUTODMA, |
491 | .bootable = ON_BOARD, | 486 | .bootable = ON_BOARD, |
487 | .host_flags = IDE_HFLAG_SINGLE, | ||
488 | .pio_mask = ATA_PIO4, | ||
492 | } | 489 | } |
493 | }; | 490 | }; |
494 | 491 | ||
diff --git a/drivers/ide/pci/sgiioc4.c b/drivers/ide/pci/sgiioc4.c index d396b2929ed8..57145767c3df 100644 --- a/drivers/ide/pci/sgiioc4.c +++ b/drivers/ide/pci/sgiioc4.c | |||
@@ -586,6 +586,7 @@ ide_init_sgiioc4(ide_hwif_t * hwif) | |||
586 | hwif->ultra_mask = 0x0; /* Disable Ultra DMA */ | 586 | hwif->ultra_mask = 0x0; /* Disable Ultra DMA */ |
587 | hwif->mwdma_mask = 0x2; /* Multimode-2 DMA */ | 587 | hwif->mwdma_mask = 0x2; /* Multimode-2 DMA */ |
588 | hwif->swdma_mask = 0x2; | 588 | hwif->swdma_mask = 0x2; |
589 | hwif->pio_mask = 0x00; | ||
589 | hwif->tuneproc = NULL; /* Sets timing for PIO mode */ | 590 | hwif->tuneproc = NULL; /* Sets timing for PIO mode */ |
590 | hwif->speedproc = NULL; /* Sets timing for DMA &/or PIO modes */ | 591 | hwif->speedproc = NULL; /* Sets timing for DMA &/or PIO modes */ |
591 | hwif->selectproc = NULL;/* Use the default routine to select drive */ | 592 | hwif->selectproc = NULL;/* Use the default routine to select drive */ |
@@ -724,10 +725,10 @@ static ide_pci_device_t sgiioc4_chipset __devinitdata = { | |||
724 | .name = "SGIIOC4", | 725 | .name = "SGIIOC4", |
725 | .init_hwif = ide_init_sgiioc4, | 726 | .init_hwif = ide_init_sgiioc4, |
726 | .init_dma = ide_dma_sgiioc4, | 727 | .init_dma = ide_dma_sgiioc4, |
727 | .channels = 1, | ||
728 | .autodma = AUTODMA, | 728 | .autodma = AUTODMA, |
729 | /* SGI IOC4 doesn't have enablebits. */ | 729 | /* SGI IOC4 doesn't have enablebits. */ |
730 | .bootable = ON_BOARD, | 730 | .bootable = ON_BOARD, |
731 | .host_flags = IDE_HFLAG_SINGLE, | ||
731 | }; | 732 | }; |
732 | 733 | ||
733 | int | 734 | int |
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c index 1c3e35487893..50f6d172ef77 100644 --- a/drivers/ide/pci/siimage.c +++ b/drivers/ide/pci/siimage.c | |||
@@ -1,9 +1,10 @@ | |||
1 | /* | 1 | /* |
2 | * linux/drivers/ide/pci/siimage.c Version 1.12 Mar 10 2007 | 2 | * linux/drivers/ide/pci/siimage.c Version 1.15 Jun 29 2007 |
3 | * | 3 | * |
4 | * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org> | 4 | * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org> |
5 | * Copyright (C) 2003 Red Hat <alan@redhat.com> | 5 | * Copyright (C) 2003 Red Hat <alan@redhat.com> |
6 | * Copyright (C) 2007 MontaVista Software, Inc. | 6 | * Copyright (C) 2007 MontaVista Software, Inc. |
7 | * Copyright (C) 2007 Bartlomiej Zolnierkiewicz | ||
7 | * | 8 | * |
8 | * May be copied or modified under the terms of the GNU General Public License | 9 | * May be copied or modified under the terms of the GNU General Public License |
9 | * | 10 | * |
@@ -31,6 +32,10 @@ | |||
31 | * unplugging/replugging the virtual CD interface when the DRAC is reset. | 32 | * unplugging/replugging the virtual CD interface when the DRAC is reset. |
32 | * This often causes drivers/ide/siimage to panic but is ok with the rather | 33 | * This often causes drivers/ide/siimage to panic but is ok with the rather |
33 | * smarter code in libata. | 34 | * smarter code in libata. |
35 | * | ||
36 | * TODO: | ||
37 | * - IORDY fixes | ||
38 | * - VDMA support | ||
34 | */ | 39 | */ |
35 | 40 | ||
36 | #include <linux/types.h> | 41 | #include <linux/types.h> |
@@ -160,82 +165,45 @@ out: | |||
160 | } | 165 | } |
161 | 166 | ||
162 | /** | 167 | /** |
163 | * siimage_taskfile_timing - turn timing data to a mode | 168 | * sil_tune_pio - tune a drive |
164 | * @hwif: interface to query | ||
165 | * | ||
166 | * Read the timing data for the interface and return the | ||
167 | * mode that is being used. | ||
168 | */ | ||
169 | |||
170 | static byte siimage_taskfile_timing (ide_hwif_t *hwif) | ||
171 | { | ||
172 | u16 timing = 0x328a; | ||
173 | unsigned long addr = siimage_selreg(hwif, 2); | ||
174 | |||
175 | if (hwif->mmio) | ||
176 | timing = hwif->INW(addr); | ||
177 | else | ||
178 | pci_read_config_word(hwif->pci_dev, addr, &timing); | ||
179 | |||
180 | switch (timing) { | ||
181 | case 0x10c1: return 4; | ||
182 | case 0x10c3: return 3; | ||
183 | case 0x1104: | ||
184 | case 0x1281: return 2; | ||
185 | case 0x2283: return 1; | ||
186 | case 0x328a: | ||
187 | default: return 0; | ||
188 | } | ||
189 | } | ||
190 | |||
191 | /** | ||
192 | * simmage_tuneproc - tune a drive | ||
193 | * @drive: drive to tune | 169 | * @drive: drive to tune |
194 | * @mode_wanted: the target operating mode | 170 | * @pio: the desired PIO mode |
195 | * | 171 | * |
196 | * Load the timing settings for this device mode into the | 172 | * Load the timing settings for this device mode into the |
197 | * controller. If we are in PIO mode 3 or 4 turn on IORDY | 173 | * controller. If we are in PIO mode 3 or 4 turn on IORDY |
198 | * monitoring (bit 9). The TF timing is bits 31:16 | 174 | * monitoring (bit 9). The TF timing is bits 31:16 |
199 | */ | 175 | */ |
200 | 176 | ||
201 | static void siimage_tuneproc (ide_drive_t *drive, byte mode_wanted) | 177 | static void sil_tune_pio(ide_drive_t *drive, u8 pio) |
202 | { | 178 | { |
179 | const u16 tf_speed[] = { 0x328a, 0x2283, 0x1281, 0x10c3, 0x10c1 }; | ||
180 | const u16 data_speed[] = { 0x328a, 0x2283, 0x1104, 0x10c3, 0x10c1 }; | ||
181 | |||
203 | ide_hwif_t *hwif = HWIF(drive); | 182 | ide_hwif_t *hwif = HWIF(drive); |
183 | ide_drive_t *pair = &hwif->drives[drive->dn ^ 1]; | ||
204 | u32 speedt = 0; | 184 | u32 speedt = 0; |
205 | u16 speedp = 0; | 185 | u16 speedp = 0; |
206 | unsigned long addr = siimage_seldev(drive, 0x04); | 186 | unsigned long addr = siimage_seldev(drive, 0x04); |
207 | unsigned long tfaddr = siimage_selreg(hwif, 0x02); | 187 | unsigned long tfaddr = siimage_selreg(hwif, 0x02); |
208 | 188 | u8 tf_pio = pio; | |
209 | /* cheat for now and use the docs */ | 189 | |
210 | switch (mode_wanted) { | 190 | /* trim *taskfile* PIO to the slowest of the master/slave */ |
211 | case 4: | 191 | if (pair->present) { |
212 | speedp = 0x10c1; | 192 | u8 pair_pio = ide_get_best_pio_mode(pair, 255, 4); |
213 | speedt = 0x10c1; | 193 | |
214 | break; | 194 | if (pair_pio < tf_pio) |
215 | case 3: | 195 | tf_pio = pair_pio; |
216 | speedp = 0x10c3; | ||
217 | speedt = 0x10c3; | ||
218 | break; | ||
219 | case 2: | ||
220 | speedp = 0x1104; | ||
221 | speedt = 0x1281; | ||
222 | break; | ||
223 | case 1: | ||
224 | speedp = 0x2283; | ||
225 | speedt = 0x2283; | ||
226 | break; | ||
227 | case 0: | ||
228 | default: | ||
229 | speedp = 0x328a; | ||
230 | speedt = 0x328a; | ||
231 | break; | ||
232 | } | 196 | } |
233 | 197 | ||
198 | /* cheat for now and use the docs */ | ||
199 | speedp = data_speed[pio]; | ||
200 | speedt = tf_speed[tf_pio]; | ||
201 | |||
234 | if (hwif->mmio) { | 202 | if (hwif->mmio) { |
235 | hwif->OUTW(speedp, addr); | 203 | hwif->OUTW(speedp, addr); |
236 | hwif->OUTW(speedt, tfaddr); | 204 | hwif->OUTW(speedt, tfaddr); |
237 | /* Now set up IORDY */ | 205 | /* Now set up IORDY */ |
238 | if(mode_wanted == 3 || mode_wanted == 4) | 206 | if (pio > 2) |
239 | hwif->OUTW(hwif->INW(tfaddr-2)|0x200, tfaddr-2); | 207 | hwif->OUTW(hwif->INW(tfaddr-2)|0x200, tfaddr-2); |
240 | else | 208 | else |
241 | hwif->OUTW(hwif->INW(tfaddr-2)&~0x200, tfaddr-2); | 209 | hwif->OUTW(hwif->INW(tfaddr-2)&~0x200, tfaddr-2); |
@@ -245,42 +213,17 @@ static void siimage_tuneproc (ide_drive_t *drive, byte mode_wanted) | |||
245 | pci_read_config_word(hwif->pci_dev, tfaddr-2, &speedp); | 213 | pci_read_config_word(hwif->pci_dev, tfaddr-2, &speedp); |
246 | speedp &= ~0x200; | 214 | speedp &= ~0x200; |
247 | /* Set IORDY for mode 3 or 4 */ | 215 | /* Set IORDY for mode 3 or 4 */ |
248 | if(mode_wanted == 3 || mode_wanted == 4) | 216 | if (pio > 2) |
249 | speedp |= 0x200; | 217 | speedp |= 0x200; |
250 | pci_write_config_word(hwif->pci_dev, tfaddr-2, speedp); | 218 | pci_write_config_word(hwif->pci_dev, tfaddr-2, speedp); |
251 | } | 219 | } |
252 | } | 220 | } |
253 | 221 | ||
254 | /** | 222 | static void sil_tuneproc(ide_drive_t *drive, u8 pio) |
255 | * config_siimage_chipset_for_pio - set drive timings | ||
256 | * @drive: drive to tune | ||
257 | * @speed we want | ||
258 | * | ||
259 | * Compute the best pio mode we can for a given device. Also honour | ||
260 | * the timings for the driver when dealing with mixed devices. Some | ||
261 | * of this is ugly but its all wrapped up here | ||
262 | * | ||
263 | * The SI680 can also do VDMA - we need to start using that | ||
264 | * | ||
265 | * FIXME: we use the BIOS channel timings to avoid driving the task | ||
266 | * files too fast at the disk. We need to compute the master/slave | ||
267 | * drive PIO mode properly so that we can up the speed on a hotplug | ||
268 | * system. | ||
269 | */ | ||
270 | |||
271 | static void config_siimage_chipset_for_pio (ide_drive_t *drive, byte set_speed) | ||
272 | { | 223 | { |
273 | u8 channel_timings = siimage_taskfile_timing(HWIF(drive)); | 224 | pio = ide_get_best_pio_mode(drive, pio, 4); |
274 | u8 speed = 0, set_pio = ide_get_best_pio_mode(drive, 4, 5, NULL); | 225 | sil_tune_pio(drive, pio); |
275 | 226 | (void)ide_config_drive_speed(drive, XFER_PIO_0 + pio); | |
276 | /* WARNING PIO timing mess is going to happen b/w devices, argh */ | ||
277 | if ((channel_timings != set_pio) && (set_pio > channel_timings)) | ||
278 | set_pio = channel_timings; | ||
279 | |||
280 | siimage_tuneproc(drive, set_pio); | ||
281 | speed = XFER_PIO_0 + set_pio; | ||
282 | if (set_speed) | ||
283 | (void) ide_config_drive_speed(drive, speed); | ||
284 | } | 227 | } |
285 | 228 | ||
286 | /** | 229 | /** |
@@ -335,7 +278,7 @@ static int siimage_tune_chipset (ide_drive_t *drive, byte xferspeed) | |||
335 | case XFER_PIO_2: | 278 | case XFER_PIO_2: |
336 | case XFER_PIO_1: | 279 | case XFER_PIO_1: |
337 | case XFER_PIO_0: | 280 | case XFER_PIO_0: |
338 | siimage_tuneproc(drive, (speed - XFER_PIO_0)); | 281 | sil_tune_pio(drive, speed - XFER_PIO_0); |
339 | mode |= ((unit) ? 0x10 : 0x01); | 282 | mode |= ((unit) ? 0x10 : 0x01); |
340 | break; | 283 | break; |
341 | case XFER_MW_DMA_2: | 284 | case XFER_MW_DMA_2: |
@@ -343,7 +286,6 @@ static int siimage_tune_chipset (ide_drive_t *drive, byte xferspeed) | |||
343 | case XFER_MW_DMA_0: | 286 | case XFER_MW_DMA_0: |
344 | multi = dma[speed - XFER_MW_DMA_0]; | 287 | multi = dma[speed - XFER_MW_DMA_0]; |
345 | mode |= ((unit) ? 0x20 : 0x02); | 288 | mode |= ((unit) ? 0x20 : 0x02); |
346 | config_siimage_chipset_for_pio(drive, 0); | ||
347 | break; | 289 | break; |
348 | case XFER_UDMA_6: | 290 | case XFER_UDMA_6: |
349 | case XFER_UDMA_5: | 291 | case XFER_UDMA_5: |
@@ -356,7 +298,6 @@ static int siimage_tune_chipset (ide_drive_t *drive, byte xferspeed) | |||
356 | ultra |= ((scsc) ? (ultra6[speed - XFER_UDMA_0]) : | 298 | ultra |= ((scsc) ? (ultra6[speed - XFER_UDMA_0]) : |
357 | (ultra5[speed - XFER_UDMA_0])); | 299 | (ultra5[speed - XFER_UDMA_0])); |
358 | mode |= ((unit) ? 0x30 : 0x03); | 300 | mode |= ((unit) ? 0x30 : 0x03); |
359 | config_siimage_chipset_for_pio(drive, 0); | ||
360 | break; | 301 | break; |
361 | default: | 302 | default: |
362 | return 1; | 303 | return 1; |
@@ -390,7 +331,7 @@ static int siimage_config_drive_for_dma (ide_drive_t *drive) | |||
390 | return 0; | 331 | return 0; |
391 | 332 | ||
392 | if (ide_use_fast_pio(drive)) | 333 | if (ide_use_fast_pio(drive)) |
393 | config_siimage_chipset_for_pio(drive, 1); | 334 | sil_tuneproc(drive, 255); |
394 | 335 | ||
395 | return -1; | 336 | return -1; |
396 | } | 337 | } |
@@ -961,7 +902,7 @@ static void __devinit init_hwif_siimage(ide_hwif_t *hwif) | |||
961 | 902 | ||
962 | hwif->resetproc = &siimage_reset; | 903 | hwif->resetproc = &siimage_reset; |
963 | hwif->speedproc = &siimage_tune_chipset; | 904 | hwif->speedproc = &siimage_tune_chipset; |
964 | hwif->tuneproc = &siimage_tuneproc; | 905 | hwif->tuneproc = &sil_tuneproc; |
965 | hwif->reset_poll = &siimage_reset_poll; | 906 | hwif->reset_poll = &siimage_reset_poll; |
966 | hwif->pre_reset = &siimage_pre_reset; | 907 | hwif->pre_reset = &siimage_pre_reset; |
967 | hwif->udma_filter = &sil_udma_filter; | 908 | hwif->udma_filter = &sil_udma_filter; |
@@ -976,11 +917,11 @@ static void __devinit init_hwif_siimage(ide_hwif_t *hwif) | |||
976 | first = 0; | 917 | first = 0; |
977 | } | 918 | } |
978 | } | 919 | } |
979 | if (!hwif->dma_base) { | 920 | |
980 | hwif->drives[0].autotune = 1; | 921 | hwif->drives[0].autotune = hwif->drives[1].autotune = 1; |
981 | hwif->drives[1].autotune = 1; | 922 | |
923 | if (hwif->dma_base == 0) | ||
982 | return; | 924 | return; |
983 | } | ||
984 | 925 | ||
985 | hwif->ultra_mask = 0x7f; | 926 | hwif->ultra_mask = 0x7f; |
986 | hwif->mwdma_mask = 0x07; | 927 | hwif->mwdma_mask = 0x07; |
@@ -1016,9 +957,9 @@ static void __devinit init_hwif_siimage(ide_hwif_t *hwif) | |||
1016 | .init_iops = init_iops_siimage, \ | 957 | .init_iops = init_iops_siimage, \ |
1017 | .init_hwif = init_hwif_siimage, \ | 958 | .init_hwif = init_hwif_siimage, \ |
1018 | .fixup = siimage_fixup, \ | 959 | .fixup = siimage_fixup, \ |
1019 | .channels = 2, \ | ||
1020 | .autodma = AUTODMA, \ | 960 | .autodma = AUTODMA, \ |
1021 | .bootable = ON_BOARD, \ | 961 | .bootable = ON_BOARD, \ |
962 | .pio_mask = ATA_PIO4, \ | ||
1022 | } | 963 | } |
1023 | 964 | ||
1024 | static ide_pci_device_t siimage_chipsets[] __devinitdata = { | 965 | static ide_pci_device_t siimage_chipsets[] __devinitdata = { |
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c index 756a9b6eb462..63fbb79e8178 100644 --- a/drivers/ide/pci/sis5513.c +++ b/drivers/ide/pci/sis5513.c | |||
@@ -521,7 +521,7 @@ static void config_art_rwp_pio (ide_drive_t *drive, u8 pio) | |||
521 | 521 | ||
522 | static int sis5513_tune_drive(ide_drive_t *drive, u8 pio) | 522 | static int sis5513_tune_drive(ide_drive_t *drive, u8 pio) |
523 | { | 523 | { |
524 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | 524 | pio = ide_get_best_pio_mode(drive, pio, 4); |
525 | config_art_rwp_pio(drive, pio); | 525 | config_art_rwp_pio(drive, pio); |
526 | return ide_config_drive_speed(drive, XFER_PIO_0 + pio); | 526 | return ide_config_drive_speed(drive, XFER_PIO_0 + pio); |
527 | } | 527 | } |
@@ -878,10 +878,10 @@ static ide_pci_device_t sis5513_chipset __devinitdata = { | |||
878 | .name = "SIS5513", | 878 | .name = "SIS5513", |
879 | .init_chipset = init_chipset_sis5513, | 879 | .init_chipset = init_chipset_sis5513, |
880 | .init_hwif = init_hwif_sis5513, | 880 | .init_hwif = init_hwif_sis5513, |
881 | .channels = 2, | ||
882 | .autodma = NOAUTODMA, | 881 | .autodma = NOAUTODMA, |
883 | .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, | 882 | .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, |
884 | .bootable = ON_BOARD, | 883 | .bootable = ON_BOARD, |
884 | .pio_mask = ATA_PIO4, | ||
885 | }; | 885 | }; |
886 | 886 | ||
887 | static int __devinit sis5513_init_one(struct pci_dev *dev, const struct pci_device_id *id) | 887 | static int __devinit sis5513_init_one(struct pci_dev *dev, const struct pci_device_id *id) |
diff --git a/drivers/ide/pci/sl82c105.c b/drivers/ide/pci/sl82c105.c index a7323d278c49..0947cab00595 100644 --- a/drivers/ide/pci/sl82c105.c +++ b/drivers/ide/pci/sl82c105.c | |||
@@ -52,12 +52,13 @@ | |||
52 | * Convert a PIO mode and cycle time to the required on/off times | 52 | * Convert a PIO mode and cycle time to the required on/off times |
53 | * for the interface. This has protection against runaway timings. | 53 | * for the interface. This has protection against runaway timings. |
54 | */ | 54 | */ |
55 | static unsigned int get_pio_timings(ide_pio_data_t *p) | 55 | static unsigned int get_pio_timings(ide_drive_t *drive, u8 pio) |
56 | { | 56 | { |
57 | unsigned int cmd_on, cmd_off; | 57 | unsigned int cmd_on, cmd_off; |
58 | u8 iordy = 0; | ||
58 | 59 | ||
59 | cmd_on = (ide_pio_timings[p->pio_mode].active_time + 29) / 30; | 60 | cmd_on = (ide_pio_timings[pio].active_time + 29) / 30; |
60 | cmd_off = (p->cycle_time - 30 * cmd_on + 29) / 30; | 61 | cmd_off = (ide_pio_cycle_time(drive, pio) - 30 * cmd_on + 29) / 30; |
61 | 62 | ||
62 | if (cmd_on == 0) | 63 | if (cmd_on == 0) |
63 | cmd_on = 1; | 64 | cmd_on = 1; |
@@ -65,7 +66,10 @@ static unsigned int get_pio_timings(ide_pio_data_t *p) | |||
65 | if (cmd_off == 0) | 66 | if (cmd_off == 0) |
66 | cmd_off = 1; | 67 | cmd_off = 1; |
67 | 68 | ||
68 | return (cmd_on - 1) << 8 | (cmd_off - 1) | (p->use_iordy ? 0x40 : 0x00); | 69 | if (pio > 2 || ide_dev_has_iordy(drive->id)) |
70 | iordy = 0x40; | ||
71 | |||
72 | return (cmd_on - 1) << 8 | (cmd_off - 1) | iordy; | ||
69 | } | 73 | } |
70 | 74 | ||
71 | /* | 75 | /* |
@@ -75,14 +79,13 @@ static u8 sl82c105_tune_pio(ide_drive_t *drive, u8 pio) | |||
75 | { | 79 | { |
76 | struct pci_dev *dev = HWIF(drive)->pci_dev; | 80 | struct pci_dev *dev = HWIF(drive)->pci_dev; |
77 | int reg = 0x44 + drive->dn * 4; | 81 | int reg = 0x44 + drive->dn * 4; |
78 | ide_pio_data_t p; | ||
79 | u16 drv_ctrl; | 82 | u16 drv_ctrl; |
80 | 83 | ||
81 | DBG(("sl82c105_tune_pio(drive:%s, pio:%u)\n", drive->name, pio)); | 84 | DBG(("sl82c105_tune_pio(drive:%s, pio:%u)\n", drive->name, pio)); |
82 | 85 | ||
83 | pio = ide_get_best_pio_mode(drive, pio, 5, &p); | 86 | pio = ide_get_best_pio_mode(drive, pio, 5); |
84 | 87 | ||
85 | drv_ctrl = get_pio_timings(&p); | 88 | drv_ctrl = get_pio_timings(drive, pio); |
86 | 89 | ||
87 | /* | 90 | /* |
88 | * Store the PIO timings so that we can restore them | 91 | * Store the PIO timings so that we can restore them |
@@ -101,7 +104,8 @@ static u8 sl82c105_tune_pio(ide_drive_t *drive, u8 pio) | |||
101 | } | 104 | } |
102 | 105 | ||
103 | printk(KERN_DEBUG "%s: selected %s (%dns) (%04X)\n", drive->name, | 106 | printk(KERN_DEBUG "%s: selected %s (%dns) (%04X)\n", drive->name, |
104 | ide_xfer_verbose(pio + XFER_PIO_0), p.cycle_time, drv_ctrl); | 107 | ide_xfer_verbose(pio + XFER_PIO_0), |
108 | ide_pio_cycle_time(drive, pio), drv_ctrl); | ||
105 | 109 | ||
106 | return pio; | 110 | return pio; |
107 | } | 111 | } |
@@ -449,10 +453,10 @@ static ide_pci_device_t sl82c105_chipset __devinitdata = { | |||
449 | .name = "W82C105", | 453 | .name = "W82C105", |
450 | .init_chipset = init_chipset_sl82c105, | 454 | .init_chipset = init_chipset_sl82c105, |
451 | .init_hwif = init_hwif_sl82c105, | 455 | .init_hwif = init_hwif_sl82c105, |
452 | .channels = 2, | ||
453 | .autodma = NOAUTODMA, | 456 | .autodma = NOAUTODMA, |
454 | .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}}, | 457 | .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}}, |
455 | .bootable = ON_BOARD, | 458 | .bootable = ON_BOARD, |
459 | .pio_mask = ATA_PIO5, | ||
456 | }; | 460 | }; |
457 | 461 | ||
458 | static int __devinit sl82c105_init_one(struct pci_dev *dev, const struct pci_device_id *id) | 462 | static int __devinit sl82c105_init_one(struct pci_dev *dev, const struct pci_device_id *id) |
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/pci/slc90e66.c index 575dbbd8b482..8e655f2db5cb 100644 --- a/drivers/ide/pci/slc90e66.c +++ b/drivers/ide/pci/slc90e66.c | |||
@@ -103,7 +103,7 @@ static void slc90e66_tune_pio (ide_drive_t *drive, u8 pio) | |||
103 | 103 | ||
104 | static void slc90e66_tune_drive (ide_drive_t *drive, u8 pio) | 104 | static void slc90e66_tune_drive (ide_drive_t *drive, u8 pio) |
105 | { | 105 | { |
106 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | 106 | pio = ide_get_best_pio_mode(drive, pio, 4); |
107 | slc90e66_tune_pio(drive, pio); | 107 | slc90e66_tune_pio(drive, pio); |
108 | (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio); | 108 | (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio); |
109 | } | 109 | } |
@@ -214,10 +214,10 @@ static void __devinit init_hwif_slc90e66 (ide_hwif_t *hwif) | |||
214 | static ide_pci_device_t slc90e66_chipset __devinitdata = { | 214 | static ide_pci_device_t slc90e66_chipset __devinitdata = { |
215 | .name = "SLC90E66", | 215 | .name = "SLC90E66", |
216 | .init_hwif = init_hwif_slc90e66, | 216 | .init_hwif = init_hwif_slc90e66, |
217 | .channels = 2, | ||
218 | .autodma = AUTODMA, | 217 | .autodma = AUTODMA, |
219 | .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, | 218 | .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, |
220 | .bootable = ON_BOARD, | 219 | .bootable = ON_BOARD, |
220 | .pio_mask = ATA_PIO4, | ||
221 | }; | 221 | }; |
222 | 222 | ||
223 | static int __devinit slc90e66_init_one(struct pci_dev *dev, const struct pci_device_id *id) | 223 | static int __devinit slc90e66_init_one(struct pci_dev *dev, const struct pci_device_id *id) |
diff --git a/drivers/ide/pci/tc86c001.c b/drivers/ide/pci/tc86c001.c index 8de1f8e22494..ec79bacc30c2 100644 --- a/drivers/ide/pci/tc86c001.c +++ b/drivers/ide/pci/tc86c001.c | |||
@@ -47,7 +47,7 @@ static int tc86c001_tune_chipset(ide_drive_t *drive, u8 speed) | |||
47 | 47 | ||
48 | static void tc86c001_tune_drive(ide_drive_t *drive, u8 pio) | 48 | static void tc86c001_tune_drive(ide_drive_t *drive, u8 pio) |
49 | { | 49 | { |
50 | pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | 50 | pio = ide_get_best_pio_mode(drive, pio, 4); |
51 | (void) tc86c001_tune_chipset(drive, XFER_PIO_0 + pio); | 51 | (void) tc86c001_tune_chipset(drive, XFER_PIO_0 + pio); |
52 | } | 52 | } |
53 | 53 | ||
@@ -248,9 +248,10 @@ static ide_pci_device_t tc86c001_chipset __devinitdata = { | |||
248 | .name = "TC86C001", | 248 | .name = "TC86C001", |
249 | .init_chipset = init_chipset_tc86c001, | 249 | .init_chipset = init_chipset_tc86c001, |
250 | .init_hwif = init_hwif_tc86c001, | 250 | .init_hwif = init_hwif_tc86c001, |
251 | .channels = 1, | ||
252 | .autodma = AUTODMA, | 251 | .autodma = AUTODMA, |
253 | .bootable = OFF_BOARD | 252 | .bootable = OFF_BOARD, |
253 | .host_flags = IDE_HFLAG_SINGLE, | ||
254 | .pio_mask = ATA_PIO4, | ||
254 | }; | 255 | }; |
255 | 256 | ||
256 | static int __devinit tc86c001_init_one(struct pci_dev *dev, | 257 | static int __devinit tc86c001_init_one(struct pci_dev *dev, |
diff --git a/drivers/ide/pci/triflex.c b/drivers/ide/pci/triflex.c index 35e8c612638f..024bbfae0429 100644 --- a/drivers/ide/pci/triflex.c +++ b/drivers/ide/pci/triflex.c | |||
@@ -96,7 +96,7 @@ static int triflex_tune_chipset(ide_drive_t *drive, u8 xferspeed) | |||
96 | 96 | ||
97 | static void triflex_tune_drive(ide_drive_t *drive, u8 pio) | 97 | static void triflex_tune_drive(ide_drive_t *drive, u8 pio) |
98 | { | 98 | { |
99 | int use_pio = ide_get_best_pio_mode(drive, pio, 4, NULL); | 99 | int use_pio = ide_get_best_pio_mode(drive, pio, 4); |
100 | (void) triflex_tune_chipset(drive, (XFER_PIO_0 + use_pio)); | 100 | (void) triflex_tune_chipset(drive, (XFER_PIO_0 + use_pio)); |
101 | } | 101 | } |
102 | 102 | ||
@@ -129,10 +129,10 @@ static void __devinit init_hwif_triflex(ide_hwif_t *hwif) | |||
129 | static ide_pci_device_t triflex_device __devinitdata = { | 129 | static ide_pci_device_t triflex_device __devinitdata = { |
130 | .name = "TRIFLEX", | 130 | .name = "TRIFLEX", |
131 | .init_hwif = init_hwif_triflex, | 131 | .init_hwif = init_hwif_triflex, |
132 | .channels = 2, | ||
133 | .autodma = AUTODMA, | 132 | .autodma = AUTODMA, |
134 | .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}}, | 133 | .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}}, |
135 | .bootable = ON_BOARD, | 134 | .bootable = ON_BOARD, |
135 | .pio_mask = ATA_PIO4, | ||
136 | }; | 136 | }; |
137 | 137 | ||
138 | static int __devinit triflex_init_one(struct pci_dev *dev, | 138 | static int __devinit triflex_init_one(struct pci_dev *dev, |
diff --git a/drivers/ide/pci/trm290.c b/drivers/ide/pci/trm290.c index cbb1b11119a5..dc4f4e298e00 100644 --- a/drivers/ide/pci/trm290.c +++ b/drivers/ide/pci/trm290.c | |||
@@ -327,7 +327,6 @@ static void __devinit init_hwif_trm290(ide_hwif_t *hwif) | |||
327 | static ide_pci_device_t trm290_chipset __devinitdata = { | 327 | static ide_pci_device_t trm290_chipset __devinitdata = { |
328 | .name = "TRM290", | 328 | .name = "TRM290", |
329 | .init_hwif = init_hwif_trm290, | 329 | .init_hwif = init_hwif_trm290, |
330 | .channels = 2, | ||
331 | .autodma = NOAUTODMA, | 330 | .autodma = NOAUTODMA, |
332 | .bootable = ON_BOARD, | 331 | .bootable = ON_BOARD, |
333 | }; | 332 | }; |
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c index 27e92fb9f95e..581316f9581d 100644 --- a/drivers/ide/pci/via82cxxx.c +++ b/drivers/ide/pci/via82cxxx.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * | 2 | * |
3 | * Version 3.45 | 3 | * Version 3.46 |
4 | * | 4 | * |
5 | * VIA IDE driver for Linux. Supported southbridges: | 5 | * VIA IDE driver for Linux. Supported southbridges: |
6 | * | 6 | * |
@@ -203,10 +203,8 @@ static int via_set_drive(ide_drive_t *drive, u8 speed) | |||
203 | 203 | ||
204 | static void via82cxxx_tune_drive(ide_drive_t *drive, u8 pio) | 204 | static void via82cxxx_tune_drive(ide_drive_t *drive, u8 pio) |
205 | { | 205 | { |
206 | if (pio == 255) { | 206 | if (pio == 255) |
207 | via_set_drive(drive, ide_find_best_pio_mode(drive)); | 207 | pio = ide_get_best_pio_mode(drive, 255, 5); |
208 | return; | ||
209 | } | ||
210 | 208 | ||
211 | via_set_drive(drive, XFER_PIO_0 + min_t(u8, pio, 5)); | 209 | via_set_drive(drive, XFER_PIO_0 + min_t(u8, pio, 5)); |
212 | } | 210 | } |
@@ -223,12 +221,14 @@ static int via82cxxx_ide_dma_check (ide_drive_t *drive) | |||
223 | { | 221 | { |
224 | u8 speed = ide_max_dma_mode(drive); | 222 | u8 speed = ide_max_dma_mode(drive); |
225 | 223 | ||
226 | if (speed == 0) | 224 | if (speed == 0) { |
227 | speed = ide_find_best_pio_mode(drive); | 225 | via82cxxx_tune_drive(drive, 255); |
226 | return -1; | ||
227 | } | ||
228 | 228 | ||
229 | via_set_drive(drive, speed); | 229 | via_set_drive(drive, speed); |
230 | 230 | ||
231 | if (drive->autodma && (speed & XFER_MODE) != XFER_PIO) | 231 | if (drive->autodma) |
232 | return 0; | 232 | return 0; |
233 | 233 | ||
234 | return -1; | 234 | return -1; |
@@ -498,18 +498,22 @@ static ide_pci_device_t via82cxxx_chipsets[] __devinitdata = { | |||
498 | .name = "VP_IDE", | 498 | .name = "VP_IDE", |
499 | .init_chipset = init_chipset_via82cxxx, | 499 | .init_chipset = init_chipset_via82cxxx, |
500 | .init_hwif = init_hwif_via82cxxx, | 500 | .init_hwif = init_hwif_via82cxxx, |
501 | .channels = 2, | ||
502 | .autodma = NOAUTODMA, | 501 | .autodma = NOAUTODMA, |
503 | .enablebits = {{0x40,0x02,0x02}, {0x40,0x01,0x01}}, | 502 | .enablebits = {{0x40,0x02,0x02}, {0x40,0x01,0x01}}, |
504 | .bootable = ON_BOARD | 503 | .bootable = ON_BOARD, |
504 | .host_flags = IDE_HFLAG_PIO_NO_BLACKLIST | ||
505 | | IDE_HFLAG_PIO_NO_DOWNGRADE, | ||
506 | .pio_mask = ATA_PIO5, | ||
505 | },{ /* 1 */ | 507 | },{ /* 1 */ |
506 | .name = "VP_IDE", | 508 | .name = "VP_IDE", |
507 | .init_chipset = init_chipset_via82cxxx, | 509 | .init_chipset = init_chipset_via82cxxx, |
508 | .init_hwif = init_hwif_via82cxxx, | 510 | .init_hwif = init_hwif_via82cxxx, |
509 | .channels = 2, | ||
510 | .autodma = AUTODMA, | 511 | .autodma = AUTODMA, |
511 | .enablebits = {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, | 512 | .enablebits = {{0x00,0x00,0x00}, {0x00,0x00,0x00}}, |
512 | .bootable = ON_BOARD, | 513 | .bootable = ON_BOARD, |
514 | .host_flags = IDE_HFLAG_PIO_NO_BLACKLIST | ||
515 | | IDE_HFLAG_PIO_NO_DOWNGRADE, | ||
516 | .pio_mask = ATA_PIO5, | ||
513 | } | 517 | } |
514 | }; | 518 | }; |
515 | 519 | ||
diff --git a/drivers/ide/ppc/mpc8xx.c b/drivers/ide/ppc/mpc8xx.c index 82de2d781f2e..8859fe2f5ac2 100644 --- a/drivers/ide/ppc/mpc8xx.c +++ b/drivers/ide/ppc/mpc8xx.c | |||
@@ -316,6 +316,7 @@ m8xx_ide_init_hwif_ports(hw_regs_t *hw, unsigned long data_port, | |||
316 | } | 316 | } |
317 | 317 | ||
318 | /* register routine to tune PIO mode */ | 318 | /* register routine to tune PIO mode */ |
319 | ide_hwifs[data_port].pio_mask = ATA_PIO4; | ||
319 | ide_hwifs[data_port].tuneproc = m8xx_ide_tuneproc; | 320 | ide_hwifs[data_port].tuneproc = m8xx_ide_tuneproc; |
320 | 321 | ||
321 | hw->ack_intr = (ide_ack_intr_t *) ide_interrupt_ack; | 322 | hw->ack_intr = (ide_ack_intr_t *) ide_interrupt_ack; |
@@ -402,6 +403,7 @@ void m8xx_ide_init_hwif_ports (hw_regs_t *hw, | |||
402 | } | 403 | } |
403 | 404 | ||
404 | /* register routine to tune PIO mode */ | 405 | /* register routine to tune PIO mode */ |
406 | ide_hwifs[data_port].pio_mask = ATA_PIO4; | ||
405 | ide_hwifs[data_port].tuneproc = m8xx_ide_tuneproc; | 407 | ide_hwifs[data_port].tuneproc = m8xx_ide_tuneproc; |
406 | 408 | ||
407 | hw->ack_intr = (ide_ack_intr_t *) ide_interrupt_ack; | 409 | hw->ack_intr = (ide_ack_intr_t *) ide_interrupt_ack; |
@@ -431,13 +433,12 @@ void m8xx_ide_init_hwif_ports (hw_regs_t *hw, | |||
431 | static void | 433 | static void |
432 | m8xx_ide_tuneproc(ide_drive_t *drive, u8 pio) | 434 | m8xx_ide_tuneproc(ide_drive_t *drive, u8 pio) |
433 | { | 435 | { |
434 | ide_pio_data_t d; | ||
435 | #if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT) | 436 | #if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT) |
436 | volatile pcmconf8xx_t *pcmp; | 437 | volatile pcmconf8xx_t *pcmp; |
437 | ulong timing, mask, reg; | 438 | ulong timing, mask, reg; |
438 | #endif | 439 | #endif |
439 | 440 | ||
440 | pio = ide_get_best_pio_mode(drive, pio, 4, &d); | 441 | pio = ide_get_best_pio_mode(drive, pio, 4); |
441 | 442 | ||
442 | #if 1 | 443 | #if 1 |
443 | printk("%s[%d] %s: best PIO mode: %d\n", | 444 | printk("%s[%d] %s: best PIO mode: %d\n", |
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c index e46f47206542..33630ad3e794 100644 --- a/drivers/ide/ppc/pmac.c +++ b/drivers/ide/ppc/pmac.c | |||
@@ -615,24 +615,25 @@ out: | |||
615 | static void | 615 | static void |
616 | pmac_ide_tuneproc(ide_drive_t *drive, u8 pio) | 616 | pmac_ide_tuneproc(ide_drive_t *drive, u8 pio) |
617 | { | 617 | { |
618 | ide_pio_data_t d; | ||
619 | u32 *timings; | 618 | u32 *timings; |
620 | unsigned accessTicks, recTicks; | 619 | unsigned accessTicks, recTicks; |
621 | unsigned accessTime, recTime; | 620 | unsigned accessTime, recTime; |
622 | pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data; | 621 | pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data; |
623 | 622 | unsigned int cycle_time; | |
623 | |||
624 | if (pmif == NULL) | 624 | if (pmif == NULL) |
625 | return; | 625 | return; |
626 | 626 | ||
627 | /* which drive is it ? */ | 627 | /* which drive is it ? */ |
628 | timings = &pmif->timings[drive->select.b.unit & 0x01]; | 628 | timings = &pmif->timings[drive->select.b.unit & 0x01]; |
629 | 629 | ||
630 | pio = ide_get_best_pio_mode(drive, pio, 4, &d); | 630 | pio = ide_get_best_pio_mode(drive, pio, 4); |
631 | cycle_time = ide_pio_cycle_time(drive, pio); | ||
631 | 632 | ||
632 | switch (pmif->kind) { | 633 | switch (pmif->kind) { |
633 | case controller_sh_ata6: { | 634 | case controller_sh_ata6: { |
634 | /* 133Mhz cell */ | 635 | /* 133Mhz cell */ |
635 | u32 tr = kauai_lookup_timing(shasta_pio_timings, d.cycle_time); | 636 | u32 tr = kauai_lookup_timing(shasta_pio_timings, cycle_time); |
636 | if (tr == 0) | 637 | if (tr == 0) |
637 | return; | 638 | return; |
638 | *timings = ((*timings) & ~TR_133_PIOREG_PIO_MASK) | tr; | 639 | *timings = ((*timings) & ~TR_133_PIOREG_PIO_MASK) | tr; |
@@ -641,7 +642,7 @@ pmac_ide_tuneproc(ide_drive_t *drive, u8 pio) | |||
641 | case controller_un_ata6: | 642 | case controller_un_ata6: |
642 | case controller_k2_ata6: { | 643 | case controller_k2_ata6: { |
643 | /* 100Mhz cell */ | 644 | /* 100Mhz cell */ |
644 | u32 tr = kauai_lookup_timing(kauai_pio_timings, d.cycle_time); | 645 | u32 tr = kauai_lookup_timing(kauai_pio_timings, cycle_time); |
645 | if (tr == 0) | 646 | if (tr == 0) |
646 | return; | 647 | return; |
647 | *timings = ((*timings) & ~TR_100_PIOREG_PIO_MASK) | tr; | 648 | *timings = ((*timings) & ~TR_100_PIOREG_PIO_MASK) | tr; |
@@ -649,7 +650,7 @@ pmac_ide_tuneproc(ide_drive_t *drive, u8 pio) | |||
649 | } | 650 | } |
650 | case controller_kl_ata4: | 651 | case controller_kl_ata4: |
651 | /* 66Mhz cell */ | 652 | /* 66Mhz cell */ |
652 | recTime = d.cycle_time - ide_pio_timings[pio].active_time | 653 | recTime = cycle_time - ide_pio_timings[pio].active_time |
653 | - ide_pio_timings[pio].setup_time; | 654 | - ide_pio_timings[pio].setup_time; |
654 | recTime = max(recTime, 150U); | 655 | recTime = max(recTime, 150U); |
655 | accessTime = ide_pio_timings[pio].active_time; | 656 | accessTime = ide_pio_timings[pio].active_time; |
@@ -665,7 +666,7 @@ pmac_ide_tuneproc(ide_drive_t *drive, u8 pio) | |||
665 | default: { | 666 | default: { |
666 | /* 33Mhz cell */ | 667 | /* 33Mhz cell */ |
667 | int ebit = 0; | 668 | int ebit = 0; |
668 | recTime = d.cycle_time - ide_pio_timings[pio].active_time | 669 | recTime = cycle_time - ide_pio_timings[pio].active_time |
669 | - ide_pio_timings[pio].setup_time; | 670 | - ide_pio_timings[pio].setup_time; |
670 | recTime = max(recTime, 150U); | 671 | recTime = max(recTime, 150U); |
671 | accessTime = ide_pio_timings[pio].active_time; | 672 | accessTime = ide_pio_timings[pio].active_time; |
@@ -1247,6 +1248,7 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif) | |||
1247 | hwif->cbl = pmif->cable_80 ? ATA_CBL_PATA80 : ATA_CBL_PATA40; | 1248 | hwif->cbl = pmif->cable_80 ? ATA_CBL_PATA80 : ATA_CBL_PATA40; |
1248 | hwif->drives[0].unmask = 1; | 1249 | hwif->drives[0].unmask = 1; |
1249 | hwif->drives[1].unmask = 1; | 1250 | hwif->drives[1].unmask = 1; |
1251 | hwif->pio_mask = ATA_PIO4; | ||
1250 | hwif->tuneproc = pmac_ide_tuneproc; | 1252 | hwif->tuneproc = pmac_ide_tuneproc; |
1251 | if (pmif->kind == controller_un_ata6 | 1253 | if (pmif->kind == controller_un_ata6 |
1252 | || pmif->kind == controller_k2_ata6 | 1254 | || pmif->kind == controller_k2_ata6 |
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c index c88d33225cf9..30e596c0f120 100644 --- a/drivers/ide/setup-pci.c +++ b/drivers/ide/setup-pci.c | |||
@@ -5,12 +5,6 @@ | |||
5 | * | 5 | * |
6 | * Copyright (c) 1995-1998 Mark Lord | 6 | * Copyright (c) 1995-1998 Mark Lord |
7 | * May be copied or modified under the terms of the GNU General Public License | 7 | * May be copied or modified under the terms of the GNU General Public License |
8 | * | ||
9 | * Recent Changes | ||
10 | * Split the set up function into multiple functions | ||
11 | * Use pci_set_master | ||
12 | * Fix misreporting of I/O v MMIO problems | ||
13 | * Initial fixups for simplex devices | ||
14 | */ | 8 | */ |
15 | 9 | ||
16 | /* | 10 | /* |
@@ -407,7 +401,7 @@ static ide_hwif_t *ide_hwif_configure(struct pci_dev *dev, ide_pci_device_t *d, | |||
407 | unsigned long ctl = 0, base = 0; | 401 | unsigned long ctl = 0, base = 0; |
408 | ide_hwif_t *hwif; | 402 | ide_hwif_t *hwif; |
409 | 403 | ||
410 | if ((d->flags & IDEPCI_FLAG_ISA_PORTS) == 0) { | 404 | if ((d->host_flags & IDE_HFLAG_ISA_PORTS) == 0) { |
411 | /* Possibly we should fail if these checks report true */ | 405 | /* Possibly we should fail if these checks report true */ |
412 | ide_pci_check_iomem(dev, d, 2*port); | 406 | ide_pci_check_iomem(dev, d, 2*port); |
413 | ide_pci_check_iomem(dev, d, 2*port+1); | 407 | ide_pci_check_iomem(dev, d, 2*port+1); |
@@ -571,7 +565,7 @@ out: | |||
571 | 565 | ||
572 | void ide_pci_setup_ports(struct pci_dev *dev, ide_pci_device_t *d, int pciirq, ata_index_t *index) | 566 | void ide_pci_setup_ports(struct pci_dev *dev, ide_pci_device_t *d, int pciirq, ata_index_t *index) |
573 | { | 567 | { |
574 | int port; | 568 | int channels = (d->host_flags & IDE_HFLAG_SINGLE) ? 1 : 2, port; |
575 | int at_least_one_hwif_enabled = 0; | 569 | int at_least_one_hwif_enabled = 0; |
576 | ide_hwif_t *hwif, *mate = NULL; | 570 | ide_hwif_t *hwif, *mate = NULL; |
577 | u8 tmp; | 571 | u8 tmp; |
@@ -582,16 +576,13 @@ void ide_pci_setup_ports(struct pci_dev *dev, ide_pci_device_t *d, int pciirq, a | |||
582 | * Set up the IDE ports | 576 | * Set up the IDE ports |
583 | */ | 577 | */ |
584 | 578 | ||
585 | for (port = 0; port <= 1; ++port) { | 579 | for (port = 0; port < channels; ++port) { |
586 | ide_pci_enablebit_t *e = &(d->enablebits[port]); | 580 | ide_pci_enablebit_t *e = &(d->enablebits[port]); |
587 | 581 | ||
588 | if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) || | 582 | if (e->reg && (pci_read_config_byte(dev, e->reg, &tmp) || |
589 | (tmp & e->mask) != e->val)) | 583 | (tmp & e->mask) != e->val)) |
590 | continue; /* port not enabled */ | 584 | continue; /* port not enabled */ |
591 | 585 | ||
592 | if (d->channels <= port) | ||
593 | break; | ||
594 | |||
595 | if ((hwif = ide_hwif_configure(dev, d, mate, port, pciirq)) == NULL) | 586 | if ((hwif = ide_hwif_configure(dev, d, mate, port, pciirq)) == NULL) |
596 | continue; | 587 | continue; |
597 | 588 | ||
@@ -616,6 +607,9 @@ void ide_pci_setup_ports(struct pci_dev *dev, ide_pci_device_t *d, int pciirq, a | |||
616 | else | 607 | else |
617 | ide_hwif_setup_dma(dev, d, hwif); | 608 | ide_hwif_setup_dma(dev, d, hwif); |
618 | bypass_legacy_dma: | 609 | bypass_legacy_dma: |
610 | hwif->host_flags = d->host_flags; | ||
611 | hwif->pio_mask = d->pio_mask; | ||
612 | |||
619 | if (d->init_hwif) | 613 | if (d->init_hwif) |
620 | /* Call chipset-specific routine | 614 | /* Call chipset-specific routine |
621 | * for each enabled hwif | 615 | * for each enabled hwif |
diff --git a/drivers/ieee1394/eth1394.c b/drivers/ieee1394/eth1394.c index 93362eed94ed..3a9d7e2d4de6 100644 --- a/drivers/ieee1394/eth1394.c +++ b/drivers/ieee1394/eth1394.c | |||
@@ -1729,7 +1729,7 @@ static int __init ether1394_init_module(void) | |||
1729 | 1729 | ||
1730 | packet_task_cache = kmem_cache_create("packet_task", | 1730 | packet_task_cache = kmem_cache_create("packet_task", |
1731 | sizeof(struct packet_task), | 1731 | sizeof(struct packet_task), |
1732 | 0, 0, NULL, NULL); | 1732 | 0, 0, NULL); |
1733 | if (!packet_task_cache) | 1733 | if (!packet_task_cache) |
1734 | return -ENOMEM; | 1734 | return -ENOMEM; |
1735 | 1735 | ||
diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c index 6b8faca02f8a..bc547f1d34ba 100644 --- a/drivers/infiniband/core/mad.c +++ b/drivers/infiniband/core/mad.c | |||
@@ -2998,7 +2998,6 @@ static int __init ib_mad_init_module(void) | |||
2998 | sizeof(struct ib_mad_private), | 2998 | sizeof(struct ib_mad_private), |
2999 | 0, | 2999 | 0, |
3000 | SLAB_HWCACHE_ALIGN, | 3000 | SLAB_HWCACHE_ALIGN, |
3001 | NULL, | ||
3002 | NULL); | 3001 | NULL); |
3003 | if (!ib_mad_cache) { | 3002 | if (!ib_mad_cache) { |
3004 | printk(KERN_ERR PFX "Couldn't create ib_mad cache\n"); | 3003 | printk(KERN_ERR PFX "Couldn't create ib_mad cache\n"); |
diff --git a/drivers/infiniband/hw/amso1100/c2_vq.c b/drivers/infiniband/hw/amso1100/c2_vq.c index 36620a22413c..cfdacb1ec279 100644 --- a/drivers/infiniband/hw/amso1100/c2_vq.c +++ b/drivers/infiniband/hw/amso1100/c2_vq.c | |||
@@ -85,7 +85,7 @@ int vq_init(struct c2_dev *c2dev) | |||
85 | (char) ('0' + c2dev->devnum)); | 85 | (char) ('0' + c2dev->devnum)); |
86 | c2dev->host_msg_cache = | 86 | c2dev->host_msg_cache = |
87 | kmem_cache_create(c2dev->vq_cache_name, c2dev->rep_vq.msg_size, 0, | 87 | kmem_cache_create(c2dev->vq_cache_name, c2dev->rep_vq.msg_size, 0, |
88 | SLAB_HWCACHE_ALIGN, NULL, NULL); | 88 | SLAB_HWCACHE_ALIGN, NULL); |
89 | if (c2dev->host_msg_cache == NULL) { | 89 | if (c2dev->host_msg_cache == NULL) { |
90 | return -ENOMEM; | 90 | return -ENOMEM; |
91 | } | 91 | } |
diff --git a/drivers/infiniband/hw/ehca/ehca_av.c b/drivers/infiniband/hw/ehca/ehca_av.c index e53a97af1260..97d108634c58 100644 --- a/drivers/infiniband/hw/ehca/ehca_av.c +++ b/drivers/infiniband/hw/ehca/ehca_av.c | |||
@@ -259,7 +259,7 @@ int ehca_init_av_cache(void) | |||
259 | av_cache = kmem_cache_create("ehca_cache_av", | 259 | av_cache = kmem_cache_create("ehca_cache_av", |
260 | sizeof(struct ehca_av), 0, | 260 | sizeof(struct ehca_av), 0, |
261 | SLAB_HWCACHE_ALIGN, | 261 | SLAB_HWCACHE_ALIGN, |
262 | NULL, NULL); | 262 | NULL); |
263 | if (!av_cache) | 263 | if (!av_cache) |
264 | return -ENOMEM; | 264 | return -ENOMEM; |
265 | return 0; | 265 | return 0; |
diff --git a/drivers/infiniband/hw/ehca/ehca_cq.c b/drivers/infiniband/hw/ehca/ehca_cq.c index 9e87883b561a..1e8ca3fca4aa 100644 --- a/drivers/infiniband/hw/ehca/ehca_cq.c +++ b/drivers/infiniband/hw/ehca/ehca_cq.c | |||
@@ -387,7 +387,7 @@ int ehca_init_cq_cache(void) | |||
387 | cq_cache = kmem_cache_create("ehca_cache_cq", | 387 | cq_cache = kmem_cache_create("ehca_cache_cq", |
388 | sizeof(struct ehca_cq), 0, | 388 | sizeof(struct ehca_cq), 0, |
389 | SLAB_HWCACHE_ALIGN, | 389 | SLAB_HWCACHE_ALIGN, |
390 | NULL, NULL); | 390 | NULL); |
391 | if (!cq_cache) | 391 | if (!cq_cache) |
392 | return -ENOMEM; | 392 | return -ENOMEM; |
393 | return 0; | 393 | return 0; |
diff --git a/drivers/infiniband/hw/ehca/ehca_main.c b/drivers/infiniband/hw/ehca/ehca_main.c index 36377c6db3d4..04c324330b7c 100644 --- a/drivers/infiniband/hw/ehca/ehca_main.c +++ b/drivers/infiniband/hw/ehca/ehca_main.c | |||
@@ -163,7 +163,7 @@ static int ehca_create_slab_caches(void) | |||
163 | ctblk_cache = kmem_cache_create("ehca_cache_ctblk", | 163 | ctblk_cache = kmem_cache_create("ehca_cache_ctblk", |
164 | EHCA_PAGESIZE, H_CB_ALIGNMENT, | 164 | EHCA_PAGESIZE, H_CB_ALIGNMENT, |
165 | SLAB_HWCACHE_ALIGN, | 165 | SLAB_HWCACHE_ALIGN, |
166 | NULL, NULL); | 166 | NULL); |
167 | if (!ctblk_cache) { | 167 | if (!ctblk_cache) { |
168 | ehca_gen_err("Cannot create ctblk SLAB cache."); | 168 | ehca_gen_err("Cannot create ctblk SLAB cache."); |
169 | ehca_cleanup_mrmw_cache(); | 169 | ehca_cleanup_mrmw_cache(); |
diff --git a/drivers/infiniband/hw/ehca/ehca_mrmw.c b/drivers/infiniband/hw/ehca/ehca_mrmw.c index 6262c5462d50..9f4c9d46e8ef 100644 --- a/drivers/infiniband/hw/ehca/ehca_mrmw.c +++ b/drivers/infiniband/hw/ehca/ehca_mrmw.c | |||
@@ -1950,13 +1950,13 @@ int ehca_init_mrmw_cache(void) | |||
1950 | mr_cache = kmem_cache_create("ehca_cache_mr", | 1950 | mr_cache = kmem_cache_create("ehca_cache_mr", |
1951 | sizeof(struct ehca_mr), 0, | 1951 | sizeof(struct ehca_mr), 0, |
1952 | SLAB_HWCACHE_ALIGN, | 1952 | SLAB_HWCACHE_ALIGN, |
1953 | NULL, NULL); | 1953 | NULL); |
1954 | if (!mr_cache) | 1954 | if (!mr_cache) |
1955 | return -ENOMEM; | 1955 | return -ENOMEM; |
1956 | mw_cache = kmem_cache_create("ehca_cache_mw", | 1956 | mw_cache = kmem_cache_create("ehca_cache_mw", |
1957 | sizeof(struct ehca_mw), 0, | 1957 | sizeof(struct ehca_mw), 0, |
1958 | SLAB_HWCACHE_ALIGN, | 1958 | SLAB_HWCACHE_ALIGN, |
1959 | NULL, NULL); | 1959 | NULL); |
1960 | if (!mw_cache) { | 1960 | if (!mw_cache) { |
1961 | kmem_cache_destroy(mr_cache); | 1961 | kmem_cache_destroy(mr_cache); |
1962 | mr_cache = NULL; | 1962 | mr_cache = NULL; |
diff --git a/drivers/infiniband/hw/ehca/ehca_pd.c b/drivers/infiniband/hw/ehca/ehca_pd.c index 79d0591a8043..c85312ad292b 100644 --- a/drivers/infiniband/hw/ehca/ehca_pd.c +++ b/drivers/infiniband/hw/ehca/ehca_pd.c | |||
@@ -100,7 +100,7 @@ int ehca_init_pd_cache(void) | |||
100 | pd_cache = kmem_cache_create("ehca_cache_pd", | 100 | pd_cache = kmem_cache_create("ehca_cache_pd", |
101 | sizeof(struct ehca_pd), 0, | 101 | sizeof(struct ehca_pd), 0, |
102 | SLAB_HWCACHE_ALIGN, | 102 | SLAB_HWCACHE_ALIGN, |
103 | NULL, NULL); | 103 | NULL); |
104 | if (!pd_cache) | 104 | if (!pd_cache) |
105 | return -ENOMEM; | 105 | return -ENOMEM; |
106 | return 0; | 106 | return 0; |
diff --git a/drivers/infiniband/hw/ehca/ehca_qp.c b/drivers/infiniband/hw/ehca/ehca_qp.c index 48e9ceacd6fa..a3146e696c5d 100644 --- a/drivers/infiniband/hw/ehca/ehca_qp.c +++ b/drivers/infiniband/hw/ehca/ehca_qp.c | |||
@@ -1760,7 +1760,7 @@ int ehca_init_qp_cache(void) | |||
1760 | qp_cache = kmem_cache_create("ehca_cache_qp", | 1760 | qp_cache = kmem_cache_create("ehca_cache_qp", |
1761 | sizeof(struct ehca_qp), 0, | 1761 | sizeof(struct ehca_qp), 0, |
1762 | SLAB_HWCACHE_ALIGN, | 1762 | SLAB_HWCACHE_ALIGN, |
1763 | NULL, NULL); | 1763 | NULL); |
1764 | if (!qp_cache) | 1764 | if (!qp_cache) |
1765 | return -ENOMEM; | 1765 | return -ENOMEM; |
1766 | return 0; | 1766 | return 0; |
diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c index effdee299b0c..5db314380271 100644 --- a/drivers/infiniband/ulp/iser/iscsi_iser.c +++ b/drivers/infiniband/ulp/iser/iscsi_iser.c | |||
@@ -637,7 +637,7 @@ static int __init iser_init(void) | |||
637 | ig.desc_cache = kmem_cache_create("iser_descriptors", | 637 | ig.desc_cache = kmem_cache_create("iser_descriptors", |
638 | sizeof (struct iser_desc), | 638 | sizeof (struct iser_desc), |
639 | 0, SLAB_HWCACHE_ALIGN, | 639 | 0, SLAB_HWCACHE_ALIGN, |
640 | NULL, NULL); | 640 | NULL); |
641 | if (ig.desc_cache == NULL) | 641 | if (ig.desc_cache == NULL) |
642 | return -ENOMEM; | 642 | return -ENOMEM; |
643 | 643 | ||
diff --git a/drivers/input/input.c b/drivers/input/input.c index 75b4d2a83dd9..5fe755586623 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c | |||
@@ -471,37 +471,16 @@ static unsigned int input_proc_devices_poll(struct file *file, poll_table *wait) | |||
471 | return 0; | 471 | return 0; |
472 | } | 472 | } |
473 | 473 | ||
474 | static struct list_head *list_get_nth_element(struct list_head *list, loff_t *pos) | ||
475 | { | ||
476 | struct list_head *node; | ||
477 | loff_t i = 0; | ||
478 | |||
479 | list_for_each(node, list) | ||
480 | if (i++ == *pos) | ||
481 | return node; | ||
482 | |||
483 | return NULL; | ||
484 | } | ||
485 | |||
486 | static struct list_head *list_get_next_element(struct list_head *list, struct list_head *element, loff_t *pos) | ||
487 | { | ||
488 | if (element->next == list) | ||
489 | return NULL; | ||
490 | |||
491 | ++(*pos); | ||
492 | return element->next; | ||
493 | } | ||
494 | |||
495 | static void *input_devices_seq_start(struct seq_file *seq, loff_t *pos) | 474 | static void *input_devices_seq_start(struct seq_file *seq, loff_t *pos) |
496 | { | 475 | { |
497 | /* acquire lock here ... Yes, we do need locking, I knowi, I know... */ | 476 | /* acquire lock here ... Yes, we do need locking, I knowi, I know... */ |
498 | 477 | ||
499 | return list_get_nth_element(&input_dev_list, pos); | 478 | return seq_list_start(&input_dev_list, *pos); |
500 | } | 479 | } |
501 | 480 | ||
502 | static void *input_devices_seq_next(struct seq_file *seq, void *v, loff_t *pos) | 481 | static void *input_devices_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
503 | { | 482 | { |
504 | return list_get_next_element(&input_dev_list, v, pos); | 483 | return seq_list_next(v, &input_dev_list, pos); |
505 | } | 484 | } |
506 | 485 | ||
507 | static void input_devices_seq_stop(struct seq_file *seq, void *v) | 486 | static void input_devices_seq_stop(struct seq_file *seq, void *v) |
@@ -592,13 +571,13 @@ static void *input_handlers_seq_start(struct seq_file *seq, loff_t *pos) | |||
592 | { | 571 | { |
593 | /* acquire lock here ... Yes, we do need locking, I knowi, I know... */ | 572 | /* acquire lock here ... Yes, we do need locking, I knowi, I know... */ |
594 | seq->private = (void *)(unsigned long)*pos; | 573 | seq->private = (void *)(unsigned long)*pos; |
595 | return list_get_nth_element(&input_handler_list, pos); | 574 | return seq_list_start(&input_handler_list, *pos); |
596 | } | 575 | } |
597 | 576 | ||
598 | static void *input_handlers_seq_next(struct seq_file *seq, void *v, loff_t *pos) | 577 | static void *input_handlers_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
599 | { | 578 | { |
600 | seq->private = (void *)(unsigned long)(*pos + 1); | 579 | seq->private = (void *)(unsigned long)(*pos + 1); |
601 | return list_get_next_element(&input_handler_list, v, pos); | 580 | return seq_list_next(v, &input_handler_list, pos); |
602 | } | 581 | } |
603 | 582 | ||
604 | static void input_handlers_seq_stop(struct seq_file *seq, void *v) | 583 | static void input_handlers_seq_stop(struct seq_file *seq, void *v) |
diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig index 12db72d83ea0..e2abe18e575d 100644 --- a/drivers/input/joystick/Kconfig +++ b/drivers/input/joystick/Kconfig | |||
@@ -275,4 +275,11 @@ config JOYSTICK_XPAD_FF | |||
275 | ---help--- | 275 | ---help--- |
276 | Say Y here if you want to take advantage of xbox 360 rumble features. | 276 | Say Y here if you want to take advantage of xbox 360 rumble features. |
277 | 277 | ||
278 | config JOYSTICK_XPAD_LEDS | ||
279 | bool "LED Support for Xbox360 controller 'BigX' LED" | ||
280 | depends on LEDS_CLASS && JOYSTICK_XPAD | ||
281 | ---help--- | ||
282 | This option enables support for the LED which surrounds the Big X on | ||
283 | XBox 360 controller. | ||
284 | |||
278 | endif | 285 | endif |
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index 244089c52650..28080395899c 100644 --- a/drivers/input/joystick/xpad.c +++ b/drivers/input/joystick/xpad.c | |||
@@ -191,13 +191,18 @@ struct usb_xpad { | |||
191 | unsigned char *idata; /* input data */ | 191 | unsigned char *idata; /* input data */ |
192 | dma_addr_t idata_dma; | 192 | dma_addr_t idata_dma; |
193 | 193 | ||
194 | #ifdef CONFIG_JOYSTICK_XPAD_FF | 194 | #if defined(CONFIG_JOYSTICK_XPAD_FF) || defined(CONFIG_JOYSTICK_XPAD_LEDS) |
195 | struct urb *irq_out; /* urb for interrupt out report */ | 195 | struct urb *irq_out; /* urb for interrupt out report */ |
196 | unsigned char *odata; /* output data */ | 196 | unsigned char *odata; /* output data */ |
197 | dma_addr_t odata_dma; | 197 | dma_addr_t odata_dma; |
198 | struct mutex odata_mutex; | ||
199 | #endif | ||
200 | |||
201 | #if defined(CONFIG_JOYSTICK_XPAD_LEDS) | ||
202 | struct xpad_led *led; | ||
198 | #endif | 203 | #endif |
199 | 204 | ||
200 | char phys[65]; /* physical device path */ | 205 | char phys[64]; /* physical device path */ |
201 | 206 | ||
202 | int dpad_mapping; /* map d-pad to buttons or to axes */ | 207 | int dpad_mapping; /* map d-pad to buttons or to axes */ |
203 | int xtype; /* type of xbox device */ | 208 | int xtype; /* type of xbox device */ |
@@ -349,7 +354,7 @@ exit: | |||
349 | __FUNCTION__, retval); | 354 | __FUNCTION__, retval); |
350 | } | 355 | } |
351 | 356 | ||
352 | #ifdef CONFIG_JOYSTICK_XPAD_FF | 357 | #if defined(CONFIG_JOYSTICK_XPAD_FF) || defined(CONFIG_JOYSTICK_XPAD_LEDS) |
353 | static void xpad_irq_out(struct urb *urb) | 358 | static void xpad_irq_out(struct urb *urb) |
354 | { | 359 | { |
355 | int retval; | 360 | int retval; |
@@ -376,29 +381,7 @@ exit: | |||
376 | __FUNCTION__, retval); | 381 | __FUNCTION__, retval); |
377 | } | 382 | } |
378 | 383 | ||
379 | static int xpad_play_effect(struct input_dev *dev, void *data, | 384 | static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) |
380 | struct ff_effect *effect) | ||
381 | { | ||
382 | struct usb_xpad *xpad = input_get_drvdata(dev); | ||
383 | |||
384 | if (effect->type == FF_RUMBLE) { | ||
385 | __u16 strong = effect->u.rumble.strong_magnitude; | ||
386 | __u16 weak = effect->u.rumble.weak_magnitude; | ||
387 | xpad->odata[0] = 0x00; | ||
388 | xpad->odata[1] = 0x08; | ||
389 | xpad->odata[2] = 0x00; | ||
390 | xpad->odata[3] = strong / 256; | ||
391 | xpad->odata[4] = weak / 256; | ||
392 | xpad->odata[5] = 0x00; | ||
393 | xpad->odata[6] = 0x00; | ||
394 | xpad->odata[7] = 0x00; | ||
395 | usb_submit_urb(xpad->irq_out, GFP_KERNEL); | ||
396 | } | ||
397 | |||
398 | return 0; | ||
399 | } | ||
400 | |||
401 | static int xpad_init_ff(struct usb_interface *intf, struct usb_xpad *xpad) | ||
402 | { | 385 | { |
403 | struct usb_endpoint_descriptor *ep_irq_out; | 386 | struct usb_endpoint_descriptor *ep_irq_out; |
404 | int error = -ENOMEM; | 387 | int error = -ENOMEM; |
@@ -411,6 +394,8 @@ static int xpad_init_ff(struct usb_interface *intf, struct usb_xpad *xpad) | |||
411 | if (!xpad->odata) | 394 | if (!xpad->odata) |
412 | goto fail1; | 395 | goto fail1; |
413 | 396 | ||
397 | mutex_init(&xpad->odata_mutex); | ||
398 | |||
414 | xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL); | 399 | xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL); |
415 | if (!xpad->irq_out) | 400 | if (!xpad->irq_out) |
416 | goto fail2; | 401 | goto fail2; |
@@ -423,25 +408,19 @@ static int xpad_init_ff(struct usb_interface *intf, struct usb_xpad *xpad) | |||
423 | xpad->irq_out->transfer_dma = xpad->odata_dma; | 408 | xpad->irq_out->transfer_dma = xpad->odata_dma; |
424 | xpad->irq_out->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 409 | xpad->irq_out->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
425 | 410 | ||
426 | input_set_capability(xpad->dev, EV_FF, FF_RUMBLE); | ||
427 | |||
428 | error = input_ff_create_memless(xpad->dev, NULL, xpad_play_effect); | ||
429 | if (error) | ||
430 | goto fail2; | ||
431 | |||
432 | return 0; | 411 | return 0; |
433 | 412 | ||
434 | fail2: usb_buffer_free(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma); | 413 | fail2: usb_buffer_free(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma); |
435 | fail1: return error; | 414 | fail1: return error; |
436 | } | 415 | } |
437 | 416 | ||
438 | static void xpad_stop_ff(struct usb_xpad *xpad) | 417 | static void xpad_stop_output(struct usb_xpad *xpad) |
439 | { | 418 | { |
440 | if (xpad->xtype == XTYPE_XBOX360) | 419 | if (xpad->xtype == XTYPE_XBOX360) |
441 | usb_kill_urb(xpad->irq_out); | 420 | usb_kill_urb(xpad->irq_out); |
442 | } | 421 | } |
443 | 422 | ||
444 | static void xpad_deinit_ff(struct usb_xpad *xpad) | 423 | static void xpad_deinit_output(struct usb_xpad *xpad) |
445 | { | 424 | { |
446 | if (xpad->xtype == XTYPE_XBOX360) { | 425 | if (xpad->xtype == XTYPE_XBOX360) { |
447 | usb_free_urb(xpad->irq_out); | 426 | usb_free_urb(xpad->irq_out); |
@@ -449,13 +428,130 @@ static void xpad_deinit_ff(struct usb_xpad *xpad) | |||
449 | xpad->odata, xpad->odata_dma); | 428 | xpad->odata, xpad->odata_dma); |
450 | } | 429 | } |
451 | } | 430 | } |
431 | #else | ||
432 | static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) { return 0; } | ||
433 | static void xpad_deinit_output(struct usb_xpad *xpad) {} | ||
434 | static void xpad_stop_output(struct usb_xpad *xpad) {} | ||
435 | #endif | ||
436 | |||
437 | #ifdef CONFIG_JOYSTICK_XPAD_FF | ||
438 | static int xpad_play_effect(struct input_dev *dev, void *data, | ||
439 | struct ff_effect *effect) | ||
440 | { | ||
441 | struct usb_xpad *xpad = input_get_drvdata(dev); | ||
452 | 442 | ||
443 | if (effect->type == FF_RUMBLE) { | ||
444 | __u16 strong = effect->u.rumble.strong_magnitude; | ||
445 | __u16 weak = effect->u.rumble.weak_magnitude; | ||
446 | xpad->odata[0] = 0x00; | ||
447 | xpad->odata[1] = 0x08; | ||
448 | xpad->odata[2] = 0x00; | ||
449 | xpad->odata[3] = strong / 256; | ||
450 | xpad->odata[4] = weak / 256; | ||
451 | xpad->odata[5] = 0x00; | ||
452 | xpad->odata[6] = 0x00; | ||
453 | xpad->odata[7] = 0x00; | ||
454 | usb_submit_urb(xpad->irq_out, GFP_KERNEL); | ||
455 | } | ||
456 | |||
457 | return 0; | ||
458 | } | ||
459 | |||
460 | static int xpad_init_ff(struct usb_xpad *xpad) | ||
461 | { | ||
462 | input_set_capability(xpad->dev, EV_FF, FF_RUMBLE); | ||
463 | |||
464 | return input_ff_create_memless(xpad->dev, NULL, xpad_play_effect); | ||
465 | } | ||
466 | |||
467 | #else | ||
468 | static int xpad_init_ff(struct usb_xpad *xpad) { return 0; } | ||
469 | #endif | ||
470 | |||
471 | #if defined(CONFIG_JOYSTICK_XPAD_LEDS) | ||
472 | #include <linux/leds.h> | ||
473 | |||
474 | struct xpad_led { | ||
475 | char name[16]; | ||
476 | struct led_classdev led_cdev; | ||
477 | struct usb_xpad *xpad; | ||
478 | }; | ||
479 | |||
480 | static void xpad_send_led_command(struct usb_xpad *xpad, int command) | ||
481 | { | ||
482 | if (command >= 0 && command < 14) { | ||
483 | mutex_lock(&xpad->odata_mutex); | ||
484 | xpad->odata[0] = 0x01; | ||
485 | xpad->odata[1] = 0x03; | ||
486 | xpad->odata[2] = command; | ||
487 | usb_submit_urb(xpad->irq_out, GFP_KERNEL); | ||
488 | mutex_unlock(&xpad->odata_mutex); | ||
489 | } | ||
490 | } | ||
491 | |||
492 | static void xpad_led_set(struct led_classdev *led_cdev, | ||
493 | enum led_brightness value) | ||
494 | { | ||
495 | struct xpad_led *xpad_led = container_of(led_cdev, | ||
496 | struct xpad_led, led_cdev); | ||
497 | |||
498 | xpad_send_led_command(xpad_led->xpad, value); | ||
499 | } | ||
500 | |||
501 | static int xpad_led_probe(struct usb_xpad *xpad) | ||
502 | { | ||
503 | static atomic_t led_seq = ATOMIC_INIT(0); | ||
504 | long led_no; | ||
505 | struct xpad_led *led; | ||
506 | struct led_classdev *led_cdev; | ||
507 | int error; | ||
508 | |||
509 | if (xpad->xtype != XTYPE_XBOX360) | ||
510 | return 0; | ||
511 | |||
512 | xpad->led = led = kzalloc(sizeof(struct xpad_led), GFP_KERNEL); | ||
513 | if (!led) | ||
514 | return -ENOMEM; | ||
515 | |||
516 | led_no = (long)atomic_inc_return(&led_seq) - 1; | ||
517 | |||
518 | snprintf(led->name, sizeof(led->name), "xpad%ld", led_no); | ||
519 | led->xpad = xpad; | ||
520 | |||
521 | led_cdev = &led->led_cdev; | ||
522 | led_cdev->name = led->name; | ||
523 | led_cdev->brightness_set = xpad_led_set; | ||
524 | |||
525 | error = led_classdev_register(&xpad->udev->dev, led_cdev); | ||
526 | if (error) { | ||
527 | kfree(led); | ||
528 | xpad->led = NULL; | ||
529 | return error; | ||
530 | } | ||
531 | |||
532 | /* | ||
533 | * Light up the segment corresponding to controller number | ||
534 | */ | ||
535 | xpad_send_led_command(xpad, (led_no % 4) + 2); | ||
536 | |||
537 | return 0; | ||
538 | } | ||
539 | |||
540 | static void xpad_led_disconnect(struct usb_xpad *xpad) | ||
541 | { | ||
542 | struct xpad_led *xpad_led = xpad->led; | ||
543 | |||
544 | if (xpad_led) { | ||
545 | led_classdev_unregister(&xpad_led->led_cdev); | ||
546 | kfree(xpad_led->name); | ||
547 | } | ||
548 | } | ||
453 | #else | 549 | #else |
454 | static int xpad_init_ff(struct usb_interface *intf, struct usb_xpad *xpad) { return 0; } | 550 | static int xpad_led_probe(struct usb_xpad *xpad) { return 0; } |
455 | static void xpad_stop_ff(struct usb_xpad *xpad) { } | 551 | static void xpad_led_disconnect(struct usb_xpad *xpad) { } |
456 | static void xpad_deinit_ff(struct usb_xpad *xpad) { } | ||
457 | #endif | 552 | #endif |
458 | 553 | ||
554 | |||
459 | static int xpad_open(struct input_dev *dev) | 555 | static int xpad_open(struct input_dev *dev) |
460 | { | 556 | { |
461 | struct usb_xpad *xpad = input_get_drvdata(dev); | 557 | struct usb_xpad *xpad = input_get_drvdata(dev); |
@@ -472,7 +568,7 @@ static void xpad_close(struct input_dev *dev) | |||
472 | struct usb_xpad *xpad = input_get_drvdata(dev); | 568 | struct usb_xpad *xpad = input_get_drvdata(dev); |
473 | 569 | ||
474 | usb_kill_urb(xpad->irq_in); | 570 | usb_kill_urb(xpad->irq_in); |
475 | xpad_stop_ff(xpad); | 571 | xpad_stop_output(xpad); |
476 | } | 572 | } |
477 | 573 | ||
478 | static void xpad_set_up_abs(struct input_dev *input_dev, signed short abs) | 574 | static void xpad_set_up_abs(struct input_dev *input_dev, signed short abs) |
@@ -564,10 +660,18 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id | |||
564 | for (i = 0; xpad_abs_pad[i] >= 0; i++) | 660 | for (i = 0; xpad_abs_pad[i] >= 0; i++) |
565 | xpad_set_up_abs(input_dev, xpad_abs_pad[i]); | 661 | xpad_set_up_abs(input_dev, xpad_abs_pad[i]); |
566 | 662 | ||
567 | error = xpad_init_ff(intf, xpad); | 663 | error = xpad_init_output(intf, xpad); |
568 | if (error) | 664 | if (error) |
569 | goto fail2; | 665 | goto fail2; |
570 | 666 | ||
667 | error = xpad_init_ff(xpad); | ||
668 | if (error) | ||
669 | goto fail3; | ||
670 | |||
671 | error = xpad_led_probe(xpad); | ||
672 | if (error) | ||
673 | goto fail3; | ||
674 | |||
571 | ep_irq_in = &intf->cur_altsetting->endpoint[0].desc; | 675 | ep_irq_in = &intf->cur_altsetting->endpoint[0].desc; |
572 | usb_fill_int_urb(xpad->irq_in, udev, | 676 | usb_fill_int_urb(xpad->irq_in, udev, |
573 | usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), | 677 | usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), |
@@ -578,12 +682,13 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id | |||
578 | 682 | ||
579 | error = input_register_device(xpad->dev); | 683 | error = input_register_device(xpad->dev); |
580 | if (error) | 684 | if (error) |
581 | goto fail3; | 685 | goto fail4; |
582 | 686 | ||
583 | usb_set_intfdata(intf, xpad); | 687 | usb_set_intfdata(intf, xpad); |
584 | return 0; | 688 | return 0; |
585 | 689 | ||
586 | fail3: usb_free_urb(xpad->irq_in); | 690 | fail4: usb_free_urb(xpad->irq_in); |
691 | fail3: xpad_deinit_output(xpad); | ||
587 | fail2: usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); | 692 | fail2: usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); |
588 | fail1: input_free_device(input_dev); | 693 | fail1: input_free_device(input_dev); |
589 | kfree(xpad); | 694 | kfree(xpad); |
@@ -597,8 +702,9 @@ static void xpad_disconnect(struct usb_interface *intf) | |||
597 | 702 | ||
598 | usb_set_intfdata(intf, NULL); | 703 | usb_set_intfdata(intf, NULL); |
599 | if (xpad) { | 704 | if (xpad) { |
705 | xpad_led_disconnect(xpad); | ||
600 | input_unregister_device(xpad->dev); | 706 | input_unregister_device(xpad->dev); |
601 | xpad_deinit_ff(xpad); | 707 | xpad_deinit_output(xpad); |
602 | usb_free_urb(xpad->irq_in); | 708 | usb_free_urb(xpad->irq_in); |
603 | usb_buffer_free(xpad->udev, XPAD_PKT_LEN, | 709 | usb_buffer_free(xpad->udev, XPAD_PKT_LEN, |
604 | xpad->idata, xpad->idata_dma); | 710 | xpad->idata, xpad->idata_dma); |
diff --git a/drivers/input/mouse/appletouch.c b/drivers/input/mouse/appletouch.c index e3215267db11..2bea1b2c631c 100644 --- a/drivers/input/mouse/appletouch.c +++ b/drivers/input/mouse/appletouch.c | |||
@@ -155,6 +155,8 @@ struct atp { | |||
155 | int xy_acc[ATP_XSENSORS + ATP_YSENSORS]; | 155 | int xy_acc[ATP_XSENSORS + ATP_YSENSORS]; |
156 | int overflowwarn; /* overflow warning printed? */ | 156 | int overflowwarn; /* overflow warning printed? */ |
157 | int datalen; /* size of an USB urb transfer */ | 157 | int datalen; /* size of an USB urb transfer */ |
158 | int idlecount; /* number of empty packets */ | ||
159 | struct work_struct work; | ||
158 | }; | 160 | }; |
159 | 161 | ||
160 | #define dbg_dump(msg, tab) \ | 162 | #define dbg_dump(msg, tab) \ |
@@ -208,6 +210,55 @@ static inline int atp_is_geyser_3(struct atp *dev) | |||
208 | (productId == GEYSER4_JIS_PRODUCT_ID); | 210 | (productId == GEYSER4_JIS_PRODUCT_ID); |
209 | } | 211 | } |
210 | 212 | ||
213 | /* | ||
214 | * By default Geyser 3 device sends standard USB HID mouse | ||
215 | * packets (Report ID 2). This code changes device mode, so it | ||
216 | * sends raw sensor reports (Report ID 5). | ||
217 | */ | ||
218 | static int atp_geyser3_init(struct usb_device *udev) | ||
219 | { | ||
220 | char data[8]; | ||
221 | int size; | ||
222 | |||
223 | size = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), | ||
224 | ATP_GEYSER3_MODE_READ_REQUEST_ID, | ||
225 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | ||
226 | ATP_GEYSER3_MODE_REQUEST_VALUE, | ||
227 | ATP_GEYSER3_MODE_REQUEST_INDEX, &data, 8, 5000); | ||
228 | |||
229 | if (size != 8) { | ||
230 | err("Could not do mode read request from device" | ||
231 | " (Geyser 3 mode)"); | ||
232 | return -EIO; | ||
233 | } | ||
234 | |||
235 | /* Apply the mode switch */ | ||
236 | data[0] = ATP_GEYSER3_MODE_VENDOR_VALUE; | ||
237 | |||
238 | size = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | ||
239 | ATP_GEYSER3_MODE_WRITE_REQUEST_ID, | ||
240 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | ||
241 | ATP_GEYSER3_MODE_REQUEST_VALUE, | ||
242 | ATP_GEYSER3_MODE_REQUEST_INDEX, &data, 8, 5000); | ||
243 | |||
244 | if (size != 8) { | ||
245 | err("Could not do mode write request to device" | ||
246 | " (Geyser 3 mode)"); | ||
247 | return -EIO; | ||
248 | } | ||
249 | return 0; | ||
250 | } | ||
251 | |||
252 | /* Reinitialise the device if it's a geyser 3 */ | ||
253 | static void atp_reinit(struct work_struct *work) | ||
254 | { | ||
255 | struct atp *dev = container_of(work, struct atp, work); | ||
256 | struct usb_device *udev = dev->udev; | ||
257 | |||
258 | dev->idlecount = 0; | ||
259 | atp_geyser3_init(udev); | ||
260 | } | ||
261 | |||
211 | static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact, | 262 | static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact, |
212 | int *z, int *fingers) | 263 | int *z, int *fingers) |
213 | { | 264 | { |
@@ -439,8 +490,8 @@ static void atp_complete(struct urb* urb) | |||
439 | } | 490 | } |
440 | dev->x_old = x; | 491 | dev->x_old = x; |
441 | dev->y_old = y; | 492 | dev->y_old = y; |
442 | } | 493 | |
443 | else if (!x && !y) { | 494 | } else if (!x && !y) { |
444 | 495 | ||
445 | dev->x_old = dev->y_old = -1; | 496 | dev->x_old = dev->y_old = -1; |
446 | input_report_key(dev->input, BTN_TOUCH, 0); | 497 | input_report_key(dev->input, BTN_TOUCH, 0); |
@@ -449,11 +500,21 @@ static void atp_complete(struct urb* urb) | |||
449 | 500 | ||
450 | /* reset the accumulator on release */ | 501 | /* reset the accumulator on release */ |
451 | memset(dev->xy_acc, 0, sizeof(dev->xy_acc)); | 502 | memset(dev->xy_acc, 0, sizeof(dev->xy_acc)); |
452 | } | ||
453 | 503 | ||
454 | input_report_key(dev->input, BTN_LEFT, | 504 | /* Geyser 3 will continue to send packets continually after |
455 | !!dev->data[dev->datalen - 1]); | 505 | the first touch unless reinitialised. Do so if it's been |
506 | idle for a while in order to avoid waking the kernel up | ||
507 | several hundred times a second */ | ||
508 | if (atp_is_geyser_3(dev)) { | ||
509 | dev->idlecount++; | ||
510 | if (dev->idlecount == 10) { | ||
511 | dev->valid = 0; | ||
512 | schedule_work(&dev->work); | ||
513 | } | ||
514 | } | ||
515 | } | ||
456 | 516 | ||
517 | input_report_key(dev->input, BTN_LEFT, dev->data[dev->datalen - 1] & 1); | ||
457 | input_sync(dev->input); | 518 | input_sync(dev->input); |
458 | 519 | ||
459 | exit: | 520 | exit: |
@@ -480,6 +541,7 @@ static void atp_close(struct input_dev *input) | |||
480 | struct atp *dev = input_get_drvdata(input); | 541 | struct atp *dev = input_get_drvdata(input); |
481 | 542 | ||
482 | usb_kill_urb(dev->urb); | 543 | usb_kill_urb(dev->urb); |
544 | cancel_work_sync(&dev->work); | ||
483 | dev->open = 0; | 545 | dev->open = 0; |
484 | } | 546 | } |
485 | 547 | ||
@@ -528,40 +590,10 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id | |||
528 | dev->datalen = 81; | 590 | dev->datalen = 81; |
529 | 591 | ||
530 | if (atp_is_geyser_3(dev)) { | 592 | if (atp_is_geyser_3(dev)) { |
531 | /* | 593 | /* switch to raw sensor mode */ |
532 | * By default Geyser 3 device sends standard USB HID mouse | 594 | if (atp_geyser3_init(udev)) |
533 | * packets (Report ID 2). This code changes device mode, so it | ||
534 | * sends raw sensor reports (Report ID 5). | ||
535 | */ | ||
536 | char data[8]; | ||
537 | int size; | ||
538 | |||
539 | size = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), | ||
540 | ATP_GEYSER3_MODE_READ_REQUEST_ID, | ||
541 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | ||
542 | ATP_GEYSER3_MODE_REQUEST_VALUE, | ||
543 | ATP_GEYSER3_MODE_REQUEST_INDEX, &data, 8, 5000); | ||
544 | |||
545 | if (size != 8) { | ||
546 | err("Could not do mode read request from device" | ||
547 | " (Geyser 3 mode)"); | ||
548 | goto err_free_devs; | 595 | goto err_free_devs; |
549 | } | ||
550 | |||
551 | /* Apply the mode switch */ | ||
552 | data[0] = ATP_GEYSER3_MODE_VENDOR_VALUE; | ||
553 | |||
554 | size = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | ||
555 | ATP_GEYSER3_MODE_WRITE_REQUEST_ID, | ||
556 | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, | ||
557 | ATP_GEYSER3_MODE_REQUEST_VALUE, | ||
558 | ATP_GEYSER3_MODE_REQUEST_INDEX, &data, 8, 5000); | ||
559 | 596 | ||
560 | if (size != 8) { | ||
561 | err("Could not do mode write request to device" | ||
562 | " (Geyser 3 mode)"); | ||
563 | goto err_free_devs; | ||
564 | } | ||
565 | printk("appletouch Geyser 3 inited.\n"); | 597 | printk("appletouch Geyser 3 inited.\n"); |
566 | } | 598 | } |
567 | 599 | ||
@@ -636,6 +668,8 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id | |||
636 | /* save our data pointer in this interface device */ | 668 | /* save our data pointer in this interface device */ |
637 | usb_set_intfdata(iface, dev); | 669 | usb_set_intfdata(iface, dev); |
638 | 670 | ||
671 | INIT_WORK(&dev->work, atp_reinit); | ||
672 | |||
639 | return 0; | 673 | return 0; |
640 | 674 | ||
641 | err_free_buffer: | 675 | err_free_buffer: |
@@ -669,14 +703,17 @@ static void atp_disconnect(struct usb_interface *iface) | |||
669 | static int atp_suspend(struct usb_interface *iface, pm_message_t message) | 703 | static int atp_suspend(struct usb_interface *iface, pm_message_t message) |
670 | { | 704 | { |
671 | struct atp *dev = usb_get_intfdata(iface); | 705 | struct atp *dev = usb_get_intfdata(iface); |
706 | |||
672 | usb_kill_urb(dev->urb); | 707 | usb_kill_urb(dev->urb); |
673 | dev->valid = 0; | 708 | dev->valid = 0; |
709 | |||
674 | return 0; | 710 | return 0; |
675 | } | 711 | } |
676 | 712 | ||
677 | static int atp_resume(struct usb_interface *iface) | 713 | static int atp_resume(struct usb_interface *iface) |
678 | { | 714 | { |
679 | struct atp *dev = usb_get_intfdata(iface); | 715 | struct atp *dev = usb_get_intfdata(iface); |
716 | |||
680 | if (dev->open && usb_submit_urb(dev->urb, GFP_ATOMIC)) | 717 | if (dev->open && usb_submit_urb(dev->urb, GFP_ATOMIC)) |
681 | return -EIO; | 718 | return -EIO; |
682 | 719 | ||
diff --git a/drivers/input/mouse/lifebook.c b/drivers/input/mouse/lifebook.c index 1740cadd9594..91109b49fde1 100644 --- a/drivers/input/mouse/lifebook.c +++ b/drivers/input/mouse/lifebook.c | |||
@@ -109,7 +109,7 @@ static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse) | |||
109 | { | 109 | { |
110 | struct lifebook_data *priv = psmouse->private; | 110 | struct lifebook_data *priv = psmouse->private; |
111 | struct input_dev *dev1 = psmouse->dev; | 111 | struct input_dev *dev1 = psmouse->dev; |
112 | struct input_dev *dev2 = priv->dev2; | 112 | struct input_dev *dev2 = priv ? priv->dev2 : NULL; |
113 | unsigned char *packet = psmouse->packet; | 113 | unsigned char *packet = psmouse->packet; |
114 | int relative_packet = packet[0] & 0x08; | 114 | int relative_packet = packet[0] & 0x08; |
115 | 115 | ||
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h index 4fca1e7f2678..702a526cf45b 100644 --- a/drivers/input/serio/i8042-x86ia64io.h +++ b/drivers/input/serio/i8042-x86ia64io.h | |||
@@ -366,6 +366,7 @@ static void i8042_pnp_exit(void) | |||
366 | static int __init i8042_pnp_init(void) | 366 | static int __init i8042_pnp_init(void) |
367 | { | 367 | { |
368 | char kbd_irq_str[4] = { 0 }, aux_irq_str[4] = { 0 }; | 368 | char kbd_irq_str[4] = { 0 }, aux_irq_str[4] = { 0 }; |
369 | int pnp_data_busted = 0; | ||
369 | int err; | 370 | int err; |
370 | 371 | ||
371 | if (i8042_nopnp) { | 372 | if (i8042_nopnp) { |
@@ -413,27 +414,48 @@ static int __init i8042_pnp_init(void) | |||
413 | #endif | 414 | #endif |
414 | 415 | ||
415 | if (((i8042_pnp_data_reg & ~0xf) == (i8042_data_reg & ~0xf) && | 416 | if (((i8042_pnp_data_reg & ~0xf) == (i8042_data_reg & ~0xf) && |
416 | i8042_pnp_data_reg != i8042_data_reg) || !i8042_pnp_data_reg) { | 417 | i8042_pnp_data_reg != i8042_data_reg) || |
417 | printk(KERN_WARNING "PNP: PS/2 controller has invalid data port %#x; using default %#x\n", | 418 | !i8042_pnp_data_reg) { |
419 | printk(KERN_WARNING | ||
420 | "PNP: PS/2 controller has invalid data port %#x; " | ||
421 | "using default %#x\n", | ||
418 | i8042_pnp_data_reg, i8042_data_reg); | 422 | i8042_pnp_data_reg, i8042_data_reg); |
419 | i8042_pnp_data_reg = i8042_data_reg; | 423 | i8042_pnp_data_reg = i8042_data_reg; |
424 | pnp_data_busted = 1; | ||
420 | } | 425 | } |
421 | 426 | ||
422 | if (((i8042_pnp_command_reg & ~0xf) == (i8042_command_reg & ~0xf) && | 427 | if (((i8042_pnp_command_reg & ~0xf) == (i8042_command_reg & ~0xf) && |
423 | i8042_pnp_command_reg != i8042_command_reg) || !i8042_pnp_command_reg) { | 428 | i8042_pnp_command_reg != i8042_command_reg) || |
424 | printk(KERN_WARNING "PNP: PS/2 controller has invalid command port %#x; using default %#x\n", | 429 | !i8042_pnp_command_reg) { |
430 | printk(KERN_WARNING | ||
431 | "PNP: PS/2 controller has invalid command port %#x; " | ||
432 | "using default %#x\n", | ||
425 | i8042_pnp_command_reg, i8042_command_reg); | 433 | i8042_pnp_command_reg, i8042_command_reg); |
426 | i8042_pnp_command_reg = i8042_command_reg; | 434 | i8042_pnp_command_reg = i8042_command_reg; |
435 | pnp_data_busted = 1; | ||
427 | } | 436 | } |
428 | 437 | ||
429 | if (!i8042_nokbd && !i8042_pnp_kbd_irq) { | 438 | if (!i8042_nokbd && !i8042_pnp_kbd_irq) { |
430 | printk(KERN_WARNING "PNP: PS/2 controller doesn't have KBD irq; using default %d\n", i8042_kbd_irq); | 439 | printk(KERN_WARNING |
440 | "PNP: PS/2 controller doesn't have KBD irq; " | ||
441 | "using default %d\n", i8042_kbd_irq); | ||
431 | i8042_pnp_kbd_irq = i8042_kbd_irq; | 442 | i8042_pnp_kbd_irq = i8042_kbd_irq; |
443 | pnp_data_busted = 1; | ||
432 | } | 444 | } |
433 | 445 | ||
434 | if (!i8042_noaux && !i8042_pnp_aux_irq) { | 446 | if (!i8042_noaux && !i8042_pnp_aux_irq) { |
435 | printk(KERN_WARNING "PNP: PS/2 controller doesn't have AUX irq; using default %d\n", i8042_aux_irq); | 447 | if (!pnp_data_busted && i8042_pnp_kbd_irq) { |
436 | i8042_pnp_aux_irq = i8042_aux_irq; | 448 | printk(KERN_WARNING |
449 | "PNP: PS/2 appears to have AUX port disabled, " | ||
450 | "if this is incorrect please boot with " | ||
451 | "i8042.nopnp\n"); | ||
452 | i8042_noaux = 1; | ||
453 | } else { | ||
454 | printk(KERN_WARNING | ||
455 | "PNP: PS/2 controller doesn't have AUX irq; " | ||
456 | "using default %d\n", i8042_aux_irq); | ||
457 | i8042_pnp_aux_irq = i8042_aux_irq; | ||
458 | } | ||
437 | } | 459 | } |
438 | 460 | ||
439 | i8042_data_reg = i8042_pnp_data_reg; | 461 | i8042_data_reg = i8042_pnp_data_reg; |
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 69371779806a..f929fcdbae2e 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig | |||
@@ -54,6 +54,19 @@ config TOUCHSCREEN_CORGI | |||
54 | To compile this driver as a module, choose M here: the | 54 | To compile this driver as a module, choose M here: the |
55 | module will be called corgi_ts. | 55 | module will be called corgi_ts. |
56 | 56 | ||
57 | config TOUCHSCREEN_FUJITSU | ||
58 | tristate "Fujitsu serial touchscreen" | ||
59 | select SERIO | ||
60 | help | ||
61 | Say Y here if you have the Fujitsu touchscreen (such as one | ||
62 | installed in Lifebook P series laptop) connected to your | ||
63 | system. | ||
64 | |||
65 | If unsure, say N. | ||
66 | |||
67 | To compile this driver as a module, choose M here: the | ||
68 | module will be called fujitsu-ts. | ||
69 | |||
57 | config TOUCHSCREEN_GUNZE | 70 | config TOUCHSCREEN_GUNZE |
58 | tristate "Gunze AHL-51S touchscreen" | 71 | tristate "Gunze AHL-51S touchscreen" |
59 | select SERIO | 72 | select SERIO |
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index 2f86d6ad06d3..5de8933c4993 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile | |||
@@ -9,6 +9,7 @@ obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o | |||
9 | obj-$(CONFIG_TOUCHSCREEN_CORGI) += corgi_ts.o | 9 | obj-$(CONFIG_TOUCHSCREEN_CORGI) += corgi_ts.o |
10 | obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o | 10 | obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o |
11 | obj-$(CONFIG_TOUCHSCREEN_ELO) += elo.o | 11 | obj-$(CONFIG_TOUCHSCREEN_ELO) += elo.o |
12 | obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o | ||
12 | obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o | 13 | obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o |
13 | obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o | 14 | obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o |
14 | obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o | 15 | obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o |
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c index 1c9069cd3bae..96581d08774f 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c | |||
@@ -95,7 +95,7 @@ struct ads7846 { | |||
95 | u16 dummy; /* for the pwrdown read */ | 95 | u16 dummy; /* for the pwrdown read */ |
96 | struct ts_event tc; | 96 | struct ts_event tc; |
97 | 97 | ||
98 | struct spi_transfer xfer[10]; | 98 | struct spi_transfer xfer[18]; |
99 | struct spi_message msg[5]; | 99 | struct spi_message msg[5]; |
100 | struct spi_message *last_msg; | 100 | struct spi_message *last_msg; |
101 | int msg_idx; | 101 | int msg_idx; |
@@ -107,6 +107,8 @@ struct ads7846 { | |||
107 | u16 debounce_tol; | 107 | u16 debounce_tol; |
108 | u16 debounce_rep; | 108 | u16 debounce_rep; |
109 | 109 | ||
110 | u16 penirq_recheck_delay_usecs; | ||
111 | |||
110 | spinlock_t lock; | 112 | spinlock_t lock; |
111 | struct hrtimer timer; | 113 | struct hrtimer timer; |
112 | unsigned pendown:1; /* P: lock */ | 114 | unsigned pendown:1; /* P: lock */ |
@@ -553,6 +555,15 @@ static void ads7846_rx(void *ads) | |||
553 | return; | 555 | return; |
554 | } | 556 | } |
555 | 557 | ||
558 | /* Maybe check the pendown state before reporting. This discards | ||
559 | * false readings when the pen is lifted. | ||
560 | */ | ||
561 | if (ts->penirq_recheck_delay_usecs) { | ||
562 | udelay(ts->penirq_recheck_delay_usecs); | ||
563 | if (!ts->get_pendown_state()) | ||
564 | Rt = 0; | ||
565 | } | ||
566 | |||
556 | /* NOTE: We can't rely on the pressure to determine the pen down | 567 | /* NOTE: We can't rely on the pressure to determine the pen down |
557 | * state, even this controller has a pressure sensor. The pressure | 568 | * state, even this controller has a pressure sensor. The pressure |
558 | * value can fluctuate for quite a while after lifting the pen and | 569 | * value can fluctuate for quite a while after lifting the pen and |
@@ -896,6 +907,10 @@ static int __devinit ads7846_probe(struct spi_device *spi) | |||
896 | ts->filter = ads7846_no_filter; | 907 | ts->filter = ads7846_no_filter; |
897 | ts->get_pendown_state = pdata->get_pendown_state; | 908 | ts->get_pendown_state = pdata->get_pendown_state; |
898 | 909 | ||
910 | if (pdata->penirq_recheck_delay_usecs) | ||
911 | ts->penirq_recheck_delay_usecs = | ||
912 | pdata->penirq_recheck_delay_usecs; | ||
913 | |||
899 | snprintf(ts->phys, sizeof(ts->phys), "%s/input0", spi->dev.bus_id); | 914 | snprintf(ts->phys, sizeof(ts->phys), "%s/input0", spi->dev.bus_id); |
900 | 915 | ||
901 | input_dev->name = "ADS784x Touchscreen"; | 916 | input_dev->name = "ADS784x Touchscreen"; |
@@ -936,6 +951,24 @@ static int __devinit ads7846_probe(struct spi_device *spi) | |||
936 | x->len = 2; | 951 | x->len = 2; |
937 | spi_message_add_tail(x, m); | 952 | spi_message_add_tail(x, m); |
938 | 953 | ||
954 | /* the first sample after switching drivers can be low quality; | ||
955 | * optionally discard it, using a second one after the signals | ||
956 | * have had enough time to stabilize. | ||
957 | */ | ||
958 | if (pdata->settle_delay_usecs) { | ||
959 | x->delay_usecs = pdata->settle_delay_usecs; | ||
960 | |||
961 | x++; | ||
962 | x->tx_buf = &ts->read_y; | ||
963 | x->len = 1; | ||
964 | spi_message_add_tail(x, m); | ||
965 | |||
966 | x++; | ||
967 | x->rx_buf = &ts->tc.y; | ||
968 | x->len = 2; | ||
969 | spi_message_add_tail(x, m); | ||
970 | } | ||
971 | |||
939 | m->complete = ads7846_rx_val; | 972 | m->complete = ads7846_rx_val; |
940 | m->context = ts; | 973 | m->context = ts; |
941 | 974 | ||
@@ -954,6 +987,21 @@ static int __devinit ads7846_probe(struct spi_device *spi) | |||
954 | x->len = 2; | 987 | x->len = 2; |
955 | spi_message_add_tail(x, m); | 988 | spi_message_add_tail(x, m); |
956 | 989 | ||
990 | /* ... maybe discard first sample ... */ | ||
991 | if (pdata->settle_delay_usecs) { | ||
992 | x->delay_usecs = pdata->settle_delay_usecs; | ||
993 | |||
994 | x++; | ||
995 | x->tx_buf = &ts->read_x; | ||
996 | x->len = 1; | ||
997 | spi_message_add_tail(x, m); | ||
998 | |||
999 | x++; | ||
1000 | x->rx_buf = &ts->tc.x; | ||
1001 | x->len = 2; | ||
1002 | spi_message_add_tail(x, m); | ||
1003 | } | ||
1004 | |||
957 | m->complete = ads7846_rx_val; | 1005 | m->complete = ads7846_rx_val; |
958 | m->context = ts; | 1006 | m->context = ts; |
959 | 1007 | ||
@@ -973,6 +1021,21 @@ static int __devinit ads7846_probe(struct spi_device *spi) | |||
973 | x->len = 2; | 1021 | x->len = 2; |
974 | spi_message_add_tail(x, m); | 1022 | spi_message_add_tail(x, m); |
975 | 1023 | ||
1024 | /* ... maybe discard first sample ... */ | ||
1025 | if (pdata->settle_delay_usecs) { | ||
1026 | x->delay_usecs = pdata->settle_delay_usecs; | ||
1027 | |||
1028 | x++; | ||
1029 | x->tx_buf = &ts->read_z1; | ||
1030 | x->len = 1; | ||
1031 | spi_message_add_tail(x, m); | ||
1032 | |||
1033 | x++; | ||
1034 | x->rx_buf = &ts->tc.z1; | ||
1035 | x->len = 2; | ||
1036 | spi_message_add_tail(x, m); | ||
1037 | } | ||
1038 | |||
976 | m->complete = ads7846_rx_val; | 1039 | m->complete = ads7846_rx_val; |
977 | m->context = ts; | 1040 | m->context = ts; |
978 | 1041 | ||
@@ -990,6 +1053,21 @@ static int __devinit ads7846_probe(struct spi_device *spi) | |||
990 | x->len = 2; | 1053 | x->len = 2; |
991 | spi_message_add_tail(x, m); | 1054 | spi_message_add_tail(x, m); |
992 | 1055 | ||
1056 | /* ... maybe discard first sample ... */ | ||
1057 | if (pdata->settle_delay_usecs) { | ||
1058 | x->delay_usecs = pdata->settle_delay_usecs; | ||
1059 | |||
1060 | x++; | ||
1061 | x->tx_buf = &ts->read_z2; | ||
1062 | x->len = 1; | ||
1063 | spi_message_add_tail(x, m); | ||
1064 | |||
1065 | x++; | ||
1066 | x->rx_buf = &ts->tc.z2; | ||
1067 | x->len = 2; | ||
1068 | spi_message_add_tail(x, m); | ||
1069 | } | ||
1070 | |||
993 | m->complete = ads7846_rx_val; | 1071 | m->complete = ads7846_rx_val; |
994 | m->context = ts; | 1072 | m->context = ts; |
995 | } | 1073 | } |
diff --git a/drivers/input/touchscreen/fujitsu_ts.c b/drivers/input/touchscreen/fujitsu_ts.c new file mode 100644 index 000000000000..daf7a4afc935 --- /dev/null +++ b/drivers/input/touchscreen/fujitsu_ts.c | |||
@@ -0,0 +1,189 @@ | |||
1 | /* | ||
2 | * Fujitsu serial touchscreen driver | ||
3 | * | ||
4 | * Copyright (c) Dmitry Torokhov <dtor@mail.ru> | ||
5 | */ | ||
6 | |||
7 | /* | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License version 2 as published | ||
10 | * by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | #include <linux/errno.h> | ||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/slab.h> | ||
17 | #include <linux/input.h> | ||
18 | #include <linux/serio.h> | ||
19 | #include <linux/init.h> | ||
20 | |||
21 | #define DRIVER_DESC "Fujitsu serial touchscreen driver" | ||
22 | |||
23 | MODULE_AUTHOR("Dmitry Torokhov <dtor@mail.ru>"); | ||
24 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
25 | MODULE_LICENSE("GPL"); | ||
26 | |||
27 | #define FUJITSU_LENGTH 5 | ||
28 | |||
29 | /* | ||
30 | * Per-touchscreen data. | ||
31 | */ | ||
32 | struct fujitsu { | ||
33 | struct input_dev *dev; | ||
34 | struct serio *serio; | ||
35 | int idx; | ||
36 | unsigned char data[FUJITSU_LENGTH]; | ||
37 | char phys[32]; | ||
38 | }; | ||
39 | |||
40 | /* | ||
41 | * Decode serial data (5 bytes per packet) | ||
42 | * First byte | ||
43 | * 1 C 0 0 R S S S | ||
44 | * Where C is 1 while in calibration mode (which we don't use) | ||
45 | * R is 1 when no coordinate corection was done. | ||
46 | * S are button state | ||
47 | */ | ||
48 | static irqreturn_t fujitsu_interrupt(struct serio *serio, | ||
49 | unsigned char data, unsigned int flags) | ||
50 | { | ||
51 | struct fujitsu *fujitsu = serio_get_drvdata(serio); | ||
52 | struct input_dev *dev = fujitsu->dev; | ||
53 | |||
54 | if (fujitsu->idx == 0) { | ||
55 | /* resync skip until start of frame */ | ||
56 | if ((data & 0xf0) != 0x80) | ||
57 | return IRQ_HANDLED; | ||
58 | } else { | ||
59 | /* resync skip garbage */ | ||
60 | if (data & 0x80) { | ||
61 | fujitsu->idx = 0; | ||
62 | return IRQ_HANDLED; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | fujitsu->data[fujitsu->idx++] = data; | ||
67 | if (fujitsu->idx == FUJITSU_LENGTH) { | ||
68 | input_report_abs(dev, ABS_X, | ||
69 | (fujitsu->data[2] << 7) | fujitsu->data[1]); | ||
70 | input_report_abs(dev, ABS_Y, | ||
71 | (fujitsu->data[4] << 7) | fujitsu->data[3]); | ||
72 | input_report_key(dev, BTN_TOUCH, | ||
73 | (fujitsu->data[0] & 0x03) != 2); | ||
74 | input_sync(dev); | ||
75 | fujitsu->idx = 0; | ||
76 | } | ||
77 | |||
78 | return IRQ_HANDLED; | ||
79 | } | ||
80 | |||
81 | /* | ||
82 | * fujitsu_disconnect() is the opposite of fujitsu_connect() | ||
83 | */ | ||
84 | static void fujitsu_disconnect(struct serio *serio) | ||
85 | { | ||
86 | struct fujitsu *fujitsu = serio_get_drvdata(serio); | ||
87 | |||
88 | input_get_device(fujitsu->dev); | ||
89 | input_unregister_device(fujitsu->dev); | ||
90 | serio_close(serio); | ||
91 | serio_set_drvdata(serio, NULL); | ||
92 | input_put_device(fujitsu->dev); | ||
93 | kfree(fujitsu); | ||
94 | } | ||
95 | |||
96 | /* | ||
97 | * fujitsu_connect() is the routine that is called when someone adds a | ||
98 | * new serio device that supports the Fujitsu protocol and registers it | ||
99 | * as input device. | ||
100 | */ | ||
101 | static int fujitsu_connect(struct serio *serio, struct serio_driver *drv) | ||
102 | { | ||
103 | struct fujitsu *fujitsu; | ||
104 | struct input_dev *input_dev; | ||
105 | int err; | ||
106 | |||
107 | fujitsu = kzalloc(sizeof(struct fujitsu), GFP_KERNEL); | ||
108 | input_dev = input_allocate_device(); | ||
109 | if (!fujitsu || !input_dev) { | ||
110 | err = -ENOMEM; | ||
111 | goto fail1; | ||
112 | } | ||
113 | |||
114 | fujitsu->serio = serio; | ||
115 | fujitsu->dev = input_dev; | ||
116 | snprintf(fujitsu->phys, sizeof(fujitsu->phys), | ||
117 | "%s/input0", serio->phys); | ||
118 | |||
119 | input_dev->name = "Fujitsu Serial Touchscreen"; | ||
120 | input_dev->phys = fujitsu->phys; | ||
121 | input_dev->id.bustype = BUS_RS232; | ||
122 | input_dev->id.vendor = SERIO_FUJITSU; | ||
123 | input_dev->id.product = 0; | ||
124 | input_dev->id.version = 0x0100; | ||
125 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); | ||
126 | input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); | ||
127 | |||
128 | input_set_abs_params(input_dev, ABS_X, 0, 4096, 0, 0); | ||
129 | input_set_abs_params(input_dev, ABS_Y, 0, 4096, 0, 0); | ||
130 | serio_set_drvdata(serio, fujitsu); | ||
131 | |||
132 | err = serio_open(serio, drv); | ||
133 | if (err) | ||
134 | goto fail2; | ||
135 | |||
136 | err = input_register_device(fujitsu->dev); | ||
137 | if (err) | ||
138 | goto fail3; | ||
139 | |||
140 | return 0; | ||
141 | |||
142 | fail3: | ||
143 | serio_close(serio); | ||
144 | fail2: | ||
145 | serio_set_drvdata(serio, NULL); | ||
146 | fail1: | ||
147 | input_free_device(input_dev); | ||
148 | kfree(fujitsu); | ||
149 | return err; | ||
150 | } | ||
151 | |||
152 | /* | ||
153 | * The serio driver structure. | ||
154 | */ | ||
155 | static struct serio_device_id fujitsu_serio_ids[] = { | ||
156 | { | ||
157 | .type = SERIO_RS232, | ||
158 | .proto = SERIO_FUJITSU, | ||
159 | .id = SERIO_ANY, | ||
160 | .extra = SERIO_ANY, | ||
161 | }, | ||
162 | { 0 } | ||
163 | }; | ||
164 | |||
165 | MODULE_DEVICE_TABLE(serio, fujitsu_serio_ids); | ||
166 | |||
167 | static struct serio_driver fujitsu_drv = { | ||
168 | .driver = { | ||
169 | .name = "fujitsu_ts", | ||
170 | }, | ||
171 | .description = DRIVER_DESC, | ||
172 | .id_table = fujitsu_serio_ids, | ||
173 | .interrupt = fujitsu_interrupt, | ||
174 | .connect = fujitsu_connect, | ||
175 | .disconnect = fujitsu_disconnect, | ||
176 | }; | ||
177 | |||
178 | static int __init fujitsu_init(void) | ||
179 | { | ||
180 | return serio_register_driver(&fujitsu_drv); | ||
181 | } | ||
182 | |||
183 | static void __exit fujitsu_exit(void) | ||
184 | { | ||
185 | serio_unregister_driver(&fujitsu_drv); | ||
186 | } | ||
187 | |||
188 | module_init(fujitsu_init); | ||
189 | module_exit(fujitsu_exit); | ||
diff --git a/drivers/kvm/Kconfig b/drivers/kvm/Kconfig index 33fa28a8c199..2f661e5f0dae 100644 --- a/drivers/kvm/Kconfig +++ b/drivers/kvm/Kconfig | |||
@@ -11,7 +11,6 @@ if VIRTUALIZATION | |||
11 | config KVM | 11 | config KVM |
12 | tristate "Kernel-based Virtual Machine (KVM) support" | 12 | tristate "Kernel-based Virtual Machine (KVM) support" |
13 | depends on X86 && EXPERIMENTAL | 13 | depends on X86 && EXPERIMENTAL |
14 | depends on X86_CMPXCHG64 || 64BIT | ||
15 | ---help--- | 14 | ---help--- |
16 | Support hosting fully virtualized guest machines using hardware | 15 | Support hosting fully virtualized guest machines using hardware |
17 | virtualization extensions. You will need a fairly recent | 16 | virtualization extensions. You will need a fairly recent |
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h index a7c5e6bee034..3ac9cbce3369 100644 --- a/drivers/kvm/kvm.h +++ b/drivers/kvm/kvm.h | |||
@@ -121,7 +121,7 @@ struct kvm_pte_chain { | |||
121 | * bits 4:7 - page table level for this shadow (1-4) | 121 | * bits 4:7 - page table level for this shadow (1-4) |
122 | * bits 8:9 - page table quadrant for 2-level guests | 122 | * bits 8:9 - page table quadrant for 2-level guests |
123 | * bit 16 - "metaphysical" - gfn is not a real page (huge page/real mode) | 123 | * bit 16 - "metaphysical" - gfn is not a real page (huge page/real mode) |
124 | * bits 17:18 - "access" - the user and writable bits of a huge page pde | 124 | * bits 17:19 - "access" - the user, writable, and nx bits of a huge page pde |
125 | */ | 125 | */ |
126 | union kvm_mmu_page_role { | 126 | union kvm_mmu_page_role { |
127 | unsigned word; | 127 | unsigned word; |
@@ -131,7 +131,7 @@ union kvm_mmu_page_role { | |||
131 | unsigned quadrant : 2; | 131 | unsigned quadrant : 2; |
132 | unsigned pad_for_nice_hex_output : 6; | 132 | unsigned pad_for_nice_hex_output : 6; |
133 | unsigned metaphysical : 1; | 133 | unsigned metaphysical : 1; |
134 | unsigned hugepage_access : 2; | 134 | unsigned hugepage_access : 3; |
135 | }; | 135 | }; |
136 | }; | 136 | }; |
137 | 137 | ||
@@ -535,8 +535,8 @@ int kvm_mmu_create(struct kvm_vcpu *vcpu); | |||
535 | int kvm_mmu_setup(struct kvm_vcpu *vcpu); | 535 | int kvm_mmu_setup(struct kvm_vcpu *vcpu); |
536 | 536 | ||
537 | int kvm_mmu_reset_context(struct kvm_vcpu *vcpu); | 537 | int kvm_mmu_reset_context(struct kvm_vcpu *vcpu); |
538 | void kvm_mmu_slot_remove_write_access(struct kvm_vcpu *vcpu, int slot); | 538 | void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot); |
539 | void kvm_mmu_zap_all(struct kvm_vcpu *vcpu); | 539 | void kvm_mmu_zap_all(struct kvm *kvm); |
540 | 540 | ||
541 | hpa_t gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa); | 541 | hpa_t gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa); |
542 | #define HPA_MSB ((sizeof(hpa_t) * 8) - 1) | 542 | #define HPA_MSB ((sizeof(hpa_t) * 8) - 1) |
@@ -569,6 +569,8 @@ void realmode_lmsw(struct kvm_vcpu *vcpu, unsigned long msw, | |||
569 | unsigned long realmode_get_cr(struct kvm_vcpu *vcpu, int cr); | 569 | unsigned long realmode_get_cr(struct kvm_vcpu *vcpu, int cr); |
570 | void realmode_set_cr(struct kvm_vcpu *vcpu, int cr, unsigned long value, | 570 | void realmode_set_cr(struct kvm_vcpu *vcpu, int cr, unsigned long value, |
571 | unsigned long *rflags); | 571 | unsigned long *rflags); |
572 | int kvm_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *data); | ||
573 | int kvm_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data); | ||
572 | 574 | ||
573 | struct x86_emulate_ctxt; | 575 | struct x86_emulate_ctxt; |
574 | 576 | ||
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c index 1b206f197c6b..bcbe6835beb4 100644 --- a/drivers/kvm/kvm_main.c +++ b/drivers/kvm/kvm_main.c | |||
@@ -238,23 +238,6 @@ static void vcpu_load(struct kvm_vcpu *vcpu) | |||
238 | kvm_arch_ops->vcpu_load(vcpu); | 238 | kvm_arch_ops->vcpu_load(vcpu); |
239 | } | 239 | } |
240 | 240 | ||
241 | /* | ||
242 | * Switches to specified vcpu, until a matching vcpu_put(). Will return NULL | ||
243 | * if the slot is not populated. | ||
244 | */ | ||
245 | static struct kvm_vcpu *vcpu_load_slot(struct kvm *kvm, int slot) | ||
246 | { | ||
247 | struct kvm_vcpu *vcpu = &kvm->vcpus[slot]; | ||
248 | |||
249 | mutex_lock(&vcpu->mutex); | ||
250 | if (!vcpu->vmcs) { | ||
251 | mutex_unlock(&vcpu->mutex); | ||
252 | return NULL; | ||
253 | } | ||
254 | kvm_arch_ops->vcpu_load(vcpu); | ||
255 | return vcpu; | ||
256 | } | ||
257 | |||
258 | static void vcpu_put(struct kvm_vcpu *vcpu) | 241 | static void vcpu_put(struct kvm_vcpu *vcpu) |
259 | { | 242 | { |
260 | kvm_arch_ops->vcpu_put(vcpu); | 243 | kvm_arch_ops->vcpu_put(vcpu); |
@@ -663,13 +646,6 @@ void fx_init(struct kvm_vcpu *vcpu) | |||
663 | } | 646 | } |
664 | EXPORT_SYMBOL_GPL(fx_init); | 647 | EXPORT_SYMBOL_GPL(fx_init); |
665 | 648 | ||
666 | static void do_remove_write_access(struct kvm_vcpu *vcpu, int slot) | ||
667 | { | ||
668 | spin_lock(&vcpu->kvm->lock); | ||
669 | kvm_mmu_slot_remove_write_access(vcpu, slot); | ||
670 | spin_unlock(&vcpu->kvm->lock); | ||
671 | } | ||
672 | |||
673 | /* | 649 | /* |
674 | * Allocate some memory and give it an address in the guest physical address | 650 | * Allocate some memory and give it an address in the guest physical address |
675 | * space. | 651 | * space. |
@@ -792,19 +768,10 @@ raced: | |||
792 | *memslot = new; | 768 | *memslot = new; |
793 | ++kvm->memory_config_version; | 769 | ++kvm->memory_config_version; |
794 | 770 | ||
795 | spin_unlock(&kvm->lock); | 771 | kvm_mmu_slot_remove_write_access(kvm, mem->slot); |
796 | 772 | kvm_flush_remote_tlbs(kvm); | |
797 | for (i = 0; i < KVM_MAX_VCPUS; ++i) { | ||
798 | struct kvm_vcpu *vcpu; | ||
799 | 773 | ||
800 | vcpu = vcpu_load_slot(kvm, i); | 774 | spin_unlock(&kvm->lock); |
801 | if (!vcpu) | ||
802 | continue; | ||
803 | if (new.flags & KVM_MEM_LOG_DIRTY_PAGES) | ||
804 | do_remove_write_access(vcpu, mem->slot); | ||
805 | kvm_mmu_reset_context(vcpu); | ||
806 | vcpu_put(vcpu); | ||
807 | } | ||
808 | 775 | ||
809 | kvm_free_physmem_slot(&old, &new); | 776 | kvm_free_physmem_slot(&old, &new); |
810 | return 0; | 777 | return 0; |
@@ -826,7 +793,6 @@ static int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, | |||
826 | struct kvm_memory_slot *memslot; | 793 | struct kvm_memory_slot *memslot; |
827 | int r, i; | 794 | int r, i; |
828 | int n; | 795 | int n; |
829 | int cleared; | ||
830 | unsigned long any = 0; | 796 | unsigned long any = 0; |
831 | 797 | ||
832 | spin_lock(&kvm->lock); | 798 | spin_lock(&kvm->lock); |
@@ -855,23 +821,11 @@ static int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, | |||
855 | if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n)) | 821 | if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n)) |
856 | goto out; | 822 | goto out; |
857 | 823 | ||
858 | if (any) { | 824 | spin_lock(&kvm->lock); |
859 | cleared = 0; | 825 | kvm_mmu_slot_remove_write_access(kvm, log->slot); |
860 | for (i = 0; i < KVM_MAX_VCPUS; ++i) { | 826 | kvm_flush_remote_tlbs(kvm); |
861 | struct kvm_vcpu *vcpu; | 827 | memset(memslot->dirty_bitmap, 0, n); |
862 | 828 | spin_unlock(&kvm->lock); | |
863 | vcpu = vcpu_load_slot(kvm, i); | ||
864 | if (!vcpu) | ||
865 | continue; | ||
866 | if (!cleared) { | ||
867 | do_remove_write_access(vcpu, log->slot); | ||
868 | memset(memslot->dirty_bitmap, 0, n); | ||
869 | cleared = 1; | ||
870 | } | ||
871 | kvm_arch_ops->tlb_flush(vcpu); | ||
872 | vcpu_put(vcpu); | ||
873 | } | ||
874 | } | ||
875 | 829 | ||
876 | r = 0; | 830 | r = 0; |
877 | 831 | ||
@@ -920,13 +874,9 @@ static int kvm_vm_ioctl_set_memory_alias(struct kvm *kvm, | |||
920 | break; | 874 | break; |
921 | kvm->naliases = n; | 875 | kvm->naliases = n; |
922 | 876 | ||
923 | spin_unlock(&kvm->lock); | 877 | kvm_mmu_zap_all(kvm); |
924 | 878 | ||
925 | vcpu_load(&kvm->vcpus[0]); | ||
926 | spin_lock(&kvm->lock); | ||
927 | kvm_mmu_zap_all(&kvm->vcpus[0]); | ||
928 | spin_unlock(&kvm->lock); | 879 | spin_unlock(&kvm->lock); |
929 | vcpu_put(&kvm->vcpus[0]); | ||
930 | 880 | ||
931 | return 0; | 881 | return 0; |
932 | 882 | ||
@@ -1567,7 +1517,7 @@ EXPORT_SYMBOL_GPL(kvm_get_msr_common); | |||
1567 | * Returns 0 on success, non-0 otherwise. | 1517 | * Returns 0 on success, non-0 otherwise. |
1568 | * Assumes vcpu_load() was already called. | 1518 | * Assumes vcpu_load() was already called. |
1569 | */ | 1519 | */ |
1570 | static int get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata) | 1520 | int kvm_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata) |
1571 | { | 1521 | { |
1572 | return kvm_arch_ops->get_msr(vcpu, msr_index, pdata); | 1522 | return kvm_arch_ops->get_msr(vcpu, msr_index, pdata); |
1573 | } | 1523 | } |
@@ -1645,7 +1595,7 @@ EXPORT_SYMBOL_GPL(kvm_set_msr_common); | |||
1645 | * Returns 0 on success, non-0 otherwise. | 1595 | * Returns 0 on success, non-0 otherwise. |
1646 | * Assumes vcpu_load() was already called. | 1596 | * Assumes vcpu_load() was already called. |
1647 | */ | 1597 | */ |
1648 | static int set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data) | 1598 | int kvm_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data) |
1649 | { | 1599 | { |
1650 | return kvm_arch_ops->set_msr(vcpu, msr_index, data); | 1600 | return kvm_arch_ops->set_msr(vcpu, msr_index, data); |
1651 | } | 1601 | } |
@@ -2183,7 +2133,7 @@ static __init void kvm_init_msr_list(void) | |||
2183 | */ | 2133 | */ |
2184 | static int do_set_msr(struct kvm_vcpu *vcpu, unsigned index, u64 *data) | 2134 | static int do_set_msr(struct kvm_vcpu *vcpu, unsigned index, u64 *data) |
2185 | { | 2135 | { |
2186 | return set_msr(vcpu, index, *data); | 2136 | return kvm_set_msr(vcpu, index, *data); |
2187 | } | 2137 | } |
2188 | 2138 | ||
2189 | /* | 2139 | /* |
@@ -2667,7 +2617,7 @@ static long kvm_vcpu_ioctl(struct file *filp, | |||
2667 | break; | 2617 | break; |
2668 | } | 2618 | } |
2669 | case KVM_GET_MSRS: | 2619 | case KVM_GET_MSRS: |
2670 | r = msr_io(vcpu, argp, get_msr, 1); | 2620 | r = msr_io(vcpu, argp, kvm_get_msr, 1); |
2671 | break; | 2621 | break; |
2672 | case KVM_SET_MSRS: | 2622 | case KVM_SET_MSRS: |
2673 | r = msr_io(vcpu, argp, do_set_msr, 0); | 2623 | r = msr_io(vcpu, argp, do_set_msr, 0); |
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c index b297a6b111ac..d99d2fe53dca 100644 --- a/drivers/kvm/mmu.c +++ b/drivers/kvm/mmu.c | |||
@@ -154,7 +154,6 @@ struct kvm_rmap_desc { | |||
154 | 154 | ||
155 | static struct kmem_cache *pte_chain_cache; | 155 | static struct kmem_cache *pte_chain_cache; |
156 | static struct kmem_cache *rmap_desc_cache; | 156 | static struct kmem_cache *rmap_desc_cache; |
157 | static struct kmem_cache *mmu_page_cache; | ||
158 | static struct kmem_cache *mmu_page_header_cache; | 157 | static struct kmem_cache *mmu_page_header_cache; |
159 | 158 | ||
160 | static int is_write_protection(struct kvm_vcpu *vcpu) | 159 | static int is_write_protection(struct kvm_vcpu *vcpu) |
@@ -225,6 +224,29 @@ static void mmu_free_memory_cache(struct kvm_mmu_memory_cache *mc) | |||
225 | kfree(mc->objects[--mc->nobjs]); | 224 | kfree(mc->objects[--mc->nobjs]); |
226 | } | 225 | } |
227 | 226 | ||
227 | static int mmu_topup_memory_cache_page(struct kvm_mmu_memory_cache *cache, | ||
228 | int min, gfp_t gfp_flags) | ||
229 | { | ||
230 | struct page *page; | ||
231 | |||
232 | if (cache->nobjs >= min) | ||
233 | return 0; | ||
234 | while (cache->nobjs < ARRAY_SIZE(cache->objects)) { | ||
235 | page = alloc_page(gfp_flags); | ||
236 | if (!page) | ||
237 | return -ENOMEM; | ||
238 | set_page_private(page, 0); | ||
239 | cache->objects[cache->nobjs++] = page_address(page); | ||
240 | } | ||
241 | return 0; | ||
242 | } | ||
243 | |||
244 | static void mmu_free_memory_cache_page(struct kvm_mmu_memory_cache *mc) | ||
245 | { | ||
246 | while (mc->nobjs) | ||
247 | __free_page(mc->objects[--mc->nobjs]); | ||
248 | } | ||
249 | |||
228 | static int __mmu_topup_memory_caches(struct kvm_vcpu *vcpu, gfp_t gfp_flags) | 250 | static int __mmu_topup_memory_caches(struct kvm_vcpu *vcpu, gfp_t gfp_flags) |
229 | { | 251 | { |
230 | int r; | 252 | int r; |
@@ -237,8 +259,7 @@ static int __mmu_topup_memory_caches(struct kvm_vcpu *vcpu, gfp_t gfp_flags) | |||
237 | rmap_desc_cache, 1, gfp_flags); | 259 | rmap_desc_cache, 1, gfp_flags); |
238 | if (r) | 260 | if (r) |
239 | goto out; | 261 | goto out; |
240 | r = mmu_topup_memory_cache(&vcpu->mmu_page_cache, | 262 | r = mmu_topup_memory_cache_page(&vcpu->mmu_page_cache, 4, gfp_flags); |
241 | mmu_page_cache, 4, gfp_flags); | ||
242 | if (r) | 263 | if (r) |
243 | goto out; | 264 | goto out; |
244 | r = mmu_topup_memory_cache(&vcpu->mmu_page_header_cache, | 265 | r = mmu_topup_memory_cache(&vcpu->mmu_page_header_cache, |
@@ -266,7 +287,7 @@ static void mmu_free_memory_caches(struct kvm_vcpu *vcpu) | |||
266 | { | 287 | { |
267 | mmu_free_memory_cache(&vcpu->mmu_pte_chain_cache); | 288 | mmu_free_memory_cache(&vcpu->mmu_pte_chain_cache); |
268 | mmu_free_memory_cache(&vcpu->mmu_rmap_desc_cache); | 289 | mmu_free_memory_cache(&vcpu->mmu_rmap_desc_cache); |
269 | mmu_free_memory_cache(&vcpu->mmu_page_cache); | 290 | mmu_free_memory_cache_page(&vcpu->mmu_page_cache); |
270 | mmu_free_memory_cache(&vcpu->mmu_page_header_cache); | 291 | mmu_free_memory_cache(&vcpu->mmu_page_header_cache); |
271 | } | 292 | } |
272 | 293 | ||
@@ -281,24 +302,15 @@ static void *mmu_memory_cache_alloc(struct kvm_mmu_memory_cache *mc, | |||
281 | return p; | 302 | return p; |
282 | } | 303 | } |
283 | 304 | ||
284 | static void mmu_memory_cache_free(struct kvm_mmu_memory_cache *mc, void *obj) | ||
285 | { | ||
286 | if (mc->nobjs < KVM_NR_MEM_OBJS) | ||
287 | mc->objects[mc->nobjs++] = obj; | ||
288 | else | ||
289 | kfree(obj); | ||
290 | } | ||
291 | |||
292 | static struct kvm_pte_chain *mmu_alloc_pte_chain(struct kvm_vcpu *vcpu) | 305 | static struct kvm_pte_chain *mmu_alloc_pte_chain(struct kvm_vcpu *vcpu) |
293 | { | 306 | { |
294 | return mmu_memory_cache_alloc(&vcpu->mmu_pte_chain_cache, | 307 | return mmu_memory_cache_alloc(&vcpu->mmu_pte_chain_cache, |
295 | sizeof(struct kvm_pte_chain)); | 308 | sizeof(struct kvm_pte_chain)); |
296 | } | 309 | } |
297 | 310 | ||
298 | static void mmu_free_pte_chain(struct kvm_vcpu *vcpu, | 311 | static void mmu_free_pte_chain(struct kvm_pte_chain *pc) |
299 | struct kvm_pte_chain *pc) | ||
300 | { | 312 | { |
301 | mmu_memory_cache_free(&vcpu->mmu_pte_chain_cache, pc); | 313 | kfree(pc); |
302 | } | 314 | } |
303 | 315 | ||
304 | static struct kvm_rmap_desc *mmu_alloc_rmap_desc(struct kvm_vcpu *vcpu) | 316 | static struct kvm_rmap_desc *mmu_alloc_rmap_desc(struct kvm_vcpu *vcpu) |
@@ -307,10 +319,9 @@ static struct kvm_rmap_desc *mmu_alloc_rmap_desc(struct kvm_vcpu *vcpu) | |||
307 | sizeof(struct kvm_rmap_desc)); | 319 | sizeof(struct kvm_rmap_desc)); |
308 | } | 320 | } |
309 | 321 | ||
310 | static void mmu_free_rmap_desc(struct kvm_vcpu *vcpu, | 322 | static void mmu_free_rmap_desc(struct kvm_rmap_desc *rd) |
311 | struct kvm_rmap_desc *rd) | ||
312 | { | 323 | { |
313 | mmu_memory_cache_free(&vcpu->mmu_rmap_desc_cache, rd); | 324 | kfree(rd); |
314 | } | 325 | } |
315 | 326 | ||
316 | /* | 327 | /* |
@@ -355,8 +366,7 @@ static void rmap_add(struct kvm_vcpu *vcpu, u64 *spte) | |||
355 | } | 366 | } |
356 | } | 367 | } |
357 | 368 | ||
358 | static void rmap_desc_remove_entry(struct kvm_vcpu *vcpu, | 369 | static void rmap_desc_remove_entry(struct page *page, |
359 | struct page *page, | ||
360 | struct kvm_rmap_desc *desc, | 370 | struct kvm_rmap_desc *desc, |
361 | int i, | 371 | int i, |
362 | struct kvm_rmap_desc *prev_desc) | 372 | struct kvm_rmap_desc *prev_desc) |
@@ -376,10 +386,10 @@ static void rmap_desc_remove_entry(struct kvm_vcpu *vcpu, | |||
376 | prev_desc->more = desc->more; | 386 | prev_desc->more = desc->more; |
377 | else | 387 | else |
378 | set_page_private(page,(unsigned long)desc->more | 1); | 388 | set_page_private(page,(unsigned long)desc->more | 1); |
379 | mmu_free_rmap_desc(vcpu, desc); | 389 | mmu_free_rmap_desc(desc); |
380 | } | 390 | } |
381 | 391 | ||
382 | static void rmap_remove(struct kvm_vcpu *vcpu, u64 *spte) | 392 | static void rmap_remove(u64 *spte) |
383 | { | 393 | { |
384 | struct page *page; | 394 | struct page *page; |
385 | struct kvm_rmap_desc *desc; | 395 | struct kvm_rmap_desc *desc; |
@@ -407,7 +417,7 @@ static void rmap_remove(struct kvm_vcpu *vcpu, u64 *spte) | |||
407 | while (desc) { | 417 | while (desc) { |
408 | for (i = 0; i < RMAP_EXT && desc->shadow_ptes[i]; ++i) | 418 | for (i = 0; i < RMAP_EXT && desc->shadow_ptes[i]; ++i) |
409 | if (desc->shadow_ptes[i] == spte) { | 419 | if (desc->shadow_ptes[i] == spte) { |
410 | rmap_desc_remove_entry(vcpu, page, | 420 | rmap_desc_remove_entry(page, |
411 | desc, i, | 421 | desc, i, |
412 | prev_desc); | 422 | prev_desc); |
413 | return; | 423 | return; |
@@ -442,7 +452,7 @@ static void rmap_write_protect(struct kvm_vcpu *vcpu, u64 gfn) | |||
442 | BUG_ON(!(*spte & PT_PRESENT_MASK)); | 452 | BUG_ON(!(*spte & PT_PRESENT_MASK)); |
443 | BUG_ON(!(*spte & PT_WRITABLE_MASK)); | 453 | BUG_ON(!(*spte & PT_WRITABLE_MASK)); |
444 | rmap_printk("rmap_write_protect: spte %p %llx\n", spte, *spte); | 454 | rmap_printk("rmap_write_protect: spte %p %llx\n", spte, *spte); |
445 | rmap_remove(vcpu, spte); | 455 | rmap_remove(spte); |
446 | set_shadow_pte(spte, *spte & ~PT_WRITABLE_MASK); | 456 | set_shadow_pte(spte, *spte & ~PT_WRITABLE_MASK); |
447 | kvm_flush_remote_tlbs(vcpu->kvm); | 457 | kvm_flush_remote_tlbs(vcpu->kvm); |
448 | } | 458 | } |
@@ -464,14 +474,14 @@ static int is_empty_shadow_page(u64 *spt) | |||
464 | } | 474 | } |
465 | #endif | 475 | #endif |
466 | 476 | ||
467 | static void kvm_mmu_free_page(struct kvm_vcpu *vcpu, | 477 | static void kvm_mmu_free_page(struct kvm *kvm, |
468 | struct kvm_mmu_page *page_head) | 478 | struct kvm_mmu_page *page_head) |
469 | { | 479 | { |
470 | ASSERT(is_empty_shadow_page(page_head->spt)); | 480 | ASSERT(is_empty_shadow_page(page_head->spt)); |
471 | list_del(&page_head->link); | 481 | list_del(&page_head->link); |
472 | mmu_memory_cache_free(&vcpu->mmu_page_cache, page_head->spt); | 482 | __free_page(virt_to_page(page_head->spt)); |
473 | mmu_memory_cache_free(&vcpu->mmu_page_header_cache, page_head); | 483 | kfree(page_head); |
474 | ++vcpu->kvm->n_free_mmu_pages; | 484 | ++kvm->n_free_mmu_pages; |
475 | } | 485 | } |
476 | 486 | ||
477 | static unsigned kvm_page_table_hashfn(gfn_t gfn) | 487 | static unsigned kvm_page_table_hashfn(gfn_t gfn) |
@@ -537,8 +547,7 @@ static void mmu_page_add_parent_pte(struct kvm_vcpu *vcpu, | |||
537 | pte_chain->parent_ptes[0] = parent_pte; | 547 | pte_chain->parent_ptes[0] = parent_pte; |
538 | } | 548 | } |
539 | 549 | ||
540 | static void mmu_page_remove_parent_pte(struct kvm_vcpu *vcpu, | 550 | static void mmu_page_remove_parent_pte(struct kvm_mmu_page *page, |
541 | struct kvm_mmu_page *page, | ||
542 | u64 *parent_pte) | 551 | u64 *parent_pte) |
543 | { | 552 | { |
544 | struct kvm_pte_chain *pte_chain; | 553 | struct kvm_pte_chain *pte_chain; |
@@ -565,7 +574,7 @@ static void mmu_page_remove_parent_pte(struct kvm_vcpu *vcpu, | |||
565 | pte_chain->parent_ptes[i] = NULL; | 574 | pte_chain->parent_ptes[i] = NULL; |
566 | if (i == 0) { | 575 | if (i == 0) { |
567 | hlist_del(&pte_chain->link); | 576 | hlist_del(&pte_chain->link); |
568 | mmu_free_pte_chain(vcpu, pte_chain); | 577 | mmu_free_pte_chain(pte_chain); |
569 | if (hlist_empty(&page->parent_ptes)) { | 578 | if (hlist_empty(&page->parent_ptes)) { |
570 | page->multimapped = 0; | 579 | page->multimapped = 0; |
571 | page->parent_pte = NULL; | 580 | page->parent_pte = NULL; |
@@ -643,7 +652,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, | |||
643 | return page; | 652 | return page; |
644 | } | 653 | } |
645 | 654 | ||
646 | static void kvm_mmu_page_unlink_children(struct kvm_vcpu *vcpu, | 655 | static void kvm_mmu_page_unlink_children(struct kvm *kvm, |
647 | struct kvm_mmu_page *page) | 656 | struct kvm_mmu_page *page) |
648 | { | 657 | { |
649 | unsigned i; | 658 | unsigned i; |
@@ -655,10 +664,10 @@ static void kvm_mmu_page_unlink_children(struct kvm_vcpu *vcpu, | |||
655 | if (page->role.level == PT_PAGE_TABLE_LEVEL) { | 664 | if (page->role.level == PT_PAGE_TABLE_LEVEL) { |
656 | for (i = 0; i < PT64_ENT_PER_PAGE; ++i) { | 665 | for (i = 0; i < PT64_ENT_PER_PAGE; ++i) { |
657 | if (pt[i] & PT_PRESENT_MASK) | 666 | if (pt[i] & PT_PRESENT_MASK) |
658 | rmap_remove(vcpu, &pt[i]); | 667 | rmap_remove(&pt[i]); |
659 | pt[i] = 0; | 668 | pt[i] = 0; |
660 | } | 669 | } |
661 | kvm_flush_remote_tlbs(vcpu->kvm); | 670 | kvm_flush_remote_tlbs(kvm); |
662 | return; | 671 | return; |
663 | } | 672 | } |
664 | 673 | ||
@@ -669,19 +678,18 @@ static void kvm_mmu_page_unlink_children(struct kvm_vcpu *vcpu, | |||
669 | if (!(ent & PT_PRESENT_MASK)) | 678 | if (!(ent & PT_PRESENT_MASK)) |
670 | continue; | 679 | continue; |
671 | ent &= PT64_BASE_ADDR_MASK; | 680 | ent &= PT64_BASE_ADDR_MASK; |
672 | mmu_page_remove_parent_pte(vcpu, page_header(ent), &pt[i]); | 681 | mmu_page_remove_parent_pte(page_header(ent), &pt[i]); |
673 | } | 682 | } |
674 | kvm_flush_remote_tlbs(vcpu->kvm); | 683 | kvm_flush_remote_tlbs(kvm); |
675 | } | 684 | } |
676 | 685 | ||
677 | static void kvm_mmu_put_page(struct kvm_vcpu *vcpu, | 686 | static void kvm_mmu_put_page(struct kvm_mmu_page *page, |
678 | struct kvm_mmu_page *page, | ||
679 | u64 *parent_pte) | 687 | u64 *parent_pte) |
680 | { | 688 | { |
681 | mmu_page_remove_parent_pte(vcpu, page, parent_pte); | 689 | mmu_page_remove_parent_pte(page, parent_pte); |
682 | } | 690 | } |
683 | 691 | ||
684 | static void kvm_mmu_zap_page(struct kvm_vcpu *vcpu, | 692 | static void kvm_mmu_zap_page(struct kvm *kvm, |
685 | struct kvm_mmu_page *page) | 693 | struct kvm_mmu_page *page) |
686 | { | 694 | { |
687 | u64 *parent_pte; | 695 | u64 *parent_pte; |
@@ -697,15 +705,15 @@ static void kvm_mmu_zap_page(struct kvm_vcpu *vcpu, | |||
697 | parent_pte = chain->parent_ptes[0]; | 705 | parent_pte = chain->parent_ptes[0]; |
698 | } | 706 | } |
699 | BUG_ON(!parent_pte); | 707 | BUG_ON(!parent_pte); |
700 | kvm_mmu_put_page(vcpu, page, parent_pte); | 708 | kvm_mmu_put_page(page, parent_pte); |
701 | set_shadow_pte(parent_pte, 0); | 709 | set_shadow_pte(parent_pte, 0); |
702 | } | 710 | } |
703 | kvm_mmu_page_unlink_children(vcpu, page); | 711 | kvm_mmu_page_unlink_children(kvm, page); |
704 | if (!page->root_count) { | 712 | if (!page->root_count) { |
705 | hlist_del(&page->hash_link); | 713 | hlist_del(&page->hash_link); |
706 | kvm_mmu_free_page(vcpu, page); | 714 | kvm_mmu_free_page(kvm, page); |
707 | } else | 715 | } else |
708 | list_move(&page->link, &vcpu->kvm->active_mmu_pages); | 716 | list_move(&page->link, &kvm->active_mmu_pages); |
709 | } | 717 | } |
710 | 718 | ||
711 | static int kvm_mmu_unprotect_page(struct kvm_vcpu *vcpu, gfn_t gfn) | 719 | static int kvm_mmu_unprotect_page(struct kvm_vcpu *vcpu, gfn_t gfn) |
@@ -724,7 +732,7 @@ static int kvm_mmu_unprotect_page(struct kvm_vcpu *vcpu, gfn_t gfn) | |||
724 | if (page->gfn == gfn && !page->role.metaphysical) { | 732 | if (page->gfn == gfn && !page->role.metaphysical) { |
725 | pgprintk("%s: gfn %lx role %x\n", __FUNCTION__, gfn, | 733 | pgprintk("%s: gfn %lx role %x\n", __FUNCTION__, gfn, |
726 | page->role.word); | 734 | page->role.word); |
727 | kvm_mmu_zap_page(vcpu, page); | 735 | kvm_mmu_zap_page(vcpu->kvm, page); |
728 | r = 1; | 736 | r = 1; |
729 | } | 737 | } |
730 | return r; | 738 | return r; |
@@ -737,7 +745,7 @@ static void mmu_unshadow(struct kvm_vcpu *vcpu, gfn_t gfn) | |||
737 | while ((page = kvm_mmu_lookup_page(vcpu, gfn)) != NULL) { | 745 | while ((page = kvm_mmu_lookup_page(vcpu, gfn)) != NULL) { |
738 | pgprintk("%s: zap %lx %x\n", | 746 | pgprintk("%s: zap %lx %x\n", |
739 | __FUNCTION__, gfn, page->role.word); | 747 | __FUNCTION__, gfn, page->role.word); |
740 | kvm_mmu_zap_page(vcpu, page); | 748 | kvm_mmu_zap_page(vcpu->kvm, page); |
741 | } | 749 | } |
742 | } | 750 | } |
743 | 751 | ||
@@ -1089,10 +1097,10 @@ static void mmu_pte_write_zap_pte(struct kvm_vcpu *vcpu, | |||
1089 | pte = *spte; | 1097 | pte = *spte; |
1090 | if (is_present_pte(pte)) { | 1098 | if (is_present_pte(pte)) { |
1091 | if (page->role.level == PT_PAGE_TABLE_LEVEL) | 1099 | if (page->role.level == PT_PAGE_TABLE_LEVEL) |
1092 | rmap_remove(vcpu, spte); | 1100 | rmap_remove(spte); |
1093 | else { | 1101 | else { |
1094 | child = page_header(pte & PT64_BASE_ADDR_MASK); | 1102 | child = page_header(pte & PT64_BASE_ADDR_MASK); |
1095 | mmu_page_remove_parent_pte(vcpu, child, spte); | 1103 | mmu_page_remove_parent_pte(child, spte); |
1096 | } | 1104 | } |
1097 | } | 1105 | } |
1098 | *spte = 0; | 1106 | *spte = 0; |
@@ -1161,7 +1169,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa, | |||
1161 | */ | 1169 | */ |
1162 | pgprintk("misaligned: gpa %llx bytes %d role %x\n", | 1170 | pgprintk("misaligned: gpa %llx bytes %d role %x\n", |
1163 | gpa, bytes, page->role.word); | 1171 | gpa, bytes, page->role.word); |
1164 | kvm_mmu_zap_page(vcpu, page); | 1172 | kvm_mmu_zap_page(vcpu->kvm, page); |
1165 | continue; | 1173 | continue; |
1166 | } | 1174 | } |
1167 | page_offset = offset; | 1175 | page_offset = offset; |
@@ -1207,7 +1215,7 @@ void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu) | |||
1207 | 1215 | ||
1208 | page = container_of(vcpu->kvm->active_mmu_pages.prev, | 1216 | page = container_of(vcpu->kvm->active_mmu_pages.prev, |
1209 | struct kvm_mmu_page, link); | 1217 | struct kvm_mmu_page, link); |
1210 | kvm_mmu_zap_page(vcpu, page); | 1218 | kvm_mmu_zap_page(vcpu->kvm, page); |
1211 | } | 1219 | } |
1212 | } | 1220 | } |
1213 | EXPORT_SYMBOL_GPL(kvm_mmu_free_some_pages); | 1221 | EXPORT_SYMBOL_GPL(kvm_mmu_free_some_pages); |
@@ -1219,7 +1227,7 @@ static void free_mmu_pages(struct kvm_vcpu *vcpu) | |||
1219 | while (!list_empty(&vcpu->kvm->active_mmu_pages)) { | 1227 | while (!list_empty(&vcpu->kvm->active_mmu_pages)) { |
1220 | page = container_of(vcpu->kvm->active_mmu_pages.next, | 1228 | page = container_of(vcpu->kvm->active_mmu_pages.next, |
1221 | struct kvm_mmu_page, link); | 1229 | struct kvm_mmu_page, link); |
1222 | kvm_mmu_zap_page(vcpu, page); | 1230 | kvm_mmu_zap_page(vcpu->kvm, page); |
1223 | } | 1231 | } |
1224 | free_page((unsigned long)vcpu->mmu.pae_root); | 1232 | free_page((unsigned long)vcpu->mmu.pae_root); |
1225 | } | 1233 | } |
@@ -1277,9 +1285,8 @@ void kvm_mmu_destroy(struct kvm_vcpu *vcpu) | |||
1277 | mmu_free_memory_caches(vcpu); | 1285 | mmu_free_memory_caches(vcpu); |
1278 | } | 1286 | } |
1279 | 1287 | ||
1280 | void kvm_mmu_slot_remove_write_access(struct kvm_vcpu *vcpu, int slot) | 1288 | void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot) |
1281 | { | 1289 | { |
1282 | struct kvm *kvm = vcpu->kvm; | ||
1283 | struct kvm_mmu_page *page; | 1290 | struct kvm_mmu_page *page; |
1284 | 1291 | ||
1285 | list_for_each_entry(page, &kvm->active_mmu_pages, link) { | 1292 | list_for_each_entry(page, &kvm->active_mmu_pages, link) { |
@@ -1293,27 +1300,20 @@ void kvm_mmu_slot_remove_write_access(struct kvm_vcpu *vcpu, int slot) | |||
1293 | for (i = 0; i < PT64_ENT_PER_PAGE; ++i) | 1300 | for (i = 0; i < PT64_ENT_PER_PAGE; ++i) |
1294 | /* avoid RMW */ | 1301 | /* avoid RMW */ |
1295 | if (pt[i] & PT_WRITABLE_MASK) { | 1302 | if (pt[i] & PT_WRITABLE_MASK) { |
1296 | rmap_remove(vcpu, &pt[i]); | 1303 | rmap_remove(&pt[i]); |
1297 | pt[i] &= ~PT_WRITABLE_MASK; | 1304 | pt[i] &= ~PT_WRITABLE_MASK; |
1298 | } | 1305 | } |
1299 | } | 1306 | } |
1300 | } | 1307 | } |
1301 | 1308 | ||
1302 | void kvm_mmu_zap_all(struct kvm_vcpu *vcpu) | 1309 | void kvm_mmu_zap_all(struct kvm *kvm) |
1303 | { | 1310 | { |
1304 | destroy_kvm_mmu(vcpu); | 1311 | struct kvm_mmu_page *page, *node; |
1305 | |||
1306 | while (!list_empty(&vcpu->kvm->active_mmu_pages)) { | ||
1307 | struct kvm_mmu_page *page; | ||
1308 | 1312 | ||
1309 | page = container_of(vcpu->kvm->active_mmu_pages.next, | 1313 | list_for_each_entry_safe(page, node, &kvm->active_mmu_pages, link) |
1310 | struct kvm_mmu_page, link); | 1314 | kvm_mmu_zap_page(kvm, page); |
1311 | kvm_mmu_zap_page(vcpu, page); | ||
1312 | } | ||
1313 | 1315 | ||
1314 | mmu_free_memory_caches(vcpu); | 1316 | kvm_flush_remote_tlbs(kvm); |
1315 | kvm_flush_remote_tlbs(vcpu->kvm); | ||
1316 | init_kvm_mmu(vcpu); | ||
1317 | } | 1317 | } |
1318 | 1318 | ||
1319 | void kvm_mmu_module_exit(void) | 1319 | void kvm_mmu_module_exit(void) |
@@ -1322,8 +1322,6 @@ void kvm_mmu_module_exit(void) | |||
1322 | kmem_cache_destroy(pte_chain_cache); | 1322 | kmem_cache_destroy(pte_chain_cache); |
1323 | if (rmap_desc_cache) | 1323 | if (rmap_desc_cache) |
1324 | kmem_cache_destroy(rmap_desc_cache); | 1324 | kmem_cache_destroy(rmap_desc_cache); |
1325 | if (mmu_page_cache) | ||
1326 | kmem_cache_destroy(mmu_page_cache); | ||
1327 | if (mmu_page_header_cache) | 1325 | if (mmu_page_header_cache) |
1328 | kmem_cache_destroy(mmu_page_header_cache); | 1326 | kmem_cache_destroy(mmu_page_header_cache); |
1329 | } | 1327 | } |
@@ -1332,24 +1330,18 @@ int kvm_mmu_module_init(void) | |||
1332 | { | 1330 | { |
1333 | pte_chain_cache = kmem_cache_create("kvm_pte_chain", | 1331 | pte_chain_cache = kmem_cache_create("kvm_pte_chain", |
1334 | sizeof(struct kvm_pte_chain), | 1332 | sizeof(struct kvm_pte_chain), |
1335 | 0, 0, NULL, NULL); | 1333 | 0, 0, NULL); |
1336 | if (!pte_chain_cache) | 1334 | if (!pte_chain_cache) |
1337 | goto nomem; | 1335 | goto nomem; |
1338 | rmap_desc_cache = kmem_cache_create("kvm_rmap_desc", | 1336 | rmap_desc_cache = kmem_cache_create("kvm_rmap_desc", |
1339 | sizeof(struct kvm_rmap_desc), | 1337 | sizeof(struct kvm_rmap_desc), |
1340 | 0, 0, NULL, NULL); | 1338 | 0, 0, NULL); |
1341 | if (!rmap_desc_cache) | 1339 | if (!rmap_desc_cache) |
1342 | goto nomem; | 1340 | goto nomem; |
1343 | 1341 | ||
1344 | mmu_page_cache = kmem_cache_create("kvm_mmu_page", | ||
1345 | PAGE_SIZE, | ||
1346 | PAGE_SIZE, 0, NULL, NULL); | ||
1347 | if (!mmu_page_cache) | ||
1348 | goto nomem; | ||
1349 | |||
1350 | mmu_page_header_cache = kmem_cache_create("kvm_mmu_page_header", | 1342 | mmu_page_header_cache = kmem_cache_create("kvm_mmu_page_header", |
1351 | sizeof(struct kvm_mmu_page), | 1343 | sizeof(struct kvm_mmu_page), |
1352 | 0, 0, NULL, NULL); | 1344 | 0, 0, NULL); |
1353 | if (!mmu_page_header_cache) | 1345 | if (!mmu_page_header_cache) |
1354 | goto nomem; | 1346 | goto nomem; |
1355 | 1347 | ||
diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h index a7c5cb0319ea..4b5391c717f8 100644 --- a/drivers/kvm/paging_tmpl.h +++ b/drivers/kvm/paging_tmpl.h | |||
@@ -366,6 +366,8 @@ static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr, | |||
366 | metaphysical = 1; | 366 | metaphysical = 1; |
367 | hugepage_access = *guest_ent; | 367 | hugepage_access = *guest_ent; |
368 | hugepage_access &= PT_USER_MASK | PT_WRITABLE_MASK; | 368 | hugepage_access &= PT_USER_MASK | PT_WRITABLE_MASK; |
369 | if (*guest_ent & PT64_NX_MASK) | ||
370 | hugepage_access |= (1 << 2); | ||
369 | hugepage_access >>= PT_WRITABLE_SHIFT; | 371 | hugepage_access >>= PT_WRITABLE_SHIFT; |
370 | table_gfn = (*guest_ent & PT_BASE_ADDR_MASK) | 372 | table_gfn = (*guest_ent & PT_BASE_ADDR_MASK) |
371 | >> PAGE_SHIFT; | 373 | >> PAGE_SHIFT; |
diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c index f60012d62610..1b800fc00342 100644 --- a/drivers/kvm/x86_emulate.c +++ b/drivers/kvm/x86_emulate.c | |||
@@ -163,7 +163,7 @@ static u16 twobyte_table[256] = { | |||
163 | ModRM | ImplicitOps, ModRM, ModRM | ImplicitOps, ModRM, 0, 0, 0, 0, | 163 | ModRM | ImplicitOps, ModRM, ModRM | ImplicitOps, ModRM, 0, 0, 0, 0, |
164 | 0, 0, 0, 0, 0, 0, 0, 0, | 164 | 0, 0, 0, 0, 0, 0, 0, 0, |
165 | /* 0x30 - 0x3F */ | 165 | /* 0x30 - 0x3F */ |
166 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 166 | ImplicitOps, 0, ImplicitOps, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
167 | /* 0x40 - 0x47 */ | 167 | /* 0x40 - 0x47 */ |
168 | DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov, | 168 | DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov, |
169 | DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov, | 169 | DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov, |
@@ -486,6 +486,7 @@ x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) | |||
486 | unsigned long modrm_ea; | 486 | unsigned long modrm_ea; |
487 | int use_modrm_ea, index_reg = 0, base_reg = 0, scale, rip_relative = 0; | 487 | int use_modrm_ea, index_reg = 0, base_reg = 0, scale, rip_relative = 0; |
488 | int no_wb = 0; | 488 | int no_wb = 0; |
489 | u64 msr_data; | ||
489 | 490 | ||
490 | /* Shadow copy of register state. Committed on successful emulation. */ | 491 | /* Shadow copy of register state. Committed on successful emulation. */ |
491 | unsigned long _regs[NR_VCPU_REGS]; | 492 | unsigned long _regs[NR_VCPU_REGS]; |
@@ -1344,6 +1345,29 @@ twobyte_special_insn: | |||
1344 | goto cannot_emulate; | 1345 | goto cannot_emulate; |
1345 | realmode_set_cr(ctxt->vcpu, modrm_reg, modrm_val, &_eflags); | 1346 | realmode_set_cr(ctxt->vcpu, modrm_reg, modrm_val, &_eflags); |
1346 | break; | 1347 | break; |
1348 | case 0x30: | ||
1349 | /* wrmsr */ | ||
1350 | msr_data = (u32)_regs[VCPU_REGS_RAX] | ||
1351 | | ((u64)_regs[VCPU_REGS_RDX] << 32); | ||
1352 | rc = kvm_set_msr(ctxt->vcpu, _regs[VCPU_REGS_RCX], msr_data); | ||
1353 | if (rc) { | ||
1354 | kvm_arch_ops->inject_gp(ctxt->vcpu, 0); | ||
1355 | _eip = ctxt->vcpu->rip; | ||
1356 | } | ||
1357 | rc = X86EMUL_CONTINUE; | ||
1358 | break; | ||
1359 | case 0x32: | ||
1360 | /* rdmsr */ | ||
1361 | rc = kvm_get_msr(ctxt->vcpu, _regs[VCPU_REGS_RCX], &msr_data); | ||
1362 | if (rc) { | ||
1363 | kvm_arch_ops->inject_gp(ctxt->vcpu, 0); | ||
1364 | _eip = ctxt->vcpu->rip; | ||
1365 | } else { | ||
1366 | _regs[VCPU_REGS_RAX] = (u32)msr_data; | ||
1367 | _regs[VCPU_REGS_RDX] = msr_data >> 32; | ||
1368 | } | ||
1369 | rc = X86EMUL_CONTINUE; | ||
1370 | break; | ||
1347 | case 0xc7: /* Grp9 (cmpxchg8b) */ | 1371 | case 0xc7: /* Grp9 (cmpxchg8b) */ |
1348 | { | 1372 | { |
1349 | u64 old, new; | 1373 | u64 old, new; |
diff --git a/drivers/lguest/interrupts_and_traps.c b/drivers/lguest/interrupts_and_traps.c index d9de5bbc613f..bee029bb2c7b 100644 --- a/drivers/lguest/interrupts_and_traps.c +++ b/drivers/lguest/interrupts_and_traps.c | |||
@@ -38,12 +38,12 @@ static void set_guest_interrupt(struct lguest *lg, u32 lo, u32 hi, int has_err) | |||
38 | ss = lg->regs->ss; | 38 | ss = lg->regs->ss; |
39 | } | 39 | } |
40 | 40 | ||
41 | /* We use IF bit in eflags to indicate whether irqs were disabled | 41 | /* We use IF bit in eflags to indicate whether irqs were enabled |
42 | (it's always 0, since irqs are enabled when guest is running). */ | 42 | (it's always 1, since irqs are enabled when guest is running). */ |
43 | eflags = lg->regs->eflags; | 43 | eflags = lg->regs->eflags; |
44 | if (get_user(irq_enable, &lg->lguest_data->irq_enabled)) | 44 | if (get_user(irq_enable, &lg->lguest_data->irq_enabled) == 0 |
45 | irq_enable = 0; | 45 | && !(irq_enable & X86_EFLAGS_IF)) |
46 | eflags |= (irq_enable & X86_EFLAGS_IF); | 46 | eflags &= ~X86_EFLAGS_IF; |
47 | 47 | ||
48 | push_guest_stack(lg, &gstack, eflags); | 48 | push_guest_stack(lg, &gstack, eflags); |
49 | push_guest_stack(lg, &gstack, lg->regs->cs); | 49 | push_guest_stack(lg, &gstack, lg->regs->cs); |
diff --git a/drivers/lguest/io.c b/drivers/lguest/io.c index 06bdba2337ef..c8eb79266991 100644 --- a/drivers/lguest/io.c +++ b/drivers/lguest/io.c | |||
@@ -187,7 +187,7 @@ static u32 copy_data(struct lguest *srclg, | |||
187 | /* FIXME: This is not completely portable, since | 187 | /* FIXME: This is not completely portable, since |
188 | archs do different things for copy_to_user_page. */ | 188 | archs do different things for copy_to_user_page. */ |
189 | if (copy_from_user(maddr + (dst->addr[di] + dstoff)%PAGE_SIZE, | 189 | if (copy_from_user(maddr + (dst->addr[di] + dstoff)%PAGE_SIZE, |
190 | (void *__user)src->addr[si], len) != 0) { | 190 | (void __user *)src->addr[si], len) != 0) { |
191 | kill_guest(srclg, "bad address in sending DMA"); | 191 | kill_guest(srclg, "bad address in sending DMA"); |
192 | totlen = 0; | 192 | totlen = 0; |
193 | break; | 193 | break; |
diff --git a/drivers/lguest/lguest.c b/drivers/lguest/lguest.c index b9a58b78c990..434fea1e82f7 100644 --- a/drivers/lguest/lguest.c +++ b/drivers/lguest/lguest.c | |||
@@ -39,7 +39,6 @@ | |||
39 | #include <asm/e820.h> | 39 | #include <asm/e820.h> |
40 | #include <asm/mce.h> | 40 | #include <asm/mce.h> |
41 | #include <asm/io.h> | 41 | #include <asm/io.h> |
42 | //#include <asm/sched-clock.h> | ||
43 | 42 | ||
44 | /* Declarations for definitions in lguest_guest.S */ | 43 | /* Declarations for definitions in lguest_guest.S */ |
45 | extern char lguest_noirq_start[], lguest_noirq_end[]; | 44 | extern char lguest_noirq_start[], lguest_noirq_end[]; |
@@ -57,6 +56,7 @@ struct lguest_data lguest_data = { | |||
57 | .blocked_interrupts = { 1 }, /* Block timer interrupts */ | 56 | .blocked_interrupts = { 1 }, /* Block timer interrupts */ |
58 | }; | 57 | }; |
59 | struct lguest_device_desc *lguest_devices; | 58 | struct lguest_device_desc *lguest_devices; |
59 | static cycle_t clock_base; | ||
60 | 60 | ||
61 | static enum paravirt_lazy_mode lazy_mode; | 61 | static enum paravirt_lazy_mode lazy_mode; |
62 | static void lguest_lazy_mode(enum paravirt_lazy_mode mode) | 62 | static void lguest_lazy_mode(enum paravirt_lazy_mode mode) |
@@ -363,6 +363,11 @@ static struct clocksource lguest_clock = { | |||
363 | .read = lguest_clock_read, | 363 | .read = lguest_clock_read, |
364 | }; | 364 | }; |
365 | 365 | ||
366 | static unsigned long long lguest_sched_clock(void) | ||
367 | { | ||
368 | return cyc2ns(&lguest_clock, lguest_clock_read() - clock_base); | ||
369 | } | ||
370 | |||
366 | /* We also need a "struct clock_event_device": Linux asks us to set it to go | 371 | /* We also need a "struct clock_event_device": Linux asks us to set it to go |
367 | * off some time in the future. Actually, James Morris figured all this out, I | 372 | * off some time in the future. Actually, James Morris figured all this out, I |
368 | * just applied the patch. */ | 373 | * just applied the patch. */ |
@@ -439,6 +444,7 @@ static void lguest_time_init(void) | |||
439 | lguest_clock.mult = (((u64)NSEC_PER_SEC<<8)/ACTHZ) << 8; | 444 | lguest_clock.mult = (((u64)NSEC_PER_SEC<<8)/ACTHZ) << 8; |
440 | lguest_clock.mask = CLOCKSOURCE_MASK(32); | 445 | lguest_clock.mask = CLOCKSOURCE_MASK(32); |
441 | } | 446 | } |
447 | clock_base = lguest_clock_read(); | ||
442 | clocksource_register(&lguest_clock); | 448 | clocksource_register(&lguest_clock); |
443 | 449 | ||
444 | /* We can't set cpumask in the initializer: damn C limitations! */ | 450 | /* We can't set cpumask in the initializer: damn C limitations! */ |
@@ -584,6 +590,7 @@ __init void lguest_init(void *boot) | |||
584 | paravirt_ops.time_init = lguest_time_init; | 590 | paravirt_ops.time_init = lguest_time_init; |
585 | paravirt_ops.set_lazy_mode = lguest_lazy_mode; | 591 | paravirt_ops.set_lazy_mode = lguest_lazy_mode; |
586 | paravirt_ops.wbinvd = lguest_wbinvd; | 592 | paravirt_ops.wbinvd = lguest_wbinvd; |
593 | paravirt_ops.sched_clock = lguest_sched_clock; | ||
587 | 594 | ||
588 | hcall(LHCALL_LGUEST_INIT, __pa(&lguest_data), 0, 0); | 595 | hcall(LHCALL_LGUEST_INIT, __pa(&lguest_data), 0, 0); |
589 | 596 | ||
diff --git a/drivers/lguest/lguest_asm.S b/drivers/lguest/lguest_asm.S index 00046c57b5ba..a3dbf22ee365 100644 --- a/drivers/lguest/lguest_asm.S +++ b/drivers/lguest/lguest_asm.S | |||
@@ -2,9 +2,7 @@ | |||
2 | #include <linux/lguest.h> | 2 | #include <linux/lguest.h> |
3 | #include <asm/asm-offsets.h> | 3 | #include <asm/asm-offsets.h> |
4 | #include <asm/thread_info.h> | 4 | #include <asm/thread_info.h> |
5 | 5 | #include <asm/processor-flags.h> | |
6 | /* FIXME: Once asm/processor-flags.h goes in, include that */ | ||
7 | #define X86_EFLAGS_IF 0x00000200 | ||
8 | 6 | ||
9 | /* | 7 | /* |
10 | * This is where we begin: we have a magic signature which the launcher looks | 8 | * This is where we begin: we have a magic signature which the launcher looks |
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 0b66afef2d82..d90ee145effe 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c | |||
@@ -493,12 +493,12 @@ async_copy_data(int frombio, struct bio *bio, struct page *page, | |||
493 | if (frombio) | 493 | if (frombio) |
494 | tx = async_memcpy(page, bio_page, page_offset, | 494 | tx = async_memcpy(page, bio_page, page_offset, |
495 | b_offset, clen, | 495 | b_offset, clen, |
496 | ASYNC_TX_DEP_ACK | ASYNC_TX_KMAP_SRC, | 496 | ASYNC_TX_DEP_ACK, |
497 | tx, NULL, NULL); | 497 | tx, NULL, NULL); |
498 | else | 498 | else |
499 | tx = async_memcpy(bio_page, page, b_offset, | 499 | tx = async_memcpy(bio_page, page, b_offset, |
500 | page_offset, clen, | 500 | page_offset, clen, |
501 | ASYNC_TX_DEP_ACK | ASYNC_TX_KMAP_DST, | 501 | ASYNC_TX_DEP_ACK, |
502 | tx, NULL, NULL); | 502 | tx, NULL, NULL); |
503 | } | 503 | } |
504 | if (clen < len) /* hit end of page */ | 504 | if (clen < len) /* hit end of page */ |
@@ -951,7 +951,7 @@ static int grow_stripes(raid5_conf_t *conf, int num) | |||
951 | conf->active_name = 0; | 951 | conf->active_name = 0; |
952 | sc = kmem_cache_create(conf->cache_name[conf->active_name], | 952 | sc = kmem_cache_create(conf->cache_name[conf->active_name], |
953 | sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev), | 953 | sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev), |
954 | 0, 0, NULL, NULL); | 954 | 0, 0, NULL); |
955 | if (!sc) | 955 | if (!sc) |
956 | return 1; | 956 | return 1; |
957 | conf->slab_cache = sc; | 957 | conf->slab_cache = sc; |
@@ -1003,7 +1003,7 @@ static int resize_stripes(raid5_conf_t *conf, int newsize) | |||
1003 | /* Step 1 */ | 1003 | /* Step 1 */ |
1004 | sc = kmem_cache_create(conf->cache_name[1-conf->active_name], | 1004 | sc = kmem_cache_create(conf->cache_name[1-conf->active_name], |
1005 | sizeof(struct stripe_head)+(newsize-1)*sizeof(struct r5dev), | 1005 | sizeof(struct stripe_head)+(newsize-1)*sizeof(struct r5dev), |
1006 | 0, 0, NULL, NULL); | 1006 | 0, 0, NULL); |
1007 | if (!sc) | 1007 | if (!sc) |
1008 | return -ENOMEM; | 1008 | return -ENOMEM; |
1009 | 1009 | ||
diff --git a/drivers/message/i2o/i2o_block.c b/drivers/message/i2o/i2o_block.c index 64a52bd7544a..988c8ce47f58 100644 --- a/drivers/message/i2o/i2o_block.c +++ b/drivers/message/i2o/i2o_block.c | |||
@@ -1171,8 +1171,7 @@ static int __init i2o_block_init(void) | |||
1171 | /* Allocate request mempool and slab */ | 1171 | /* Allocate request mempool and slab */ |
1172 | size = sizeof(struct i2o_block_request); | 1172 | size = sizeof(struct i2o_block_request); |
1173 | i2o_blk_req_pool.slab = kmem_cache_create("i2o_block_req", size, 0, | 1173 | i2o_blk_req_pool.slab = kmem_cache_create("i2o_block_req", size, 0, |
1174 | SLAB_HWCACHE_ALIGN, NULL, | 1174 | SLAB_HWCACHE_ALIGN, NULL); |
1175 | NULL); | ||
1176 | if (!i2o_blk_req_pool.slab) { | 1175 | if (!i2o_blk_req_pool.slab) { |
1177 | osm_err("can't init request slab\n"); | 1176 | osm_err("can't init request slab\n"); |
1178 | rc = -ENOMEM; | 1177 | rc = -ENOMEM; |
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c index 8aff9385613f..7c5e29eaf118 100644 --- a/drivers/mtd/ubi/eba.c +++ b/drivers/mtd/ubi/eba.c | |||
@@ -1149,7 +1149,7 @@ int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
1149 | if (ubi_devices_cnt == 0) { | 1149 | if (ubi_devices_cnt == 0) { |
1150 | ltree_slab = kmem_cache_create("ubi_ltree_slab", | 1150 | ltree_slab = kmem_cache_create("ubi_ltree_slab", |
1151 | sizeof(struct ltree_entry), 0, | 1151 | sizeof(struct ltree_entry), 0, |
1152 | 0, <ree_entry_ctor, NULL); | 1152 | 0, <ree_entry_ctor); |
1153 | if (!ltree_slab) | 1153 | if (!ltree_slab) |
1154 | return -ENOMEM; | 1154 | return -ENOMEM; |
1155 | } | 1155 | } |
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c index 9de953762097..a5a9b8d87302 100644 --- a/drivers/mtd/ubi/wl.c +++ b/drivers/mtd/ubi/wl.c | |||
@@ -1452,7 +1452,7 @@ int ubi_wl_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
1452 | if (ubi_devices_cnt == 0) { | 1452 | if (ubi_devices_cnt == 0) { |
1453 | wl_entries_slab = kmem_cache_create("ubi_wl_entry_slab", | 1453 | wl_entries_slab = kmem_cache_create("ubi_wl_entry_slab", |
1454 | sizeof(struct ubi_wl_entry), | 1454 | sizeof(struct ubi_wl_entry), |
1455 | 0, 0, NULL, NULL); | 1455 | 0, 0, NULL); |
1456 | if (!wl_entries_slab) | 1456 | if (!wl_entries_slab) |
1457 | return -ENOMEM; | 1457 | return -ENOMEM; |
1458 | } | 1458 | } |
diff --git a/drivers/net/mac89x0.c b/drivers/net/mac89x0.c index 26a3b45a4a34..62c1c6262feb 100644 --- a/drivers/net/mac89x0.c +++ b/drivers/net/mac89x0.c | |||
@@ -608,7 +608,7 @@ module_param(debug, int, 0); | |||
608 | MODULE_PARM_DESC(debug, "CS89[02]0 debug level (0-5)"); | 608 | MODULE_PARM_DESC(debug, "CS89[02]0 debug level (0-5)"); |
609 | MODULE_LICENSE("GPL"); | 609 | MODULE_LICENSE("GPL"); |
610 | 610 | ||
611 | int | 611 | int __init |
612 | init_module(void) | 612 | init_module(void) |
613 | { | 613 | { |
614 | net_debug = debug; | 614 | net_debug = debug; |
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c index a2f32151559e..13f08a390e1f 100644 --- a/drivers/net/sky2.c +++ b/drivers/net/sky2.c | |||
@@ -692,6 +692,7 @@ static void sky2_mac_init(struct sky2_hw *hw, unsigned port) | |||
692 | { | 692 | { |
693 | struct sky2_port *sky2 = netdev_priv(hw->dev[port]); | 693 | struct sky2_port *sky2 = netdev_priv(hw->dev[port]); |
694 | u16 reg; | 694 | u16 reg; |
695 | u32 rx_reg; | ||
695 | int i; | 696 | int i; |
696 | const u8 *addr = hw->dev[port]->dev_addr; | 697 | const u8 *addr = hw->dev[port]->dev_addr; |
697 | 698 | ||
@@ -768,11 +769,11 @@ static void sky2_mac_init(struct sky2_hw *hw, unsigned port) | |||
768 | 769 | ||
769 | /* Configure Rx MAC FIFO */ | 770 | /* Configure Rx MAC FIFO */ |
770 | sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR); | 771 | sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR); |
771 | reg = GMF_OPER_ON | GMF_RX_F_FL_ON; | 772 | rx_reg = GMF_OPER_ON | GMF_RX_F_FL_ON; |
772 | if (hw->chip_id == CHIP_ID_YUKON_EX) | 773 | if (hw->chip_id == CHIP_ID_YUKON_EX) |
773 | reg |= GMF_RX_OVER_ON; | 774 | rx_reg |= GMF_RX_OVER_ON; |
774 | 775 | ||
775 | sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), reg); | 776 | sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), rx_reg); |
776 | 777 | ||
777 | /* Flush Rx MAC FIFO on any flow control or error */ | 778 | /* Flush Rx MAC FIFO on any flow control or error */ |
778 | sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), GMR_FS_ANY_ERR); | 779 | sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), GMR_FS_ANY_ERR); |
diff --git a/drivers/net/sunvnet.c b/drivers/net/sunvnet.c index b801e3b3a11a..ef0066bab2cf 100644 --- a/drivers/net/sunvnet.c +++ b/drivers/net/sunvnet.c | |||
@@ -1136,7 +1136,7 @@ static struct vio_device_id vnet_port_match[] = { | |||
1136 | }, | 1136 | }, |
1137 | {}, | 1137 | {}, |
1138 | }; | 1138 | }; |
1139 | MODULE_DEVICE_TABLE(vio, vnet_match); | 1139 | MODULE_DEVICE_TABLE(vio, vnet_port_match); |
1140 | 1140 | ||
1141 | static struct vio_driver vnet_port_driver = { | 1141 | static struct vio_driver vnet_port_driver = { |
1142 | .id_table = vnet_port_match, | 1142 | .id_table = vnet_port_match, |
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c index 5ee14764fd74..887b9a5cfe48 100644 --- a/drivers/net/tg3.c +++ b/drivers/net/tg3.c | |||
@@ -64,8 +64,8 @@ | |||
64 | 64 | ||
65 | #define DRV_MODULE_NAME "tg3" | 65 | #define DRV_MODULE_NAME "tg3" |
66 | #define PFX DRV_MODULE_NAME ": " | 66 | #define PFX DRV_MODULE_NAME ": " |
67 | #define DRV_MODULE_VERSION "3.78" | 67 | #define DRV_MODULE_VERSION "3.79" |
68 | #define DRV_MODULE_RELDATE "July 11, 2007" | 68 | #define DRV_MODULE_RELDATE "July 18, 2007" |
69 | 69 | ||
70 | #define TG3_DEF_MAC_MODE 0 | 70 | #define TG3_DEF_MAC_MODE 0 |
71 | #define TG3_DEF_RX_MODE 0 | 71 | #define TG3_DEF_RX_MODE 0 |
@@ -4847,6 +4847,59 @@ static int tg3_poll_fw(struct tg3 *tp) | |||
4847 | return 0; | 4847 | return 0; |
4848 | } | 4848 | } |
4849 | 4849 | ||
4850 | /* Save PCI command register before chip reset */ | ||
4851 | static void tg3_save_pci_state(struct tg3 *tp) | ||
4852 | { | ||
4853 | u32 val; | ||
4854 | |||
4855 | pci_read_config_dword(tp->pdev, TG3PCI_COMMAND, &val); | ||
4856 | tp->pci_cmd = val; | ||
4857 | } | ||
4858 | |||
4859 | /* Restore PCI state after chip reset */ | ||
4860 | static void tg3_restore_pci_state(struct tg3 *tp) | ||
4861 | { | ||
4862 | u32 val; | ||
4863 | |||
4864 | /* Re-enable indirect register accesses. */ | ||
4865 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | ||
4866 | tp->misc_host_ctrl); | ||
4867 | |||
4868 | /* Set MAX PCI retry to zero. */ | ||
4869 | val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE); | ||
4870 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && | ||
4871 | (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) | ||
4872 | val |= PCISTATE_RETRY_SAME_DMA; | ||
4873 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val); | ||
4874 | |||
4875 | pci_write_config_dword(tp->pdev, TG3PCI_COMMAND, tp->pci_cmd); | ||
4876 | |||
4877 | /* Make sure PCI-X relaxed ordering bit is clear. */ | ||
4878 | pci_read_config_dword(tp->pdev, TG3PCI_X_CAPS, &val); | ||
4879 | val &= ~PCIX_CAPS_RELAXED_ORDERING; | ||
4880 | pci_write_config_dword(tp->pdev, TG3PCI_X_CAPS, val); | ||
4881 | |||
4882 | if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) { | ||
4883 | u32 val; | ||
4884 | |||
4885 | /* Chip reset on 5780 will reset MSI enable bit, | ||
4886 | * so need to restore it. | ||
4887 | */ | ||
4888 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) { | ||
4889 | u16 ctrl; | ||
4890 | |||
4891 | pci_read_config_word(tp->pdev, | ||
4892 | tp->msi_cap + PCI_MSI_FLAGS, | ||
4893 | &ctrl); | ||
4894 | pci_write_config_word(tp->pdev, | ||
4895 | tp->msi_cap + PCI_MSI_FLAGS, | ||
4896 | ctrl | PCI_MSI_FLAGS_ENABLE); | ||
4897 | val = tr32(MSGINT_MODE); | ||
4898 | tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE); | ||
4899 | } | ||
4900 | } | ||
4901 | } | ||
4902 | |||
4850 | static void tg3_stop_fw(struct tg3 *); | 4903 | static void tg3_stop_fw(struct tg3 *); |
4851 | 4904 | ||
4852 | /* tp->lock is held. */ | 4905 | /* tp->lock is held. */ |
@@ -4863,6 +4916,12 @@ static int tg3_chip_reset(struct tg3 *tp) | |||
4863 | */ | 4916 | */ |
4864 | tp->nvram_lock_cnt = 0; | 4917 | tp->nvram_lock_cnt = 0; |
4865 | 4918 | ||
4919 | /* GRC_MISC_CFG core clock reset will clear the memory | ||
4920 | * enable bit in PCI register 4 and the MSI enable bit | ||
4921 | * on some chips, so we save relevant registers here. | ||
4922 | */ | ||
4923 | tg3_save_pci_state(tp); | ||
4924 | |||
4866 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || | 4925 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
4867 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || | 4926 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
4868 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) | 4927 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) |
@@ -4961,50 +5020,14 @@ static int tg3_chip_reset(struct tg3 *tp) | |||
4961 | pci_write_config_dword(tp->pdev, 0xd8, 0xf5000); | 5020 | pci_write_config_dword(tp->pdev, 0xd8, 0xf5000); |
4962 | } | 5021 | } |
4963 | 5022 | ||
4964 | /* Re-enable indirect register accesses. */ | 5023 | tg3_restore_pci_state(tp); |
4965 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | ||
4966 | tp->misc_host_ctrl); | ||
4967 | |||
4968 | /* Set MAX PCI retry to zero. */ | ||
4969 | val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE); | ||
4970 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && | ||
4971 | (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) | ||
4972 | val |= PCISTATE_RETRY_SAME_DMA; | ||
4973 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val); | ||
4974 | |||
4975 | pci_restore_state(tp->pdev); | ||
4976 | 5024 | ||
4977 | tp->tg3_flags &= ~TG3_FLAG_CHIP_RESETTING; | 5025 | tp->tg3_flags &= ~TG3_FLAG_CHIP_RESETTING; |
4978 | 5026 | ||
4979 | /* Make sure PCI-X relaxed ordering bit is clear. */ | 5027 | val = 0; |
4980 | pci_read_config_dword(tp->pdev, TG3PCI_X_CAPS, &val); | 5028 | if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) |
4981 | val &= ~PCIX_CAPS_RELAXED_ORDERING; | ||
4982 | pci_write_config_dword(tp->pdev, TG3PCI_X_CAPS, val); | ||
4983 | |||
4984 | if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) { | ||
4985 | u32 val; | ||
4986 | |||
4987 | /* Chip reset on 5780 will reset MSI enable bit, | ||
4988 | * so need to restore it. | ||
4989 | */ | ||
4990 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) { | ||
4991 | u16 ctrl; | ||
4992 | |||
4993 | pci_read_config_word(tp->pdev, | ||
4994 | tp->msi_cap + PCI_MSI_FLAGS, | ||
4995 | &ctrl); | ||
4996 | pci_write_config_word(tp->pdev, | ||
4997 | tp->msi_cap + PCI_MSI_FLAGS, | ||
4998 | ctrl | PCI_MSI_FLAGS_ENABLE); | ||
4999 | val = tr32(MSGINT_MODE); | ||
5000 | tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE); | ||
5001 | } | ||
5002 | |||
5003 | val = tr32(MEMARB_MODE); | 5029 | val = tr32(MEMARB_MODE); |
5004 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); | 5030 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
5005 | |||
5006 | } else | ||
5007 | tw32(MEMARB_MODE, MEMARB_MODE_ENABLE); | ||
5008 | 5031 | ||
5009 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) { | 5032 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) { |
5010 | tg3_stop_fw(tp); | 5033 | tg3_stop_fw(tp); |
@@ -11978,7 +12001,6 @@ static int __devinit tg3_init_one(struct pci_dev *pdev, | |||
11978 | */ | 12001 | */ |
11979 | if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) || | 12002 | if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) || |
11980 | (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { | 12003 | (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
11981 | pci_save_state(tp->pdev); | ||
11982 | tw32(MEMARB_MODE, MEMARB_MODE_ENABLE); | 12004 | tw32(MEMARB_MODE, MEMARB_MODE_ENABLE); |
11983 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); | 12005 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
11984 | } | 12006 | } |
@@ -12007,12 +12029,6 @@ static int __devinit tg3_init_one(struct pci_dev *pdev, | |||
12007 | 12029 | ||
12008 | tg3_init_coal(tp); | 12030 | tg3_init_coal(tp); |
12009 | 12031 | ||
12010 | /* Now that we have fully setup the chip, save away a snapshot | ||
12011 | * of the PCI config space. We need to restore this after | ||
12012 | * GRC_MISC_CFG core clock resets and some resume events. | ||
12013 | */ | ||
12014 | pci_save_state(tp->pdev); | ||
12015 | |||
12016 | pci_set_drvdata(pdev, dev); | 12032 | pci_set_drvdata(pdev, dev); |
12017 | 12033 | ||
12018 | err = register_netdev(dev); | 12034 | err = register_netdev(dev); |
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h index d84e75e7365d..5c21f49026c9 100644 --- a/drivers/net/tg3.h +++ b/drivers/net/tg3.h | |||
@@ -2345,6 +2345,7 @@ struct tg3 { | |||
2345 | #define PHY_REV_BCM5411_X0 0x1 /* Found on Netgear GA302T */ | 2345 | #define PHY_REV_BCM5411_X0 0x1 /* Found on Netgear GA302T */ |
2346 | 2346 | ||
2347 | u32 led_ctrl; | 2347 | u32 led_ctrl; |
2348 | u32 pci_cmd; | ||
2348 | 2349 | ||
2349 | char board_part_number[24]; | 2350 | char board_part_number[24]; |
2350 | char fw_ver[16]; | 2351 | char fw_ver[16]; |
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig new file mode 100644 index 000000000000..c03072b12f42 --- /dev/null +++ b/drivers/of/Kconfig | |||
@@ -0,0 +1,3 @@ | |||
1 | config OF_DEVICE | ||
2 | def_bool y | ||
3 | depends on OF && (SPARC || PPC_OF) | ||
diff --git a/drivers/of/Makefile b/drivers/of/Makefile new file mode 100644 index 000000000000..ab9be5d5255b --- /dev/null +++ b/drivers/of/Makefile | |||
@@ -0,0 +1,2 @@ | |||
1 | obj-y = base.o | ||
2 | obj-$(CONFIG_OF_DEVICE) += device.o platform.o | ||
diff --git a/drivers/of/base.c b/drivers/of/base.c new file mode 100644 index 000000000000..9377f3bc410a --- /dev/null +++ b/drivers/of/base.c | |||
@@ -0,0 +1,275 @@ | |||
1 | /* | ||
2 | * Procedures for creating, accessing and interpreting the device tree. | ||
3 | * | ||
4 | * Paul Mackerras August 1996. | ||
5 | * Copyright (C) 1996-2005 Paul Mackerras. | ||
6 | * | ||
7 | * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner. | ||
8 | * {engebret|bergner}@us.ibm.com | ||
9 | * | ||
10 | * Adapted for sparc and sparc64 by David S. Miller davem@davemloft.net | ||
11 | * | ||
12 | * Reconsolidated from arch/x/kernel/prom.c by Stephen Rothwell. | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or | ||
15 | * modify it under the terms of the GNU General Public License | ||
16 | * as published by the Free Software Foundation; either version | ||
17 | * 2 of the License, or (at your option) any later version. | ||
18 | */ | ||
19 | #include <linux/module.h> | ||
20 | #include <linux/of.h> | ||
21 | #include <linux/spinlock.h> | ||
22 | |||
23 | struct device_node *allnodes; | ||
24 | |||
25 | /* use when traversing tree through the allnext, child, sibling, | ||
26 | * or parent members of struct device_node. | ||
27 | */ | ||
28 | DEFINE_RWLOCK(devtree_lock); | ||
29 | |||
30 | int of_n_addr_cells(struct device_node *np) | ||
31 | { | ||
32 | const int *ip; | ||
33 | |||
34 | do { | ||
35 | if (np->parent) | ||
36 | np = np->parent; | ||
37 | ip = of_get_property(np, "#address-cells", NULL); | ||
38 | if (ip) | ||
39 | return *ip; | ||
40 | } while (np->parent); | ||
41 | /* No #address-cells property for the root node */ | ||
42 | return OF_ROOT_NODE_ADDR_CELLS_DEFAULT; | ||
43 | } | ||
44 | EXPORT_SYMBOL(of_n_addr_cells); | ||
45 | |||
46 | int of_n_size_cells(struct device_node *np) | ||
47 | { | ||
48 | const int *ip; | ||
49 | |||
50 | do { | ||
51 | if (np->parent) | ||
52 | np = np->parent; | ||
53 | ip = of_get_property(np, "#size-cells", NULL); | ||
54 | if (ip) | ||
55 | return *ip; | ||
56 | } while (np->parent); | ||
57 | /* No #size-cells property for the root node */ | ||
58 | return OF_ROOT_NODE_SIZE_CELLS_DEFAULT; | ||
59 | } | ||
60 | EXPORT_SYMBOL(of_n_size_cells); | ||
61 | |||
62 | struct property *of_find_property(const struct device_node *np, | ||
63 | const char *name, | ||
64 | int *lenp) | ||
65 | { | ||
66 | struct property *pp; | ||
67 | |||
68 | read_lock(&devtree_lock); | ||
69 | for (pp = np->properties; pp != 0; pp = pp->next) { | ||
70 | if (of_prop_cmp(pp->name, name) == 0) { | ||
71 | if (lenp != 0) | ||
72 | *lenp = pp->length; | ||
73 | break; | ||
74 | } | ||
75 | } | ||
76 | read_unlock(&devtree_lock); | ||
77 | |||
78 | return pp; | ||
79 | } | ||
80 | EXPORT_SYMBOL(of_find_property); | ||
81 | |||
82 | /* | ||
83 | * Find a property with a given name for a given node | ||
84 | * and return the value. | ||
85 | */ | ||
86 | const void *of_get_property(const struct device_node *np, const char *name, | ||
87 | int *lenp) | ||
88 | { | ||
89 | struct property *pp = of_find_property(np, name, lenp); | ||
90 | |||
91 | return pp ? pp->value : NULL; | ||
92 | } | ||
93 | EXPORT_SYMBOL(of_get_property); | ||
94 | |||
95 | /** Checks if the given "compat" string matches one of the strings in | ||
96 | * the device's "compatible" property | ||
97 | */ | ||
98 | int of_device_is_compatible(const struct device_node *device, | ||
99 | const char *compat) | ||
100 | { | ||
101 | const char* cp; | ||
102 | int cplen, l; | ||
103 | |||
104 | cp = of_get_property(device, "compatible", &cplen); | ||
105 | if (cp == NULL) | ||
106 | return 0; | ||
107 | while (cplen > 0) { | ||
108 | if (of_compat_cmp(cp, compat, strlen(compat)) == 0) | ||
109 | return 1; | ||
110 | l = strlen(cp) + 1; | ||
111 | cp += l; | ||
112 | cplen -= l; | ||
113 | } | ||
114 | |||
115 | return 0; | ||
116 | } | ||
117 | EXPORT_SYMBOL(of_device_is_compatible); | ||
118 | |||
119 | /** | ||
120 | * of_get_parent - Get a node's parent if any | ||
121 | * @node: Node to get parent | ||
122 | * | ||
123 | * Returns a node pointer with refcount incremented, use | ||
124 | * of_node_put() on it when done. | ||
125 | */ | ||
126 | struct device_node *of_get_parent(const struct device_node *node) | ||
127 | { | ||
128 | struct device_node *np; | ||
129 | |||
130 | if (!node) | ||
131 | return NULL; | ||
132 | |||
133 | read_lock(&devtree_lock); | ||
134 | np = of_node_get(node->parent); | ||
135 | read_unlock(&devtree_lock); | ||
136 | return np; | ||
137 | } | ||
138 | EXPORT_SYMBOL(of_get_parent); | ||
139 | |||
140 | /** | ||
141 | * of_get_next_child - Iterate a node childs | ||
142 | * @node: parent node | ||
143 | * @prev: previous child of the parent node, or NULL to get first | ||
144 | * | ||
145 | * Returns a node pointer with refcount incremented, use | ||
146 | * of_node_put() on it when done. | ||
147 | */ | ||
148 | struct device_node *of_get_next_child(const struct device_node *node, | ||
149 | struct device_node *prev) | ||
150 | { | ||
151 | struct device_node *next; | ||
152 | |||
153 | read_lock(&devtree_lock); | ||
154 | next = prev ? prev->sibling : node->child; | ||
155 | for (; next; next = next->sibling) | ||
156 | if (of_node_get(next)) | ||
157 | break; | ||
158 | of_node_put(prev); | ||
159 | read_unlock(&devtree_lock); | ||
160 | return next; | ||
161 | } | ||
162 | EXPORT_SYMBOL(of_get_next_child); | ||
163 | |||
164 | /** | ||
165 | * of_find_node_by_path - Find a node matching a full OF path | ||
166 | * @path: The full path to match | ||
167 | * | ||
168 | * Returns a node pointer with refcount incremented, use | ||
169 | * of_node_put() on it when done. | ||
170 | */ | ||
171 | struct device_node *of_find_node_by_path(const char *path) | ||
172 | { | ||
173 | struct device_node *np = allnodes; | ||
174 | |||
175 | read_lock(&devtree_lock); | ||
176 | for (; np; np = np->allnext) { | ||
177 | if (np->full_name && (of_node_cmp(np->full_name, path) == 0) | ||
178 | && of_node_get(np)) | ||
179 | break; | ||
180 | } | ||
181 | read_unlock(&devtree_lock); | ||
182 | return np; | ||
183 | } | ||
184 | EXPORT_SYMBOL(of_find_node_by_path); | ||
185 | |||
186 | /** | ||
187 | * of_find_node_by_name - Find a node by its "name" property | ||
188 | * @from: The node to start searching from or NULL, the node | ||
189 | * you pass will not be searched, only the next one | ||
190 | * will; typically, you pass what the previous call | ||
191 | * returned. of_node_put() will be called on it | ||
192 | * @name: The name string to match against | ||
193 | * | ||
194 | * Returns a node pointer with refcount incremented, use | ||
195 | * of_node_put() on it when done. | ||
196 | */ | ||
197 | struct device_node *of_find_node_by_name(struct device_node *from, | ||
198 | const char *name) | ||
199 | { | ||
200 | struct device_node *np; | ||
201 | |||
202 | read_lock(&devtree_lock); | ||
203 | np = from ? from->allnext : allnodes; | ||
204 | for (; np; np = np->allnext) | ||
205 | if (np->name && (of_node_cmp(np->name, name) == 0) | ||
206 | && of_node_get(np)) | ||
207 | break; | ||
208 | of_node_put(from); | ||
209 | read_unlock(&devtree_lock); | ||
210 | return np; | ||
211 | } | ||
212 | EXPORT_SYMBOL(of_find_node_by_name); | ||
213 | |||
214 | /** | ||
215 | * of_find_node_by_type - Find a node by its "device_type" property | ||
216 | * @from: The node to start searching from, or NULL to start searching | ||
217 | * the entire device tree. The node you pass will not be | ||
218 | * searched, only the next one will; typically, you pass | ||
219 | * what the previous call returned. of_node_put() will be | ||
220 | * called on from for you. | ||
221 | * @type: The type string to match against | ||
222 | * | ||
223 | * Returns a node pointer with refcount incremented, use | ||
224 | * of_node_put() on it when done. | ||
225 | */ | ||
226 | struct device_node *of_find_node_by_type(struct device_node *from, | ||
227 | const char *type) | ||
228 | { | ||
229 | struct device_node *np; | ||
230 | |||
231 | read_lock(&devtree_lock); | ||
232 | np = from ? from->allnext : allnodes; | ||
233 | for (; np; np = np->allnext) | ||
234 | if (np->type && (of_node_cmp(np->type, type) == 0) | ||
235 | && of_node_get(np)) | ||
236 | break; | ||
237 | of_node_put(from); | ||
238 | read_unlock(&devtree_lock); | ||
239 | return np; | ||
240 | } | ||
241 | EXPORT_SYMBOL(of_find_node_by_type); | ||
242 | |||
243 | /** | ||
244 | * of_find_compatible_node - Find a node based on type and one of the | ||
245 | * tokens in its "compatible" property | ||
246 | * @from: The node to start searching from or NULL, the node | ||
247 | * you pass will not be searched, only the next one | ||
248 | * will; typically, you pass what the previous call | ||
249 | * returned. of_node_put() will be called on it | ||
250 | * @type: The type string to match "device_type" or NULL to ignore | ||
251 | * @compatible: The string to match to one of the tokens in the device | ||
252 | * "compatible" list. | ||
253 | * | ||
254 | * Returns a node pointer with refcount incremented, use | ||
255 | * of_node_put() on it when done. | ||
256 | */ | ||
257 | struct device_node *of_find_compatible_node(struct device_node *from, | ||
258 | const char *type, const char *compatible) | ||
259 | { | ||
260 | struct device_node *np; | ||
261 | |||
262 | read_lock(&devtree_lock); | ||
263 | np = from ? from->allnext : allnodes; | ||
264 | for (; np; np = np->allnext) { | ||
265 | if (type | ||
266 | && !(np->type && (of_node_cmp(np->type, type) == 0))) | ||
267 | continue; | ||
268 | if (of_device_is_compatible(np, compatible) && of_node_get(np)) | ||
269 | break; | ||
270 | } | ||
271 | of_node_put(from); | ||
272 | read_unlock(&devtree_lock); | ||
273 | return np; | ||
274 | } | ||
275 | EXPORT_SYMBOL(of_find_compatible_node); | ||
diff --git a/drivers/of/device.c b/drivers/of/device.c new file mode 100644 index 000000000000..6245f060fb77 --- /dev/null +++ b/drivers/of/device.c | |||
@@ -0,0 +1,131 @@ | |||
1 | #include <linux/string.h> | ||
2 | #include <linux/kernel.h> | ||
3 | #include <linux/of.h> | ||
4 | #include <linux/of_device.h> | ||
5 | #include <linux/init.h> | ||
6 | #include <linux/module.h> | ||
7 | #include <linux/mod_devicetable.h> | ||
8 | #include <linux/slab.h> | ||
9 | |||
10 | #include <asm/errno.h> | ||
11 | |||
12 | /** | ||
13 | * of_match_node - Tell if an device_node has a matching of_match structure | ||
14 | * @ids: array of of device match structures to search in | ||
15 | * @node: the of device structure to match against | ||
16 | * | ||
17 | * Low level utility function used by device matching. | ||
18 | */ | ||
19 | const struct of_device_id *of_match_node(const struct of_device_id *matches, | ||
20 | const struct device_node *node) | ||
21 | { | ||
22 | while (matches->name[0] || matches->type[0] || matches->compatible[0]) { | ||
23 | int match = 1; | ||
24 | if (matches->name[0]) | ||
25 | match &= node->name | ||
26 | && !strcmp(matches->name, node->name); | ||
27 | if (matches->type[0]) | ||
28 | match &= node->type | ||
29 | && !strcmp(matches->type, node->type); | ||
30 | if (matches->compatible[0]) | ||
31 | match &= of_device_is_compatible(node, | ||
32 | matches->compatible); | ||
33 | if (match) | ||
34 | return matches; | ||
35 | matches++; | ||
36 | } | ||
37 | return NULL; | ||
38 | } | ||
39 | EXPORT_SYMBOL(of_match_node); | ||
40 | |||
41 | /** | ||
42 | * of_match_device - Tell if an of_device structure has a matching | ||
43 | * of_match structure | ||
44 | * @ids: array of of device match structures to search in | ||
45 | * @dev: the of device structure to match against | ||
46 | * | ||
47 | * Used by a driver to check whether an of_device present in the | ||
48 | * system is in its list of supported devices. | ||
49 | */ | ||
50 | const struct of_device_id *of_match_device(const struct of_device_id *matches, | ||
51 | const struct of_device *dev) | ||
52 | { | ||
53 | if (!dev->node) | ||
54 | return NULL; | ||
55 | return of_match_node(matches, dev->node); | ||
56 | } | ||
57 | EXPORT_SYMBOL(of_match_device); | ||
58 | |||
59 | struct of_device *of_dev_get(struct of_device *dev) | ||
60 | { | ||
61 | struct device *tmp; | ||
62 | |||
63 | if (!dev) | ||
64 | return NULL; | ||
65 | tmp = get_device(&dev->dev); | ||
66 | if (tmp) | ||
67 | return to_of_device(tmp); | ||
68 | else | ||
69 | return NULL; | ||
70 | } | ||
71 | EXPORT_SYMBOL(of_dev_get); | ||
72 | |||
73 | void of_dev_put(struct of_device *dev) | ||
74 | { | ||
75 | if (dev) | ||
76 | put_device(&dev->dev); | ||
77 | } | ||
78 | EXPORT_SYMBOL(of_dev_put); | ||
79 | |||
80 | static ssize_t dev_show_devspec(struct device *dev, | ||
81 | struct device_attribute *attr, char *buf) | ||
82 | { | ||
83 | struct of_device *ofdev; | ||
84 | |||
85 | ofdev = to_of_device(dev); | ||
86 | return sprintf(buf, "%s", ofdev->node->full_name); | ||
87 | } | ||
88 | |||
89 | static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL); | ||
90 | |||
91 | /** | ||
92 | * of_release_dev - free an of device structure when all users of it are finished. | ||
93 | * @dev: device that's been disconnected | ||
94 | * | ||
95 | * Will be called only by the device core when all users of this of device are | ||
96 | * done. | ||
97 | */ | ||
98 | void of_release_dev(struct device *dev) | ||
99 | { | ||
100 | struct of_device *ofdev; | ||
101 | |||
102 | ofdev = to_of_device(dev); | ||
103 | of_node_put(ofdev->node); | ||
104 | kfree(ofdev); | ||
105 | } | ||
106 | EXPORT_SYMBOL(of_release_dev); | ||
107 | |||
108 | int of_device_register(struct of_device *ofdev) | ||
109 | { | ||
110 | int rc; | ||
111 | |||
112 | BUG_ON(ofdev->node == NULL); | ||
113 | |||
114 | rc = device_register(&ofdev->dev); | ||
115 | if (rc) | ||
116 | return rc; | ||
117 | |||
118 | rc = device_create_file(&ofdev->dev, &dev_attr_devspec); | ||
119 | if (rc) | ||
120 | device_unregister(&ofdev->dev); | ||
121 | |||
122 | return rc; | ||
123 | } | ||
124 | EXPORT_SYMBOL(of_device_register); | ||
125 | |||
126 | void of_device_unregister(struct of_device *ofdev) | ||
127 | { | ||
128 | device_remove_file(&ofdev->dev, &dev_attr_devspec); | ||
129 | device_unregister(&ofdev->dev); | ||
130 | } | ||
131 | EXPORT_SYMBOL(of_device_unregister); | ||
diff --git a/drivers/of/platform.c b/drivers/of/platform.c new file mode 100644 index 000000000000..864f09fd9f86 --- /dev/null +++ b/drivers/of/platform.c | |||
@@ -0,0 +1,96 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp. | ||
3 | * <benh@kernel.crashing.org> | ||
4 | * and Arnd Bergmann, IBM Corp. | ||
5 | * Merged from powerpc/kernel/of_platform.c and | ||
6 | * sparc{,64}/kernel/of_device.c by Stephen Rothwell | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License | ||
10 | * as published by the Free Software Foundation; either version | ||
11 | * 2 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | #include <linux/errno.h> | ||
15 | #include <linux/device.h> | ||
16 | #include <linux/of_device.h> | ||
17 | #include <linux/of_platform.h> | ||
18 | |||
19 | static int of_platform_bus_match(struct device *dev, struct device_driver *drv) | ||
20 | { | ||
21 | struct of_device *of_dev = to_of_device(dev); | ||
22 | struct of_platform_driver *of_drv = to_of_platform_driver(drv); | ||
23 | const struct of_device_id *matches = of_drv->match_table; | ||
24 | |||
25 | if (!matches) | ||
26 | return 0; | ||
27 | |||
28 | return of_match_device(matches, of_dev) != NULL; | ||
29 | } | ||
30 | |||
31 | static int of_platform_device_probe(struct device *dev) | ||
32 | { | ||
33 | int error = -ENODEV; | ||
34 | struct of_platform_driver *drv; | ||
35 | struct of_device *of_dev; | ||
36 | const struct of_device_id *match; | ||
37 | |||
38 | drv = to_of_platform_driver(dev->driver); | ||
39 | of_dev = to_of_device(dev); | ||
40 | |||
41 | if (!drv->probe) | ||
42 | return error; | ||
43 | |||
44 | of_dev_get(of_dev); | ||
45 | |||
46 | match = of_match_device(drv->match_table, of_dev); | ||
47 | if (match) | ||
48 | error = drv->probe(of_dev, match); | ||
49 | if (error) | ||
50 | of_dev_put(of_dev); | ||
51 | |||
52 | return error; | ||
53 | } | ||
54 | |||
55 | static int of_platform_device_remove(struct device *dev) | ||
56 | { | ||
57 | struct of_device *of_dev = to_of_device(dev); | ||
58 | struct of_platform_driver *drv = to_of_platform_driver(dev->driver); | ||
59 | |||
60 | if (dev->driver && drv->remove) | ||
61 | drv->remove(of_dev); | ||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | static int of_platform_device_suspend(struct device *dev, pm_message_t state) | ||
66 | { | ||
67 | struct of_device *of_dev = to_of_device(dev); | ||
68 | struct of_platform_driver *drv = to_of_platform_driver(dev->driver); | ||
69 | int error = 0; | ||
70 | |||
71 | if (dev->driver && drv->suspend) | ||
72 | error = drv->suspend(of_dev, state); | ||
73 | return error; | ||
74 | } | ||
75 | |||
76 | static int of_platform_device_resume(struct device * dev) | ||
77 | { | ||
78 | struct of_device *of_dev = to_of_device(dev); | ||
79 | struct of_platform_driver *drv = to_of_platform_driver(dev->driver); | ||
80 | int error = 0; | ||
81 | |||
82 | if (dev->driver && drv->resume) | ||
83 | error = drv->resume(of_dev); | ||
84 | return error; | ||
85 | } | ||
86 | |||
87 | int of_bus_type_init(struct bus_type *bus, const char *name) | ||
88 | { | ||
89 | bus->name = name; | ||
90 | bus->match = of_platform_bus_match; | ||
91 | bus->probe = of_platform_device_probe; | ||
92 | bus->remove = of_platform_device_remove; | ||
93 | bus->suspend = of_platform_device_suspend; | ||
94 | bus->resume = of_platform_device_resume; | ||
95 | return bus_register(bus); | ||
96 | } | ||
diff --git a/drivers/parport/Kconfig b/drivers/parport/Kconfig index 09c93ff932b1..d449b150930e 100644 --- a/drivers/parport/Kconfig +++ b/drivers/parport/Kconfig | |||
@@ -35,7 +35,7 @@ if PARPORT | |||
35 | 35 | ||
36 | config PARPORT_PC | 36 | config PARPORT_PC |
37 | tristate "PC-style hardware" | 37 | tristate "PC-style hardware" |
38 | depends on (!SPARC64 || PCI) && !SPARC32 && !M32R && !FRV | 38 | depends on (!SPARC64 || PCI) && !SPARC32 && !M32R && !FRV && (!M68K || ISA) |
39 | ---help--- | 39 | ---help--- |
40 | You should say Y here if you have a PC-style parallel port. All | 40 | You should say Y here if you have a PC-style parallel port. All |
41 | IBM PC compatible computers and some Alphas have PC-style | 41 | IBM PC compatible computers and some Alphas have PC-style |
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index cea401feb0f3..35f34665e3c4 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
@@ -394,7 +394,7 @@ config RTC_DRV_SA1100 | |||
394 | 394 | ||
395 | config RTC_DRV_SH | 395 | config RTC_DRV_SH |
396 | tristate "SuperH On-Chip RTC" | 396 | tristate "SuperH On-Chip RTC" |
397 | depends on RTC_CLASS && SUPERH | 397 | depends on RTC_CLASS && SUPERH && (CPU_SH3 || CPU_SH4) |
398 | help | 398 | help |
399 | Say Y here to enable support for the on-chip RTC found in | 399 | Say Y here to enable support for the on-chip RTC found in |
400 | most SuperH processors. | 400 | most SuperH processors. |
diff --git a/drivers/s390/block/dasd_devmap.c b/drivers/s390/block/dasd_devmap.c index 6a89cefe99bb..0c67258fb9ec 100644 --- a/drivers/s390/block/dasd_devmap.c +++ b/drivers/s390/block/dasd_devmap.c | |||
@@ -291,7 +291,7 @@ dasd_parse_keyword( char *parsestring ) { | |||
291 | dasd_page_cache = | 291 | dasd_page_cache = |
292 | kmem_cache_create("dasd_page_cache", PAGE_SIZE, | 292 | kmem_cache_create("dasd_page_cache", PAGE_SIZE, |
293 | PAGE_SIZE, SLAB_CACHE_DMA, | 293 | PAGE_SIZE, SLAB_CACHE_DMA, |
294 | NULL, NULL ); | 294 | NULL); |
295 | if (!dasd_page_cache) | 295 | if (!dasd_page_cache) |
296 | MESSAGE(KERN_WARNING, "%s", "Failed to create slab, " | 296 | MESSAGE(KERN_WARNING, "%s", "Failed to create slab, " |
297 | "fixed buffer mode disabled."); | 297 | "fixed buffer mode disabled."); |
diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c index a1db95925138..9726261c367d 100644 --- a/drivers/s390/scsi/zfcp_aux.c +++ b/drivers/s390/scsi/zfcp_aux.c | |||
@@ -259,21 +259,21 @@ zfcp_module_init(void) | |||
259 | size = sizeof(struct zfcp_fsf_req_qtcb); | 259 | size = sizeof(struct zfcp_fsf_req_qtcb); |
260 | align = calc_alignment(size); | 260 | align = calc_alignment(size); |
261 | zfcp_data.fsf_req_qtcb_cache = | 261 | zfcp_data.fsf_req_qtcb_cache = |
262 | kmem_cache_create("zfcp_fsf", size, align, 0, NULL, NULL); | 262 | kmem_cache_create("zfcp_fsf", size, align, 0, NULL); |
263 | if (!zfcp_data.fsf_req_qtcb_cache) | 263 | if (!zfcp_data.fsf_req_qtcb_cache) |
264 | goto out; | 264 | goto out; |
265 | 265 | ||
266 | size = sizeof(struct fsf_status_read_buffer); | 266 | size = sizeof(struct fsf_status_read_buffer); |
267 | align = calc_alignment(size); | 267 | align = calc_alignment(size); |
268 | zfcp_data.sr_buffer_cache = | 268 | zfcp_data.sr_buffer_cache = |
269 | kmem_cache_create("zfcp_sr", size, align, 0, NULL, NULL); | 269 | kmem_cache_create("zfcp_sr", size, align, 0, NULL); |
270 | if (!zfcp_data.sr_buffer_cache) | 270 | if (!zfcp_data.sr_buffer_cache) |
271 | goto out_sr_cache; | 271 | goto out_sr_cache; |
272 | 272 | ||
273 | size = sizeof(struct zfcp_gid_pn_data); | 273 | size = sizeof(struct zfcp_gid_pn_data); |
274 | align = calc_alignment(size); | 274 | align = calc_alignment(size); |
275 | zfcp_data.gid_pn_cache = | 275 | zfcp_data.gid_pn_cache = |
276 | kmem_cache_create("zfcp_gid", size, align, 0, NULL, NULL); | 276 | kmem_cache_create("zfcp_gid", size, align, 0, NULL); |
277 | if (!zfcp_data.gid_pn_cache) | 277 | if (!zfcp_data.gid_pn_cache) |
278 | goto out_gid_cache; | 278 | goto out_gid_cache; |
279 | 279 | ||
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig index 372723161c97..a947257b8964 100644 --- a/drivers/scsi/Kconfig +++ b/drivers/scsi/Kconfig | |||
@@ -483,7 +483,7 @@ source "drivers/scsi/aic94xx/Kconfig" | |||
483 | # All the I2O code and drivers do not seem to be 64bit safe. | 483 | # All the I2O code and drivers do not seem to be 64bit safe. |
484 | config SCSI_DPT_I2O | 484 | config SCSI_DPT_I2O |
485 | tristate "Adaptec I2O RAID support " | 485 | tristate "Adaptec I2O RAID support " |
486 | depends on !64BIT && SCSI && PCI | 486 | depends on !64BIT && SCSI && PCI && VIRT_TO_BUS |
487 | help | 487 | help |
488 | This driver supports all of Adaptec's I2O based RAID controllers as | 488 | This driver supports all of Adaptec's I2O based RAID controllers as |
489 | well as the DPT SmartRaid V cards. This is an Adaptec maintained | 489 | well as the DPT SmartRaid V cards. This is an Adaptec maintained |
diff --git a/drivers/scsi/NCR53C9x.c b/drivers/scsi/NCR53C9x.c index 773d11dd9953..79b4df158140 100644 --- a/drivers/scsi/NCR53C9x.c +++ b/drivers/scsi/NCR53C9x.c | |||
@@ -95,6 +95,8 @@ enum { | |||
95 | /* The master ring of all esp hosts we are managing in this driver. */ | 95 | /* The master ring of all esp hosts we are managing in this driver. */ |
96 | static struct NCR_ESP *espchain; | 96 | static struct NCR_ESP *espchain; |
97 | int nesps = 0, esps_in_use = 0, esps_running = 0; | 97 | int nesps = 0, esps_in_use = 0, esps_running = 0; |
98 | EXPORT_SYMBOL(nesps); | ||
99 | EXPORT_SYMBOL(esps_running); | ||
98 | 100 | ||
99 | irqreturn_t esp_intr(int irq, void *dev_id); | 101 | irqreturn_t esp_intr(int irq, void *dev_id); |
100 | 102 | ||
@@ -524,6 +526,7 @@ void esp_bootup_reset(struct NCR_ESP *esp, struct ESP_regs *eregs) | |||
524 | /* Eat any bitrot in the chip and we are done... */ | 526 | /* Eat any bitrot in the chip and we are done... */ |
525 | trash = esp_read(eregs->esp_intrpt); | 527 | trash = esp_read(eregs->esp_intrpt); |
526 | } | 528 | } |
529 | EXPORT_SYMBOL(esp_bootup_reset); | ||
527 | 530 | ||
528 | /* Allocate structure and insert basic data such as SCSI chip frequency | 531 | /* Allocate structure and insert basic data such as SCSI chip frequency |
529 | * data and a pointer to the device | 532 | * data and a pointer to the device |
@@ -772,6 +775,7 @@ const char *esp_info(struct Scsi_Host *host) | |||
772 | panic("Bogon ESP revision"); | 775 | panic("Bogon ESP revision"); |
773 | }; | 776 | }; |
774 | } | 777 | } |
778 | EXPORT_SYMBOL(esp_info); | ||
775 | 779 | ||
776 | /* From Wolfgang Stanglmeier's NCR scsi driver. */ | 780 | /* From Wolfgang Stanglmeier's NCR scsi driver. */ |
777 | struct info_str | 781 | struct info_str |
@@ -902,6 +906,7 @@ int esp_proc_info(struct Scsi_Host *shost, char *buffer, char **start, off_t off | |||
902 | *start = buffer; | 906 | *start = buffer; |
903 | return esp_host_info(esp, buffer, offset, length); | 907 | return esp_host_info(esp, buffer, offset, length); |
904 | } | 908 | } |
909 | EXPORT_SYMBOL(esp_proc_info); | ||
905 | 910 | ||
906 | static void esp_get_dmabufs(struct NCR_ESP *esp, Scsi_Cmnd *sp) | 911 | static void esp_get_dmabufs(struct NCR_ESP *esp, Scsi_Cmnd *sp) |
907 | { | 912 | { |
@@ -3535,6 +3540,7 @@ state_machine: | |||
3535 | if(esp->dma_irq_exit) | 3540 | if(esp->dma_irq_exit) |
3536 | esp->dma_irq_exit(esp); | 3541 | esp->dma_irq_exit(esp); |
3537 | } | 3542 | } |
3543 | EXPORT_SYMBOL(esp_handle); | ||
3538 | 3544 | ||
3539 | #ifndef CONFIG_SMP | 3545 | #ifndef CONFIG_SMP |
3540 | irqreturn_t esp_intr(int irq, void *dev_id) | 3546 | irqreturn_t esp_intr(int irq, void *dev_id) |
@@ -3631,6 +3637,7 @@ void esp_release(void) | |||
3631 | esps_in_use--; | 3637 | esps_in_use--; |
3632 | esps_running = esps_in_use; | 3638 | esps_running = esps_in_use; |
3633 | } | 3639 | } |
3640 | EXPORT_SYMBOL(esp_release); | ||
3634 | #endif | 3641 | #endif |
3635 | 3642 | ||
3636 | EXPORT_SYMBOL(esp_abort); | 3643 | EXPORT_SYMBOL(esp_abort); |
diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c index 1c0d7578e791..b8c6810090d5 100644 --- a/drivers/scsi/aic94xx/aic94xx_init.c +++ b/drivers/scsi/aic94xx/aic94xx_init.c | |||
@@ -462,7 +462,7 @@ static int asd_create_global_caches(void) | |||
462 | sizeof(struct asd_dma_tok), | 462 | sizeof(struct asd_dma_tok), |
463 | 0, | 463 | 0, |
464 | SLAB_HWCACHE_ALIGN, | 464 | SLAB_HWCACHE_ALIGN, |
465 | NULL, NULL); | 465 | NULL); |
466 | if (!asd_dma_token_cache) { | 466 | if (!asd_dma_token_cache) { |
467 | asd_printk("couldn't create dma token cache\n"); | 467 | asd_printk("couldn't create dma token cache\n"); |
468 | return -ENOMEM; | 468 | return -ENOMEM; |
@@ -474,7 +474,7 @@ static int asd_create_global_caches(void) | |||
474 | sizeof(struct asd_ascb), | 474 | sizeof(struct asd_ascb), |
475 | 0, | 475 | 0, |
476 | SLAB_HWCACHE_ALIGN, | 476 | SLAB_HWCACHE_ALIGN, |
477 | NULL, NULL); | 477 | NULL); |
478 | if (!asd_ascb_cache) { | 478 | if (!asd_ascb_cache) { |
479 | asd_printk("couldn't create ascb cache\n"); | 479 | asd_printk("couldn't create ascb cache\n"); |
480 | goto Err; | 480 | goto Err; |
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c index aebcd5fcdc55..7829ab1e2fb4 100644 --- a/drivers/scsi/iscsi_tcp.c +++ b/drivers/scsi/iscsi_tcp.c | |||
@@ -1885,7 +1885,7 @@ static int iscsi_tcp_get_addr(struct iscsi_conn *conn, struct socket *sock, | |||
1885 | struct sockaddr_in *sin; | 1885 | struct sockaddr_in *sin; |
1886 | int rc = 0, len; | 1886 | int rc = 0, len; |
1887 | 1887 | ||
1888 | addr = kmalloc(GFP_KERNEL, sizeof(*addr)); | 1888 | addr = kmalloc(sizeof(*addr), GFP_KERNEL); |
1889 | if (!addr) | 1889 | if (!addr) |
1890 | return -ENOMEM; | 1890 | return -ENOMEM; |
1891 | 1891 | ||
diff --git a/drivers/scsi/libsas/sas_init.c b/drivers/scsi/libsas/sas_init.c index 965698c8b7bf..1396c83b0c9c 100644 --- a/drivers/scsi/libsas/sas_init.c +++ b/drivers/scsi/libsas/sas_init.c | |||
@@ -292,7 +292,7 @@ EXPORT_SYMBOL_GPL(sas_domain_release_transport); | |||
292 | static int __init sas_class_init(void) | 292 | static int __init sas_class_init(void) |
293 | { | 293 | { |
294 | sas_task_cache = kmem_cache_create("sas_task", sizeof(struct sas_task), | 294 | sas_task_cache = kmem_cache_create("sas_task", sizeof(struct sas_task), |
295 | 0, SLAB_HWCACHE_ALIGN, NULL, NULL); | 295 | 0, SLAB_HWCACHE_ALIGN, NULL); |
296 | if (!sas_task_cache) | 296 | if (!sas_task_cache) |
297 | return -ENOMEM; | 297 | return -ENOMEM; |
298 | 298 | ||
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c index b5a77b0c0deb..92376f9dfdd5 100644 --- a/drivers/scsi/qla2xxx/qla_os.c +++ b/drivers/scsi/qla2xxx/qla_os.c | |||
@@ -2723,7 +2723,7 @@ qla2x00_module_init(void) | |||
2723 | 2723 | ||
2724 | /* Allocate cache for SRBs. */ | 2724 | /* Allocate cache for SRBs. */ |
2725 | srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0, | 2725 | srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0, |
2726 | SLAB_HWCACHE_ALIGN, NULL, NULL); | 2726 | SLAB_HWCACHE_ALIGN, NULL); |
2727 | if (srb_cachep == NULL) { | 2727 | if (srb_cachep == NULL) { |
2728 | printk(KERN_ERR | 2728 | printk(KERN_ERR |
2729 | "qla2xxx: Unable to allocate SRB cache...Failing load!\n"); | 2729 | "qla2xxx: Unable to allocate SRB cache...Failing load!\n"); |
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c index e69160a7bc60..b1d565c12c5b 100644 --- a/drivers/scsi/qla4xxx/ql4_os.c +++ b/drivers/scsi/qla4xxx/ql4_os.c | |||
@@ -1677,7 +1677,7 @@ static int __init qla4xxx_module_init(void) | |||
1677 | 1677 | ||
1678 | /* Allocate cache for SRBs. */ | 1678 | /* Allocate cache for SRBs. */ |
1679 | srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0, | 1679 | srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0, |
1680 | SLAB_HWCACHE_ALIGN, NULL, NULL); | 1680 | SLAB_HWCACHE_ALIGN, NULL); |
1681 | if (srb_cachep == NULL) { | 1681 | if (srb_cachep == NULL) { |
1682 | printk(KERN_ERR | 1682 | printk(KERN_ERR |
1683 | "%s: Unable to allocate SRB cache..." | 1683 | "%s: Unable to allocate SRB cache..." |
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index a691dda40d2c..a5de1a829a76 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c | |||
@@ -288,7 +288,7 @@ int scsi_setup_command_freelist(struct Scsi_Host *shost) | |||
288 | if (!pool->users) { | 288 | if (!pool->users) { |
289 | pool->slab = kmem_cache_create(pool->name, | 289 | pool->slab = kmem_cache_create(pool->name, |
290 | sizeof(struct scsi_cmnd), 0, | 290 | sizeof(struct scsi_cmnd), 0, |
291 | pool->slab_flags, NULL, NULL); | 291 | pool->slab_flags, NULL); |
292 | if (!pool->slab) | 292 | if (!pool->slab) |
293 | goto fail; | 293 | goto fail; |
294 | } | 294 | } |
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 1f5a07bf2a75..da63c544919b 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c | |||
@@ -1661,7 +1661,7 @@ int __init scsi_init_queue(void) | |||
1661 | 1661 | ||
1662 | scsi_io_context_cache = kmem_cache_create("scsi_io_context", | 1662 | scsi_io_context_cache = kmem_cache_create("scsi_io_context", |
1663 | sizeof(struct scsi_io_context), | 1663 | sizeof(struct scsi_io_context), |
1664 | 0, 0, NULL, NULL); | 1664 | 0, 0, NULL); |
1665 | if (!scsi_io_context_cache) { | 1665 | if (!scsi_io_context_cache) { |
1666 | printk(KERN_ERR "SCSI: can't init scsi io context cache\n"); | 1666 | printk(KERN_ERR "SCSI: can't init scsi io context cache\n"); |
1667 | return -ENOMEM; | 1667 | return -ENOMEM; |
@@ -1672,7 +1672,7 @@ int __init scsi_init_queue(void) | |||
1672 | int size = sgp->size * sizeof(struct scatterlist); | 1672 | int size = sgp->size * sizeof(struct scatterlist); |
1673 | 1673 | ||
1674 | sgp->slab = kmem_cache_create(sgp->name, size, 0, | 1674 | sgp->slab = kmem_cache_create(sgp->name, size, 0, |
1675 | SLAB_HWCACHE_ALIGN, NULL, NULL); | 1675 | SLAB_HWCACHE_ALIGN, NULL); |
1676 | if (!sgp->slab) { | 1676 | if (!sgp->slab) { |
1677 | printk(KERN_ERR "SCSI: can't init sg slab %s\n", | 1677 | printk(KERN_ERR "SCSI: can't init sg slab %s\n", |
1678 | sgp->name); | 1678 | sgp->name); |
diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c index 2570f48a69c7..371b69c110bc 100644 --- a/drivers/scsi/scsi_tgt_lib.c +++ b/drivers/scsi/scsi_tgt_lib.c | |||
@@ -585,7 +585,7 @@ static int __init scsi_tgt_init(void) | |||
585 | 585 | ||
586 | scsi_tgt_cmd_cache = kmem_cache_create("scsi_tgt_cmd", | 586 | scsi_tgt_cmd_cache = kmem_cache_create("scsi_tgt_cmd", |
587 | sizeof(struct scsi_tgt_cmd), | 587 | sizeof(struct scsi_tgt_cmd), |
588 | 0, 0, NULL, NULL); | 588 | 0, 0, NULL); |
589 | if (!scsi_tgt_cmd_cache) | 589 | if (!scsi_tgt_cmd_cache) |
590 | return -ENOMEM; | 590 | return -ENOMEM; |
591 | 591 | ||
diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c index 1bc884051e0f..02c52f8d5dbf 100644 --- a/drivers/usb/atm/cxacru.c +++ b/drivers/usb/atm/cxacru.c | |||
@@ -456,7 +456,7 @@ static int cxacru_start_wait_urb(struct urb *urb, struct completion *done, | |||
456 | int* actual_length) | 456 | int* actual_length) |
457 | { | 457 | { |
458 | struct timer_list timer; | 458 | struct timer_list timer; |
459 | int status; | 459 | int status = urb->status; |
460 | 460 | ||
461 | init_timer(&timer); | 461 | init_timer(&timer); |
462 | timer.expires = jiffies + msecs_to_jiffies(CMD_TIMEOUT); | 462 | timer.expires = jiffies + msecs_to_jiffies(CMD_TIMEOUT); |
@@ -464,7 +464,6 @@ static int cxacru_start_wait_urb(struct urb *urb, struct completion *done, | |||
464 | timer.function = cxacru_timeout_kill; | 464 | timer.function = cxacru_timeout_kill; |
465 | add_timer(&timer); | 465 | add_timer(&timer); |
466 | wait_for_completion(done); | 466 | wait_for_completion(done); |
467 | status = urb->status; | ||
468 | del_timer_sync(&timer); | 467 | del_timer_sync(&timer); |
469 | 468 | ||
470 | if (actual_length) | 469 | if (actual_length) |
diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c index 638b8009b3bc..eb0615abff68 100644 --- a/drivers/usb/atm/speedtch.c +++ b/drivers/usb/atm/speedtch.c | |||
@@ -612,7 +612,8 @@ static void speedtch_handle_int(struct urb *int_urb) | |||
612 | struct speedtch_instance_data *instance = int_urb->context; | 612 | struct speedtch_instance_data *instance = int_urb->context; |
613 | struct usbatm_data *usbatm = instance->usbatm; | 613 | struct usbatm_data *usbatm = instance->usbatm; |
614 | unsigned int count = int_urb->actual_length; | 614 | unsigned int count = int_urb->actual_length; |
615 | int ret = int_urb->status; | 615 | int status = int_urb->status; |
616 | int ret; | ||
616 | 617 | ||
617 | /* The magic interrupt for "up state" */ | 618 | /* The magic interrupt for "up state" */ |
618 | static const unsigned char up_int[6] = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00 }; | 619 | static const unsigned char up_int[6] = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00 }; |
@@ -621,8 +622,8 @@ static void speedtch_handle_int(struct urb *int_urb) | |||
621 | 622 | ||
622 | atm_dbg(usbatm, "%s entered\n", __func__); | 623 | atm_dbg(usbatm, "%s entered\n", __func__); |
623 | 624 | ||
624 | if (ret < 0) { | 625 | if (status < 0) { |
625 | atm_dbg(usbatm, "%s: nonzero urb status %d!\n", __func__, ret); | 626 | atm_dbg(usbatm, "%s: nonzero urb status %d!\n", __func__, status); |
626 | goto fail; | 627 | goto fail; |
627 | } | 628 | } |
628 | 629 | ||
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c index 8f046659b4e9..a1a1c9d467e0 100644 --- a/drivers/usb/atm/ueagle-atm.c +++ b/drivers/usb/atm/ueagle-atm.c | |||
@@ -1308,11 +1308,13 @@ static void uea_intr(struct urb *urb) | |||
1308 | { | 1308 | { |
1309 | struct uea_softc *sc = urb->context; | 1309 | struct uea_softc *sc = urb->context; |
1310 | struct intr_pkt *intr = urb->transfer_buffer; | 1310 | struct intr_pkt *intr = urb->transfer_buffer; |
1311 | int status = urb->status; | ||
1312 | |||
1311 | uea_enters(INS_TO_USBDEV(sc)); | 1313 | uea_enters(INS_TO_USBDEV(sc)); |
1312 | 1314 | ||
1313 | if (unlikely(urb->status < 0)) { | 1315 | if (unlikely(status < 0)) { |
1314 | uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n", | 1316 | uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n", |
1315 | urb->status); | 1317 | status); |
1316 | return; | 1318 | return; |
1317 | } | 1319 | } |
1318 | 1320 | ||
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c index 11e9b15ca45a..e717f5b1caee 100644 --- a/drivers/usb/atm/usbatm.c +++ b/drivers/usb/atm/usbatm.c | |||
@@ -257,9 +257,10 @@ static void usbatm_complete(struct urb *urb) | |||
257 | { | 257 | { |
258 | struct usbatm_channel *channel = urb->context; | 258 | struct usbatm_channel *channel = urb->context; |
259 | unsigned long flags; | 259 | unsigned long flags; |
260 | int status = urb->status; | ||
260 | 261 | ||
261 | vdbg("%s: urb 0x%p, status %d, actual_length %d", | 262 | vdbg("%s: urb 0x%p, status %d, actual_length %d", |
262 | __func__, urb, urb->status, urb->actual_length); | 263 | __func__, urb, status, urb->actual_length); |
263 | 264 | ||
264 | /* usually in_interrupt(), but not always */ | 265 | /* usually in_interrupt(), but not always */ |
265 | spin_lock_irqsave(&channel->lock, flags); | 266 | spin_lock_irqsave(&channel->lock, flags); |
@@ -269,16 +270,16 @@ static void usbatm_complete(struct urb *urb) | |||
269 | 270 | ||
270 | spin_unlock_irqrestore(&channel->lock, flags); | 271 | spin_unlock_irqrestore(&channel->lock, flags); |
271 | 272 | ||
272 | if (unlikely(urb->status) && | 273 | if (unlikely(status) && |
273 | (!(channel->usbatm->flags & UDSL_IGNORE_EILSEQ) || | 274 | (!(channel->usbatm->flags & UDSL_IGNORE_EILSEQ) || |
274 | urb->status != -EILSEQ )) | 275 | status != -EILSEQ )) |
275 | { | 276 | { |
276 | if (urb->status == -ESHUTDOWN) | 277 | if (status == -ESHUTDOWN) |
277 | return; | 278 | return; |
278 | 279 | ||
279 | if (printk_ratelimit()) | 280 | if (printk_ratelimit()) |
280 | atm_warn(channel->usbatm, "%s: urb 0x%p failed (%d)!\n", | 281 | atm_warn(channel->usbatm, "%s: urb 0x%p failed (%d)!\n", |
281 | __func__, urb, urb->status); | 282 | __func__, urb, status); |
282 | /* throttle processing in case of an error */ | 283 | /* throttle processing in case of an error */ |
283 | mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS)); | 284 | mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS)); |
284 | } else | 285 | } else |
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index cd51520c7e72..fe940e0536e0 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c | |||
@@ -257,9 +257,10 @@ static void acm_ctrl_irq(struct urb *urb) | |||
257 | struct usb_cdc_notification *dr = urb->transfer_buffer; | 257 | struct usb_cdc_notification *dr = urb->transfer_buffer; |
258 | unsigned char *data; | 258 | unsigned char *data; |
259 | int newctrl; | 259 | int newctrl; |
260 | int status; | 260 | int retval; |
261 | int status = urb->status; | ||
261 | 262 | ||
262 | switch (urb->status) { | 263 | switch (status) { |
263 | case 0: | 264 | case 0: |
264 | /* success */ | 265 | /* success */ |
265 | break; | 266 | break; |
@@ -267,10 +268,10 @@ static void acm_ctrl_irq(struct urb *urb) | |||
267 | case -ENOENT: | 268 | case -ENOENT: |
268 | case -ESHUTDOWN: | 269 | case -ESHUTDOWN: |
269 | /* this urb is terminated, clean up */ | 270 | /* this urb is terminated, clean up */ |
270 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); | 271 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, status); |
271 | return; | 272 | return; |
272 | default: | 273 | default: |
273 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); | 274 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, status); |
274 | goto exit; | 275 | goto exit; |
275 | } | 276 | } |
276 | 277 | ||
@@ -311,10 +312,10 @@ static void acm_ctrl_irq(struct urb *urb) | |||
311 | break; | 312 | break; |
312 | } | 313 | } |
313 | exit: | 314 | exit: |
314 | status = usb_submit_urb (urb, GFP_ATOMIC); | 315 | retval = usb_submit_urb (urb, GFP_ATOMIC); |
315 | if (status) | 316 | if (retval) |
316 | err ("%s - usb_submit_urb failed with result %d", | 317 | err ("%s - usb_submit_urb failed with result %d", |
317 | __FUNCTION__, status); | 318 | __FUNCTION__, retval); |
318 | } | 319 | } |
319 | 320 | ||
320 | /* data interface returns incoming bytes, or we got unthrottled */ | 321 | /* data interface returns incoming bytes, or we got unthrottled */ |
@@ -324,7 +325,8 @@ static void acm_read_bulk(struct urb *urb) | |||
324 | struct acm_ru *rcv = urb->context; | 325 | struct acm_ru *rcv = urb->context; |
325 | struct acm *acm = rcv->instance; | 326 | struct acm *acm = rcv->instance; |
326 | int status = urb->status; | 327 | int status = urb->status; |
327 | dbg("Entering acm_read_bulk with status %d", urb->status); | 328 | |
329 | dbg("Entering acm_read_bulk with status %d", status); | ||
328 | 330 | ||
329 | if (!ACM_READY(acm)) | 331 | if (!ACM_READY(acm)) |
330 | return; | 332 | return; |
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c index 9a1478972bf5..5192cd9356de 100644 --- a/drivers/usb/class/usblp.c +++ b/drivers/usb/class/usblp.c | |||
@@ -289,16 +289,17 @@ static int proto_bias = -1; | |||
289 | static void usblp_bulk_read(struct urb *urb) | 289 | static void usblp_bulk_read(struct urb *urb) |
290 | { | 290 | { |
291 | struct usblp *usblp = urb->context; | 291 | struct usblp *usblp = urb->context; |
292 | int status = urb->status; | ||
292 | 293 | ||
293 | if (usblp->present && usblp->used) { | 294 | if (usblp->present && usblp->used) { |
294 | if (urb->status) | 295 | if (status) |
295 | printk(KERN_WARNING "usblp%d: " | 296 | printk(KERN_WARNING "usblp%d: " |
296 | "nonzero read bulk status received: %d\n", | 297 | "nonzero read bulk status received: %d\n", |
297 | usblp->minor, urb->status); | 298 | usblp->minor, status); |
298 | } | 299 | } |
299 | spin_lock(&usblp->lock); | 300 | spin_lock(&usblp->lock); |
300 | if (urb->status < 0) | 301 | if (status < 0) |
301 | usblp->rstatus = urb->status; | 302 | usblp->rstatus = status; |
302 | else | 303 | else |
303 | usblp->rstatus = urb->actual_length; | 304 | usblp->rstatus = urb->actual_length; |
304 | usblp->rcomplete = 1; | 305 | usblp->rcomplete = 1; |
@@ -311,16 +312,17 @@ static void usblp_bulk_read(struct urb *urb) | |||
311 | static void usblp_bulk_write(struct urb *urb) | 312 | static void usblp_bulk_write(struct urb *urb) |
312 | { | 313 | { |
313 | struct usblp *usblp = urb->context; | 314 | struct usblp *usblp = urb->context; |
315 | int status = urb->status; | ||
314 | 316 | ||
315 | if (usblp->present && usblp->used) { | 317 | if (usblp->present && usblp->used) { |
316 | if (urb->status) | 318 | if (status) |
317 | printk(KERN_WARNING "usblp%d: " | 319 | printk(KERN_WARNING "usblp%d: " |
318 | "nonzero write bulk status received: %d\n", | 320 | "nonzero write bulk status received: %d\n", |
319 | usblp->minor, urb->status); | 321 | usblp->minor, status); |
320 | } | 322 | } |
321 | spin_lock(&usblp->lock); | 323 | spin_lock(&usblp->lock); |
322 | if (urb->status < 0) | 324 | if (status < 0) |
323 | usblp->wstatus = urb->status; | 325 | usblp->wstatus = status; |
324 | else | 326 | else |
325 | usblp->wstatus = urb->actual_length; | 327 | usblp->wstatus = urb->actual_length; |
326 | usblp->wcomplete = 1; | 328 | usblp->wcomplete = 1; |
@@ -741,10 +743,11 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t | |||
741 | */ | 743 | */ |
742 | rv = usblp_wwait(usblp, !!(file->f_flags&O_NONBLOCK)); | 744 | rv = usblp_wwait(usblp, !!(file->f_flags&O_NONBLOCK)); |
743 | if (rv < 0) { | 745 | if (rv < 0) { |
744 | /* | 746 | if (rv == -EAGAIN) { |
745 | * If interrupted, we simply leave the URB to dangle, | 747 | /* Presume that it's going to complete well. */ |
746 | * so the ->release will call usb_kill_urb(). | 748 | writecount += transfer_length; |
747 | */ | 749 | } |
750 | /* Leave URB dangling, to be cleaned on close. */ | ||
748 | goto collect_error; | 751 | goto collect_error; |
749 | } | 752 | } |
750 | 753 | ||
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 963520fbef90..42ef1d5f6c8a 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c | |||
@@ -99,12 +99,17 @@ EXPORT_SYMBOL_GPL (usb_bus_list_lock); | |||
99 | /* used for controlling access to virtual root hubs */ | 99 | /* used for controlling access to virtual root hubs */ |
100 | static DEFINE_SPINLOCK(hcd_root_hub_lock); | 100 | static DEFINE_SPINLOCK(hcd_root_hub_lock); |
101 | 101 | ||
102 | /* used when updating hcd data */ | 102 | /* used when updating an endpoint's URB list */ |
103 | static DEFINE_SPINLOCK(hcd_data_lock); | 103 | static DEFINE_SPINLOCK(hcd_urb_list_lock); |
104 | 104 | ||
105 | /* wait queue for synchronous unlinks */ | 105 | /* wait queue for synchronous unlinks */ |
106 | DECLARE_WAIT_QUEUE_HEAD(usb_kill_urb_queue); | 106 | DECLARE_WAIT_QUEUE_HEAD(usb_kill_urb_queue); |
107 | 107 | ||
108 | static inline int is_root_hub(struct usb_device *udev) | ||
109 | { | ||
110 | return (udev->parent == NULL); | ||
111 | } | ||
112 | |||
108 | /*-------------------------------------------------------------------------*/ | 113 | /*-------------------------------------------------------------------------*/ |
109 | 114 | ||
110 | /* | 115 | /* |
@@ -906,14 +911,13 @@ EXPORT_SYMBOL (usb_calc_bus_time); | |||
906 | static void urb_unlink(struct usb_hcd *hcd, struct urb *urb) | 911 | static void urb_unlink(struct usb_hcd *hcd, struct urb *urb) |
907 | { | 912 | { |
908 | unsigned long flags; | 913 | unsigned long flags; |
909 | int at_root_hub = (urb->dev == hcd->self.root_hub); | ||
910 | 914 | ||
911 | /* clear all state linking urb to this dev (and hcd) */ | 915 | /* clear all state linking urb to this dev (and hcd) */ |
912 | spin_lock_irqsave (&hcd_data_lock, flags); | 916 | spin_lock_irqsave(&hcd_urb_list_lock, flags); |
913 | list_del_init (&urb->urb_list); | 917 | list_del_init (&urb->urb_list); |
914 | spin_unlock_irqrestore (&hcd_data_lock, flags); | 918 | spin_unlock_irqrestore(&hcd_urb_list_lock, flags); |
915 | 919 | ||
916 | if (hcd->self.uses_dma && !at_root_hub) { | 920 | if (hcd->self.uses_dma && !is_root_hub(urb->dev)) { |
917 | if (usb_pipecontrol (urb->pipe) | 921 | if (usb_pipecontrol (urb->pipe) |
918 | && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) | 922 | && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) |
919 | dma_unmap_single (hcd->self.controller, urb->setup_dma, | 923 | dma_unmap_single (hcd->self.controller, urb->setup_dma, |
@@ -955,7 +959,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags) | |||
955 | 959 | ||
956 | // FIXME: verify that quiescing hc works right (RH cleans up) | 960 | // FIXME: verify that quiescing hc works right (RH cleans up) |
957 | 961 | ||
958 | spin_lock_irqsave (&hcd_data_lock, flags); | 962 | spin_lock_irqsave(&hcd_urb_list_lock, flags); |
959 | ep = (usb_pipein(urb->pipe) ? urb->dev->ep_in : urb->dev->ep_out) | 963 | ep = (usb_pipein(urb->pipe) ? urb->dev->ep_in : urb->dev->ep_out) |
960 | [usb_pipeendpoint(urb->pipe)]; | 964 | [usb_pipeendpoint(urb->pipe)]; |
961 | if (unlikely (!ep)) | 965 | if (unlikely (!ep)) |
@@ -972,7 +976,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags) | |||
972 | status = -ESHUTDOWN; | 976 | status = -ESHUTDOWN; |
973 | break; | 977 | break; |
974 | } | 978 | } |
975 | spin_unlock_irqrestore (&hcd_data_lock, flags); | 979 | spin_unlock_irqrestore(&hcd_urb_list_lock, flags); |
976 | if (status) { | 980 | if (status) { |
977 | INIT_LIST_HEAD (&urb->urb_list); | 981 | INIT_LIST_HEAD (&urb->urb_list); |
978 | usbmon_urb_submit_error(&hcd->self, urb, status); | 982 | usbmon_urb_submit_error(&hcd->self, urb, status); |
@@ -986,7 +990,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags) | |||
986 | urb = usb_get_urb (urb); | 990 | urb = usb_get_urb (urb); |
987 | atomic_inc (&urb->use_count); | 991 | atomic_inc (&urb->use_count); |
988 | 992 | ||
989 | if (urb->dev == hcd->self.root_hub) { | 993 | if (is_root_hub(urb->dev)) { |
990 | /* NOTE: requirement on hub callers (usbfs and the hub | 994 | /* NOTE: requirement on hub callers (usbfs and the hub |
991 | * driver, for now) that URBs' urb->transfer_buffer be | 995 | * driver, for now) that URBs' urb->transfer_buffer be |
992 | * valid and usb_buffer_{sync,unmap}() not be needed, since | 996 | * valid and usb_buffer_{sync,unmap}() not be needed, since |
@@ -1033,18 +1037,6 @@ done: | |||
1033 | 1037 | ||
1034 | /*-------------------------------------------------------------------------*/ | 1038 | /*-------------------------------------------------------------------------*/ |
1035 | 1039 | ||
1036 | /* called in any context */ | ||
1037 | int usb_hcd_get_frame_number (struct usb_device *udev) | ||
1038 | { | ||
1039 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); | ||
1040 | |||
1041 | if (!HC_IS_RUNNING (hcd->state)) | ||
1042 | return -ESHUTDOWN; | ||
1043 | return hcd->driver->get_frame_number (hcd); | ||
1044 | } | ||
1045 | |||
1046 | /*-------------------------------------------------------------------------*/ | ||
1047 | |||
1048 | /* this makes the hcd giveback() the urb more quickly, by kicking it | 1040 | /* this makes the hcd giveback() the urb more quickly, by kicking it |
1049 | * off hardware queues (which may take a while) and returning it as | 1041 | * off hardware queues (which may take a while) and returning it as |
1050 | * soon as practical. we've already set up the urb's return status, | 1042 | * soon as practical. we've already set up the urb's return status, |
@@ -1055,7 +1047,7 @@ unlink1 (struct usb_hcd *hcd, struct urb *urb) | |||
1055 | { | 1047 | { |
1056 | int value; | 1048 | int value; |
1057 | 1049 | ||
1058 | if (urb->dev == hcd->self.root_hub) | 1050 | if (is_root_hub(urb->dev)) |
1059 | value = usb_rh_urb_dequeue (hcd, urb); | 1051 | value = usb_rh_urb_dequeue (hcd, urb); |
1060 | else { | 1052 | else { |
1061 | 1053 | ||
@@ -1103,11 +1095,11 @@ int usb_hcd_unlink_urb (struct urb *urb, int status) | |||
1103 | * that it was submitted. But as a rule it can't know whether or | 1095 | * that it was submitted. But as a rule it can't know whether or |
1104 | * not it's already been unlinked ... so we respect the reversed | 1096 | * not it's already been unlinked ... so we respect the reversed |
1105 | * lock sequence needed for the usb_hcd_giveback_urb() code paths | 1097 | * lock sequence needed for the usb_hcd_giveback_urb() code paths |
1106 | * (urb lock, then hcd_data_lock) in case some other CPU is now | 1098 | * (urb lock, then hcd_urb_list_lock) in case some other CPU is now |
1107 | * unlinking it. | 1099 | * unlinking it. |
1108 | */ | 1100 | */ |
1109 | spin_lock_irqsave (&urb->lock, flags); | 1101 | spin_lock_irqsave (&urb->lock, flags); |
1110 | spin_lock (&hcd_data_lock); | 1102 | spin_lock(&hcd_urb_list_lock); |
1111 | 1103 | ||
1112 | sys = &urb->dev->dev; | 1104 | sys = &urb->dev->dev; |
1113 | hcd = bus_to_hcd(urb->dev->bus); | 1105 | hcd = bus_to_hcd(urb->dev->bus); |
@@ -1139,17 +1131,16 @@ int usb_hcd_unlink_urb (struct urb *urb, int status) | |||
1139 | * finish unlinking the initial failed usb_set_address() | 1131 | * finish unlinking the initial failed usb_set_address() |
1140 | * or device descriptor fetch. | 1132 | * or device descriptor fetch. |
1141 | */ | 1133 | */ |
1142 | if (!test_bit(HCD_FLAG_SAW_IRQ, &hcd->flags) | 1134 | if (!test_bit(HCD_FLAG_SAW_IRQ, &hcd->flags) && |
1143 | && hcd->self.root_hub != urb->dev) { | 1135 | !is_root_hub(urb->dev)) { |
1144 | dev_warn (hcd->self.controller, "Unlink after no-IRQ? " | 1136 | dev_warn (hcd->self.controller, "Unlink after no-IRQ? " |
1145 | "Controller is probably using the wrong IRQ." | 1137 | "Controller is probably using the wrong IRQ.\n"); |
1146 | "\n"); | ||
1147 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); | 1138 | set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); |
1148 | } | 1139 | } |
1149 | 1140 | ||
1150 | urb->status = status; | 1141 | urb->status = status; |
1151 | 1142 | ||
1152 | spin_unlock (&hcd_data_lock); | 1143 | spin_unlock(&hcd_urb_list_lock); |
1153 | spin_unlock_irqrestore (&urb->lock, flags); | 1144 | spin_unlock_irqrestore (&urb->lock, flags); |
1154 | 1145 | ||
1155 | retval = unlink1 (hcd, urb); | 1146 | retval = unlink1 (hcd, urb); |
@@ -1158,7 +1149,7 @@ int usb_hcd_unlink_urb (struct urb *urb, int status) | |||
1158 | return retval; | 1149 | return retval; |
1159 | 1150 | ||
1160 | done: | 1151 | done: |
1161 | spin_unlock (&hcd_data_lock); | 1152 | spin_unlock(&hcd_urb_list_lock); |
1162 | spin_unlock_irqrestore (&urb->lock, flags); | 1153 | spin_unlock_irqrestore (&urb->lock, flags); |
1163 | if (retval != -EIDRM && sys && sys->driver) | 1154 | if (retval != -EIDRM && sys && sys->driver) |
1164 | dev_dbg (sys, "hcd_unlink_urb %p fail %d\n", urb, retval); | 1155 | dev_dbg (sys, "hcd_unlink_urb %p fail %d\n", urb, retval); |
@@ -1167,6 +1158,35 @@ done: | |||
1167 | 1158 | ||
1168 | /*-------------------------------------------------------------------------*/ | 1159 | /*-------------------------------------------------------------------------*/ |
1169 | 1160 | ||
1161 | /** | ||
1162 | * usb_hcd_giveback_urb - return URB from HCD to device driver | ||
1163 | * @hcd: host controller returning the URB | ||
1164 | * @urb: urb being returned to the USB device driver. | ||
1165 | * Context: in_interrupt() | ||
1166 | * | ||
1167 | * This hands the URB from HCD to its USB device driver, using its | ||
1168 | * completion function. The HCD has freed all per-urb resources | ||
1169 | * (and is done using urb->hcpriv). It also released all HCD locks; | ||
1170 | * the device driver won't cause problems if it frees, modifies, | ||
1171 | * or resubmits this URB. | ||
1172 | */ | ||
1173 | void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb) | ||
1174 | { | ||
1175 | urb_unlink(hcd, urb); | ||
1176 | usbmon_urb_complete (&hcd->self, urb); | ||
1177 | usb_unanchor_urb(urb); | ||
1178 | |||
1179 | /* pass ownership to the completion handler */ | ||
1180 | urb->complete (urb); | ||
1181 | atomic_dec (&urb->use_count); | ||
1182 | if (unlikely (urb->reject)) | ||
1183 | wake_up (&usb_kill_urb_queue); | ||
1184 | usb_put_urb (urb); | ||
1185 | } | ||
1186 | EXPORT_SYMBOL (usb_hcd_giveback_urb); | ||
1187 | |||
1188 | /*-------------------------------------------------------------------------*/ | ||
1189 | |||
1170 | /* disables the endpoint: cancels any pending urbs, then synchronizes with | 1190 | /* disables the endpoint: cancels any pending urbs, then synchronizes with |
1171 | * the hcd to make sure all endpoint state is gone from hardware, and then | 1191 | * the hcd to make sure all endpoint state is gone from hardware, and then |
1172 | * waits until the endpoint's queue is completely drained. use for | 1192 | * waits until the endpoint's queue is completely drained. use for |
@@ -1186,7 +1206,7 @@ void usb_hcd_endpoint_disable (struct usb_device *udev, | |||
1186 | 1206 | ||
1187 | /* ep is already gone from udev->ep_{in,out}[]; no more submits */ | 1207 | /* ep is already gone from udev->ep_{in,out}[]; no more submits */ |
1188 | rescan: | 1208 | rescan: |
1189 | spin_lock (&hcd_data_lock); | 1209 | spin_lock(&hcd_urb_list_lock); |
1190 | list_for_each_entry (urb, &ep->urb_list, urb_list) { | 1210 | list_for_each_entry (urb, &ep->urb_list, urb_list) { |
1191 | int tmp; | 1211 | int tmp; |
1192 | 1212 | ||
@@ -1194,7 +1214,7 @@ rescan: | |||
1194 | if (urb->status != -EINPROGRESS) | 1214 | if (urb->status != -EINPROGRESS) |
1195 | continue; | 1215 | continue; |
1196 | usb_get_urb (urb); | 1216 | usb_get_urb (urb); |
1197 | spin_unlock (&hcd_data_lock); | 1217 | spin_unlock(&hcd_urb_list_lock); |
1198 | 1218 | ||
1199 | spin_lock (&urb->lock); | 1219 | spin_lock (&urb->lock); |
1200 | tmp = urb->status; | 1220 | tmp = urb->status; |
@@ -1223,7 +1243,7 @@ rescan: | |||
1223 | /* list contents may have changed */ | 1243 | /* list contents may have changed */ |
1224 | goto rescan; | 1244 | goto rescan; |
1225 | } | 1245 | } |
1226 | spin_unlock (&hcd_data_lock); | 1246 | spin_unlock(&hcd_urb_list_lock); |
1227 | local_irq_enable (); | 1247 | local_irq_enable (); |
1228 | 1248 | ||
1229 | /* synchronize with the hardware, so old configuration state | 1249 | /* synchronize with the hardware, so old configuration state |
@@ -1240,7 +1260,7 @@ rescan: | |||
1240 | * endpoint_disable methods. | 1260 | * endpoint_disable methods. |
1241 | */ | 1261 | */ |
1242 | while (!list_empty (&ep->urb_list)) { | 1262 | while (!list_empty (&ep->urb_list)) { |
1243 | spin_lock_irq (&hcd_data_lock); | 1263 | spin_lock_irq(&hcd_urb_list_lock); |
1244 | 1264 | ||
1245 | /* The list may have changed while we acquired the spinlock */ | 1265 | /* The list may have changed while we acquired the spinlock */ |
1246 | urb = NULL; | 1266 | urb = NULL; |
@@ -1249,7 +1269,7 @@ rescan: | |||
1249 | urb_list); | 1269 | urb_list); |
1250 | usb_get_urb (urb); | 1270 | usb_get_urb (urb); |
1251 | } | 1271 | } |
1252 | spin_unlock_irq (&hcd_data_lock); | 1272 | spin_unlock_irq(&hcd_urb_list_lock); |
1253 | 1273 | ||
1254 | if (urb) { | 1274 | if (urb) { |
1255 | usb_kill_urb (urb); | 1275 | usb_kill_urb (urb); |
@@ -1260,6 +1280,18 @@ rescan: | |||
1260 | 1280 | ||
1261 | /*-------------------------------------------------------------------------*/ | 1281 | /*-------------------------------------------------------------------------*/ |
1262 | 1282 | ||
1283 | /* called in any context */ | ||
1284 | int usb_hcd_get_frame_number (struct usb_device *udev) | ||
1285 | { | ||
1286 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); | ||
1287 | |||
1288 | if (!HC_IS_RUNNING (hcd->state)) | ||
1289 | return -ESHUTDOWN; | ||
1290 | return hcd->driver->get_frame_number (hcd); | ||
1291 | } | ||
1292 | |||
1293 | /*-------------------------------------------------------------------------*/ | ||
1294 | |||
1263 | #ifdef CONFIG_PM | 1295 | #ifdef CONFIG_PM |
1264 | 1296 | ||
1265 | int hcd_bus_suspend(struct usb_device *rhdev) | 1297 | int hcd_bus_suspend(struct usb_device *rhdev) |
@@ -1395,35 +1427,6 @@ EXPORT_SYMBOL (usb_bus_start_enum); | |||
1395 | /*-------------------------------------------------------------------------*/ | 1427 | /*-------------------------------------------------------------------------*/ |
1396 | 1428 | ||
1397 | /** | 1429 | /** |
1398 | * usb_hcd_giveback_urb - return URB from HCD to device driver | ||
1399 | * @hcd: host controller returning the URB | ||
1400 | * @urb: urb being returned to the USB device driver. | ||
1401 | * Context: in_interrupt() | ||
1402 | * | ||
1403 | * This hands the URB from HCD to its USB device driver, using its | ||
1404 | * completion function. The HCD has freed all per-urb resources | ||
1405 | * (and is done using urb->hcpriv). It also released all HCD locks; | ||
1406 | * the device driver won't cause problems if it frees, modifies, | ||
1407 | * or resubmits this URB. | ||
1408 | */ | ||
1409 | void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb) | ||
1410 | { | ||
1411 | urb_unlink(hcd, urb); | ||
1412 | usbmon_urb_complete (&hcd->self, urb); | ||
1413 | usb_unanchor_urb(urb); | ||
1414 | |||
1415 | /* pass ownership to the completion handler */ | ||
1416 | urb->complete (urb); | ||
1417 | atomic_dec (&urb->use_count); | ||
1418 | if (unlikely (urb->reject)) | ||
1419 | wake_up (&usb_kill_urb_queue); | ||
1420 | usb_put_urb (urb); | ||
1421 | } | ||
1422 | EXPORT_SYMBOL (usb_hcd_giveback_urb); | ||
1423 | |||
1424 | /*-------------------------------------------------------------------------*/ | ||
1425 | |||
1426 | /** | ||
1427 | * usb_hcd_irq - hook IRQs to HCD framework (bus glue) | 1430 | * usb_hcd_irq - hook IRQs to HCD framework (bus glue) |
1428 | * @irq: the IRQ being raised | 1431 | * @irq: the IRQ being raised |
1429 | * @__hcd: pointer to the HCD whose IRQ is being signaled | 1432 | * @__hcd: pointer to the HCD whose IRQ is being signaled |
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index fd74c50b1804..e341a1da517f 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -1335,6 +1335,10 @@ int usb_new_device(struct usb_device *udev) | |||
1335 | udev->dev.devt = MKDEV(USB_DEVICE_MAJOR, | 1335 | udev->dev.devt = MKDEV(USB_DEVICE_MAJOR, |
1336 | (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); | 1336 | (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); |
1337 | 1337 | ||
1338 | /* Increment the parent's count of unsuspended children */ | ||
1339 | if (udev->parent) | ||
1340 | usb_autoresume_device(udev->parent); | ||
1341 | |||
1338 | /* Register the device. The device driver is responsible | 1342 | /* Register the device. The device driver is responsible |
1339 | * for adding the device files to sysfs and for configuring | 1343 | * for adding the device files to sysfs and for configuring |
1340 | * the device. | 1344 | * the device. |
@@ -1342,13 +1346,11 @@ int usb_new_device(struct usb_device *udev) | |||
1342 | err = device_add(&udev->dev); | 1346 | err = device_add(&udev->dev); |
1343 | if (err) { | 1347 | if (err) { |
1344 | dev_err(&udev->dev, "can't device_add, error %d\n", err); | 1348 | dev_err(&udev->dev, "can't device_add, error %d\n", err); |
1349 | if (udev->parent) | ||
1350 | usb_autosuspend_device(udev->parent); | ||
1345 | goto fail; | 1351 | goto fail; |
1346 | } | 1352 | } |
1347 | 1353 | ||
1348 | /* Increment the parent's count of unsuspended children */ | ||
1349 | if (udev->parent) | ||
1350 | usb_autoresume_device(udev->parent); | ||
1351 | |||
1352 | exit: | 1354 | exit: |
1353 | return err; | 1355 | return err; |
1354 | 1356 | ||
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index 530e854961ce..25f63f1096b4 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c | |||
@@ -34,13 +34,14 @@ static int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length) | |||
34 | { | 34 | { |
35 | struct completion done; | 35 | struct completion done; |
36 | unsigned long expire; | 36 | unsigned long expire; |
37 | int status; | 37 | int retval; |
38 | int status = urb->status; | ||
38 | 39 | ||
39 | init_completion(&done); | 40 | init_completion(&done); |
40 | urb->context = &done; | 41 | urb->context = &done; |
41 | urb->actual_length = 0; | 42 | urb->actual_length = 0; |
42 | status = usb_submit_urb(urb, GFP_NOIO); | 43 | retval = usb_submit_urb(urb, GFP_NOIO); |
43 | if (unlikely(status)) | 44 | if (unlikely(retval)) |
44 | goto out; | 45 | goto out; |
45 | 46 | ||
46 | expire = timeout ? msecs_to_jiffies(timeout) : MAX_SCHEDULE_TIMEOUT; | 47 | expire = timeout ? msecs_to_jiffies(timeout) : MAX_SCHEDULE_TIMEOUT; |
@@ -55,15 +56,15 @@ static int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length) | |||
55 | urb->transfer_buffer_length); | 56 | urb->transfer_buffer_length); |
56 | 57 | ||
57 | usb_kill_urb(urb); | 58 | usb_kill_urb(urb); |
58 | status = urb->status == -ENOENT ? -ETIMEDOUT : urb->status; | 59 | retval = status == -ENOENT ? -ETIMEDOUT : status; |
59 | } else | 60 | } else |
60 | status = urb->status; | 61 | retval = status; |
61 | out: | 62 | out: |
62 | if (actual_length) | 63 | if (actual_length) |
63 | *actual_length = urb->actual_length; | 64 | *actual_length = urb->actual_length; |
64 | 65 | ||
65 | usb_free_urb(urb); | 66 | usb_free_urb(urb); |
66 | return status; | 67 | return retval; |
67 | } | 68 | } |
68 | 69 | ||
69 | /*-------------------------------------------------------------------*/ | 70 | /*-------------------------------------------------------------------*/ |
@@ -250,6 +251,7 @@ static void sg_clean (struct usb_sg_request *io) | |||
250 | static void sg_complete (struct urb *urb) | 251 | static void sg_complete (struct urb *urb) |
251 | { | 252 | { |
252 | struct usb_sg_request *io = urb->context; | 253 | struct usb_sg_request *io = urb->context; |
254 | int status = urb->status; | ||
253 | 255 | ||
254 | spin_lock (&io->lock); | 256 | spin_lock (&io->lock); |
255 | 257 | ||
@@ -265,21 +267,21 @@ static void sg_complete (struct urb *urb) | |||
265 | */ | 267 | */ |
266 | if (io->status | 268 | if (io->status |
267 | && (io->status != -ECONNRESET | 269 | && (io->status != -ECONNRESET |
268 | || urb->status != -ECONNRESET) | 270 | || status != -ECONNRESET) |
269 | && urb->actual_length) { | 271 | && urb->actual_length) { |
270 | dev_err (io->dev->bus->controller, | 272 | dev_err (io->dev->bus->controller, |
271 | "dev %s ep%d%s scatterlist error %d/%d\n", | 273 | "dev %s ep%d%s scatterlist error %d/%d\n", |
272 | io->dev->devpath, | 274 | io->dev->devpath, |
273 | usb_pipeendpoint (urb->pipe), | 275 | usb_pipeendpoint (urb->pipe), |
274 | usb_pipein (urb->pipe) ? "in" : "out", | 276 | usb_pipein (urb->pipe) ? "in" : "out", |
275 | urb->status, io->status); | 277 | status, io->status); |
276 | // BUG (); | 278 | // BUG (); |
277 | } | 279 | } |
278 | 280 | ||
279 | if (io->status == 0 && urb->status && urb->status != -ECONNRESET) { | 281 | if (io->status == 0 && status && status != -ECONNRESET) { |
280 | int i, found, status; | 282 | int i, found, retval; |
281 | 283 | ||
282 | io->status = urb->status; | 284 | io->status = status; |
283 | 285 | ||
284 | /* the previous urbs, and this one, completed already. | 286 | /* the previous urbs, and this one, completed already. |
285 | * unlink pending urbs so they won't rx/tx bad data. | 287 | * unlink pending urbs so they won't rx/tx bad data. |
@@ -290,13 +292,13 @@ static void sg_complete (struct urb *urb) | |||
290 | if (!io->urbs [i] || !io->urbs [i]->dev) | 292 | if (!io->urbs [i] || !io->urbs [i]->dev) |
291 | continue; | 293 | continue; |
292 | if (found) { | 294 | if (found) { |
293 | status = usb_unlink_urb (io->urbs [i]); | 295 | retval = usb_unlink_urb (io->urbs [i]); |
294 | if (status != -EINPROGRESS | 296 | if (retval != -EINPROGRESS && |
295 | && status != -ENODEV | 297 | retval != -ENODEV && |
296 | && status != -EBUSY) | 298 | retval != -EBUSY) |
297 | dev_err (&io->dev->dev, | 299 | dev_err (&io->dev->dev, |
298 | "%s, unlink --> %d\n", | 300 | "%s, unlink --> %d\n", |
299 | __FUNCTION__, status); | 301 | __FUNCTION__, retval); |
300 | } else if (urb == io->urbs [i]) | 302 | } else if (urb == io->urbs [i]) |
301 | found = 1; | 303 | found = 1; |
302 | } | 304 | } |
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index d47ae89154a7..2ab222be8fd1 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c | |||
@@ -441,6 +441,54 @@ static struct attribute_group dev_attr_grp = { | |||
441 | .attrs = dev_attrs, | 441 | .attrs = dev_attrs, |
442 | }; | 442 | }; |
443 | 443 | ||
444 | /* Binary descriptors */ | ||
445 | |||
446 | static ssize_t | ||
447 | read_descriptors(struct kobject *kobj, struct bin_attribute *attr, | ||
448 | char *buf, loff_t off, size_t count) | ||
449 | { | ||
450 | struct usb_device *udev = to_usb_device( | ||
451 | container_of(kobj, struct device, kobj)); | ||
452 | size_t nleft = count; | ||
453 | size_t srclen, n; | ||
454 | |||
455 | usb_lock_device(udev); | ||
456 | |||
457 | /* The binary attribute begins with the device descriptor */ | ||
458 | srclen = sizeof(struct usb_device_descriptor); | ||
459 | if (off < srclen) { | ||
460 | n = min_t(size_t, nleft, srclen - off); | ||
461 | memcpy(buf, off + (char *) &udev->descriptor, n); | ||
462 | nleft -= n; | ||
463 | buf += n; | ||
464 | off = 0; | ||
465 | } else { | ||
466 | off -= srclen; | ||
467 | } | ||
468 | |||
469 | /* Then follows the raw descriptor entry for the current | ||
470 | * configuration (config plus subsidiary descriptors). | ||
471 | */ | ||
472 | if (udev->actconfig) { | ||
473 | int cfgno = udev->actconfig - udev->config; | ||
474 | |||
475 | srclen = __le16_to_cpu(udev->actconfig->desc.wTotalLength); | ||
476 | if (off < srclen) { | ||
477 | n = min_t(size_t, nleft, srclen - off); | ||
478 | memcpy(buf, off + udev->rawdescriptors[cfgno], n); | ||
479 | nleft -= n; | ||
480 | } | ||
481 | } | ||
482 | usb_unlock_device(udev); | ||
483 | return count - nleft; | ||
484 | } | ||
485 | |||
486 | static struct bin_attribute dev_bin_attr_descriptors = { | ||
487 | .attr = {.name = "descriptors", .mode = 0444}, | ||
488 | .read = read_descriptors, | ||
489 | .size = 18 + 65535, /* dev descr + max-size raw descriptor */ | ||
490 | }; | ||
491 | |||
444 | int usb_create_sysfs_dev_files(struct usb_device *udev) | 492 | int usb_create_sysfs_dev_files(struct usb_device *udev) |
445 | { | 493 | { |
446 | struct device *dev = &udev->dev; | 494 | struct device *dev = &udev->dev; |
@@ -450,6 +498,10 @@ int usb_create_sysfs_dev_files(struct usb_device *udev) | |||
450 | if (retval) | 498 | if (retval) |
451 | return retval; | 499 | return retval; |
452 | 500 | ||
501 | retval = device_create_bin_file(dev, &dev_bin_attr_descriptors); | ||
502 | if (retval) | ||
503 | goto error; | ||
504 | |||
453 | retval = add_persist_attributes(dev); | 505 | retval = add_persist_attributes(dev); |
454 | if (retval) | 506 | if (retval) |
455 | goto error; | 507 | goto error; |
@@ -492,6 +544,7 @@ void usb_remove_sysfs_dev_files(struct usb_device *udev) | |||
492 | device_remove_file(dev, &dev_attr_serial); | 544 | device_remove_file(dev, &dev_attr_serial); |
493 | remove_power_attributes(dev); | 545 | remove_power_attributes(dev); |
494 | remove_persist_attributes(dev); | 546 | remove_persist_attributes(dev); |
547 | device_remove_bin_file(dev, &dev_bin_attr_descriptors); | ||
495 | sysfs_remove_group(&dev->kobj, &dev_attr_grp); | 548 | sysfs_remove_group(&dev->kobj, &dev_attr_grp); |
496 | } | 549 | } |
497 | 550 | ||
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c index 52ec44b828f3..be630228461c 100644 --- a/drivers/usb/core/urb.c +++ b/drivers/usb/core/urb.c | |||
@@ -440,55 +440,57 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | |||
440 | * @urb: pointer to urb describing a previously submitted request, | 440 | * @urb: pointer to urb describing a previously submitted request, |
441 | * may be NULL | 441 | * may be NULL |
442 | * | 442 | * |
443 | * This routine cancels an in-progress request. URBs complete only | 443 | * This routine cancels an in-progress request. URBs complete only once |
444 | * once per submission, and may be canceled only once per submission. | 444 | * per submission, and may be canceled only once per submission. |
445 | * Successful cancellation means the requests's completion handler will | 445 | * Successful cancellation means termination of @urb will be expedited |
446 | * be called with a status code indicating that the request has been | 446 | * and the completion handler will be called with a status code |
447 | * canceled (rather than any other code) and will quickly be removed | 447 | * indicating that the request has been canceled (rather than any other |
448 | * from host controller data structures. | 448 | * code). |
449 | * | 449 | * |
450 | * This request is always asynchronous. | 450 | * This request is always asynchronous. Success is indicated by |
451 | * Success is indicated by returning -EINPROGRESS, | 451 | * returning -EINPROGRESS, at which time the URB will probably not yet |
452 | * at which time the URB will normally have been unlinked but not yet | 452 | * have been given back to the device driver. When it is eventually |
453 | * given back to the device driver. When it is called, the completion | 453 | * called, the completion function will see @urb->status == -ECONNRESET. |
454 | * function will see urb->status == -ECONNRESET. Failure is indicated | 454 | * Failure is indicated by usb_unlink_urb() returning any other value. |
455 | * by any other return value. Unlinking will fail when the URB is not | 455 | * Unlinking will fail when @urb is not currently "linked" (i.e., it was |
456 | * currently "linked" (i.e., it was never submitted, or it was unlinked | 456 | * never submitted, or it was unlinked before, or the hardware is already |
457 | * before, or the hardware is already finished with it), even if the | 457 | * finished with it), even if the completion handler has not yet run. |
458 | * completion handler has not yet run. | ||
459 | * | 458 | * |
460 | * Unlinking and Endpoint Queues: | 459 | * Unlinking and Endpoint Queues: |
461 | * | 460 | * |
461 | * [The behaviors and guarantees described below do not apply to virtual | ||
462 | * root hubs but only to endpoint queues for physical USB devices.] | ||
463 | * | ||
462 | * Host Controller Drivers (HCDs) place all the URBs for a particular | 464 | * Host Controller Drivers (HCDs) place all the URBs for a particular |
463 | * endpoint in a queue. Normally the queue advances as the controller | 465 | * endpoint in a queue. Normally the queue advances as the controller |
464 | * hardware processes each request. But when an URB terminates with an | 466 | * hardware processes each request. But when an URB terminates with an |
465 | * error its queue stops, at least until that URB's completion routine | 467 | * error its queue generally stops (see below), at least until that URB's |
466 | * returns. It is guaranteed that the queue will not restart until all | 468 | * completion routine returns. It is guaranteed that a stopped queue |
467 | * its unlinked URBs have been fully retired, with their completion | 469 | * will not restart until all its unlinked URBs have been fully retired, |
468 | * routines run, even if that's not until some time after the original | 470 | * with their completion routines run, even if that's not until some time |
469 | * completion handler returns. Normally the same behavior and guarantees | 471 | * after the original completion handler returns. The same behavior and |
470 | * apply when an URB terminates because it was unlinked; however if an | 472 | * guarantee apply when an URB terminates because it was unlinked. |
471 | * URB is unlinked before the hardware has started to execute it, then | 473 | * |
472 | * its queue is not guaranteed to stop until all the preceding URBs have | 474 | * Bulk and interrupt endpoint queues are guaranteed to stop whenever an |
473 | * completed. | 475 | * URB terminates with any sort of error, including -ECONNRESET, -ENOENT, |
474 | * | 476 | * and -EREMOTEIO. Control endpoint queues behave the same way except |
475 | * This means that USB device drivers can safely build deep queues for | 477 | * that they are not guaranteed to stop for -EREMOTEIO errors. Queues |
476 | * large or complex transfers, and clean them up reliably after any sort | 478 | * for isochronous endpoints are treated differently, because they must |
477 | * of aborted transfer by unlinking all pending URBs at the first fault. | 479 | * advance at fixed rates. Such queues do not stop when an URB |
478 | * | 480 | * encounters an error or is unlinked. An unlinked isochronous URB may |
479 | * Note that an URB terminating early because a short packet was received | 481 | * leave a gap in the stream of packets; it is undefined whether such |
480 | * will count as an error if and only if the URB_SHORT_NOT_OK flag is set. | 482 | * gaps can be filled in. |
481 | * Also, that all unlinks performed in any URB completion handler must | 483 | * |
482 | * be asynchronous. | 484 | * Note that early termination of an URB because a short packet was |
483 | * | 485 | * received will generate a -EREMOTEIO error if and only if the |
484 | * Queues for isochronous endpoints are treated differently, because they | 486 | * URB_SHORT_NOT_OK flag is set. By setting this flag, USB device |
485 | * advance at fixed rates. Such queues do not stop when an URB is unlinked. | 487 | * drivers can build deep queues for large or complex bulk transfers |
486 | * An unlinked URB may leave a gap in the stream of packets. It is undefined | 488 | * and clean them up reliably after any sort of aborted transfer by |
487 | * whether such gaps can be filled in. | 489 | * unlinking all pending URBs at the first fault. |
488 | * | 490 | * |
489 | * When a control URB terminates with an error, it is likely that the | 491 | * When a control URB terminates with an error other than -EREMOTEIO, it |
490 | * status stage of the transfer will not take place, even if it is merely | 492 | * is quite likely that the status stage of the transfer will not take |
491 | * a soft error resulting from a short-packet with URB_SHORT_NOT_OK set. | 493 | * place. |
492 | */ | 494 | */ |
493 | int usb_unlink_urb(struct urb *urb) | 495 | int usb_unlink_urb(struct urb *urb) |
494 | { | 496 | { |
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 45e01e289455..767aed5b4bea 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig | |||
@@ -82,6 +82,27 @@ choice | |||
82 | Many controller drivers are platform-specific; these | 82 | Many controller drivers are platform-specific; these |
83 | often need board-specific hooks. | 83 | often need board-specific hooks. |
84 | 84 | ||
85 | config USB_GADGET_AMD5536UDC | ||
86 | boolean "AMD5536 UDC" | ||
87 | depends on PCI | ||
88 | select USB_GADGET_DUALSPEED | ||
89 | help | ||
90 | The AMD5536 UDC is part of the AMD Geode CS5536, an x86 southbridge. | ||
91 | It is a USB Highspeed DMA capable USB device controller. Beside ep0 | ||
92 | it provides 4 IN and 4 OUT endpoints (bulk or interrupt type). | ||
93 | The UDC port supports OTG operation, and may be used as a host port | ||
94 | if it's not being used to implement peripheral or OTG roles. | ||
95 | |||
96 | Say "y" to link the driver statically, or "m" to build a | ||
97 | dynamically linked module called "amd5536udc" and force all | ||
98 | gadget drivers to also be dynamically linked. | ||
99 | |||
100 | config USB_AMD5536UDC | ||
101 | tristate | ||
102 | depends on USB_GADGET_AMD5536UDC | ||
103 | default USB_GADGET | ||
104 | select USB_GADGET_SELECTED | ||
105 | |||
85 | config USB_GADGET_FSL_USB2 | 106 | config USB_GADGET_FSL_USB2 |
86 | boolean "Freescale Highspeed USB DR Peripheral Controller" | 107 | boolean "Freescale Highspeed USB DR Peripheral Controller" |
87 | depends on MPC834x || PPC_MPC831x | 108 | depends on MPC834x || PPC_MPC831x |
@@ -156,6 +177,24 @@ config USB_PXA2XX_SMALL | |||
156 | default y if USB_ETH | 177 | default y if USB_ETH |
157 | default y if USB_G_SERIAL | 178 | default y if USB_G_SERIAL |
158 | 179 | ||
180 | config USB_GADGET_M66592 | ||
181 | boolean "Renesas M66592 USB Peripheral Controller" | ||
182 | select USB_GADGET_DUALSPEED | ||
183 | help | ||
184 | M66592 is a discrete USB peripheral controller chip that | ||
185 | supports both full and high speed USB 2.0 data transfers. | ||
186 | It has seven configurable endpoints, and endpoint zero. | ||
187 | |||
188 | Say "y" to link the driver statically, or "m" to build a | ||
189 | dynamically linked module called "m66592_udc" and force all | ||
190 | gadget drivers to also be dynamically linked. | ||
191 | |||
192 | config USB_M66592 | ||
193 | tristate | ||
194 | depends on USB_GADGET_M66592 | ||
195 | default USB_GADGET | ||
196 | select USB_GADGET_SELECTED | ||
197 | |||
159 | config USB_GADGET_GOKU | 198 | config USB_GADGET_GOKU |
160 | boolean "Toshiba TC86C001 'Goku-S'" | 199 | boolean "Toshiba TC86C001 'Goku-S'" |
161 | depends on PCI | 200 | depends on PCI |
@@ -261,24 +300,6 @@ config USB_AT91 | |||
261 | depends on USB_GADGET_AT91 | 300 | depends on USB_GADGET_AT91 |
262 | default USB_GADGET | 301 | default USB_GADGET |
263 | 302 | ||
264 | config USB_GADGET_M66592 | ||
265 | boolean "M66592 driver" | ||
266 | select USB_GADGET_DUALSPEED | ||
267 | help | ||
268 | M66592 is a USB 2.0 peripheral controller. | ||
269 | |||
270 | It has seven configurable endpoints, and endpoint zero. | ||
271 | |||
272 | Say "y" to link the driver statically, or "m" to build a | ||
273 | dynamically linked module called "m66592_udc" and force all | ||
274 | gadget drivers to also be dynamically linked. | ||
275 | |||
276 | config USB_M66592 | ||
277 | tristate | ||
278 | depends on USB_GADGET_M66592 | ||
279 | default USB_GADGET | ||
280 | select USB_GADGET_SELECTED | ||
281 | |||
282 | config USB_GADGET_DUMMY_HCD | 303 | config USB_GADGET_DUMMY_HCD |
283 | boolean "Dummy HCD (DEVELOPMENT)" | 304 | boolean "Dummy HCD (DEVELOPMENT)" |
284 | depends on (USB=y || (USB=m && USB_GADGET=m)) && EXPERIMENTAL | 305 | depends on (USB=y || (USB=m && USB_GADGET=m)) && EXPERIMENTAL |
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile index 8ae76f738635..1bc0f03550ce 100644 --- a/drivers/usb/gadget/Makefile +++ b/drivers/usb/gadget/Makefile | |||
@@ -7,6 +7,7 @@ endif | |||
7 | 7 | ||
8 | obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o | 8 | obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o |
9 | obj-$(CONFIG_USB_NET2280) += net2280.o | 9 | obj-$(CONFIG_USB_NET2280) += net2280.o |
10 | obj-$(CONFIG_USB_AMD5536UDC) += amd5536udc.o | ||
10 | obj-$(CONFIG_USB_PXA2XX) += pxa2xx_udc.o | 11 | obj-$(CONFIG_USB_PXA2XX) += pxa2xx_udc.o |
11 | obj-$(CONFIG_USB_GOKU) += goku_udc.o | 12 | obj-$(CONFIG_USB_GOKU) += goku_udc.o |
12 | obj-$(CONFIG_USB_OMAP) += omap_udc.o | 13 | obj-$(CONFIG_USB_OMAP) += omap_udc.o |
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c new file mode 100644 index 000000000000..714156ca8fe4 --- /dev/null +++ b/drivers/usb/gadget/amd5536udc.c | |||
@@ -0,0 +1,3454 @@ | |||
1 | /* | ||
2 | * amd5536.c -- AMD 5536 UDC high/full speed USB device controller | ||
3 | * | ||
4 | * Copyright (C) 2005-2007 AMD (http://www.amd.com) | ||
5 | * Author: Thomas Dahlmann | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | ||
21 | |||
22 | /* | ||
23 | * The AMD5536 UDC is part of the x86 southbridge AMD Geode CS5536. | ||
24 | * It is a USB Highspeed DMA capable USB device controller. Beside ep0 it | ||
25 | * provides 4 IN and 4 OUT endpoints (bulk or interrupt type). | ||
26 | * | ||
27 | * Make sure that UDC is assigned to port 4 by BIOS settings (port can also | ||
28 | * be used as host port) and UOC bits PAD_EN and APU are set (should be done | ||
29 | * by BIOS init). | ||
30 | * | ||
31 | * UDC DMA requires 32-bit aligned buffers so DMA with gadget ether does not | ||
32 | * work without updating NET_IP_ALIGN. Or PIO mode (module param "use_dma=0") | ||
33 | * can be used with gadget ether. | ||
34 | */ | ||
35 | |||
36 | /* debug control */ | ||
37 | /* #define UDC_VERBOSE */ | ||
38 | |||
39 | /* Driver strings */ | ||
40 | #define UDC_MOD_DESCRIPTION "AMD 5536 UDC - USB Device Controller" | ||
41 | #define UDC_DRIVER_VERSION_STRING "01.00.0206 - $Revision: #3 $" | ||
42 | |||
43 | /* system */ | ||
44 | #include <linux/module.h> | ||
45 | #include <linux/pci.h> | ||
46 | #include <linux/kernel.h> | ||
47 | #include <linux/version.h> | ||
48 | #include <linux/delay.h> | ||
49 | #include <linux/ioport.h> | ||
50 | #include <linux/sched.h> | ||
51 | #include <linux/slab.h> | ||
52 | #include <linux/smp_lock.h> | ||
53 | #include <linux/errno.h> | ||
54 | #include <linux/init.h> | ||
55 | #include <linux/timer.h> | ||
56 | #include <linux/list.h> | ||
57 | #include <linux/interrupt.h> | ||
58 | #include <linux/ioctl.h> | ||
59 | #include <linux/fs.h> | ||
60 | #include <linux/dmapool.h> | ||
61 | #include <linux/moduleparam.h> | ||
62 | #include <linux/device.h> | ||
63 | #include <linux/io.h> | ||
64 | #include <linux/irq.h> | ||
65 | |||
66 | #include <asm/byteorder.h> | ||
67 | #include <asm/system.h> | ||
68 | #include <asm/unaligned.h> | ||
69 | |||
70 | /* gadget stack */ | ||
71 | #include <linux/usb/ch9.h> | ||
72 | #include <linux/usb_gadget.h> | ||
73 | |||
74 | /* udc specific */ | ||
75 | #include "amd5536udc.h" | ||
76 | |||
77 | |||
78 | static void udc_tasklet_disconnect(unsigned long); | ||
79 | static void empty_req_queue(struct udc_ep *); | ||
80 | static int udc_probe(struct udc *dev); | ||
81 | static void udc_basic_init(struct udc *dev); | ||
82 | static void udc_setup_endpoints(struct udc *dev); | ||
83 | static void udc_soft_reset(struct udc *dev); | ||
84 | static struct udc_request *udc_alloc_bna_dummy(struct udc_ep *ep); | ||
85 | static void udc_free_request(struct usb_ep *usbep, struct usb_request *usbreq); | ||
86 | static int udc_free_dma_chain(struct udc *dev, struct udc_request *req); | ||
87 | static int udc_create_dma_chain(struct udc_ep *ep, struct udc_request *req, | ||
88 | unsigned long buf_len, gfp_t gfp_flags); | ||
89 | static int udc_remote_wakeup(struct udc *dev); | ||
90 | static int udc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id); | ||
91 | static void udc_pci_remove(struct pci_dev *pdev); | ||
92 | |||
93 | /* description */ | ||
94 | static const char mod_desc[] = UDC_MOD_DESCRIPTION; | ||
95 | static const char name[] = "amd5536udc"; | ||
96 | |||
97 | /* structure to hold endpoint function pointers */ | ||
98 | static const struct usb_ep_ops udc_ep_ops; | ||
99 | |||
100 | /* received setup data */ | ||
101 | static union udc_setup_data setup_data; | ||
102 | |||
103 | /* pointer to device object */ | ||
104 | static struct udc *udc; | ||
105 | |||
106 | /* irq spin lock for soft reset */ | ||
107 | static DEFINE_SPINLOCK(udc_irq_spinlock); | ||
108 | /* stall spin lock */ | ||
109 | static DEFINE_SPINLOCK(udc_stall_spinlock); | ||
110 | |||
111 | /* | ||
112 | * slave mode: pending bytes in rx fifo after nyet, | ||
113 | * used if EPIN irq came but no req was available | ||
114 | */ | ||
115 | static unsigned int udc_rxfifo_pending; | ||
116 | |||
117 | /* count soft resets after suspend to avoid loop */ | ||
118 | static int soft_reset_occured; | ||
119 | static int soft_reset_after_usbreset_occured; | ||
120 | |||
121 | /* timer */ | ||
122 | static struct timer_list udc_timer; | ||
123 | static int stop_timer; | ||
124 | |||
125 | /* set_rde -- Is used to control enabling of RX DMA. Problem is | ||
126 | * that UDC has only one bit (RDE) to enable/disable RX DMA for | ||
127 | * all OUT endpoints. So we have to handle race conditions like | ||
128 | * when OUT data reaches the fifo but no request was queued yet. | ||
129 | * This cannot be solved by letting the RX DMA disabled until a | ||
130 | * request gets queued because there may be other OUT packets | ||
131 | * in the FIFO (important for not blocking control traffic). | ||
132 | * The value of set_rde controls the correspondig timer. | ||
133 | * | ||
134 | * set_rde -1 == not used, means it is alloed to be set to 0 or 1 | ||
135 | * set_rde 0 == do not touch RDE, do no start the RDE timer | ||
136 | * set_rde 1 == timer function will look whether FIFO has data | ||
137 | * set_rde 2 == set by timer function to enable RX DMA on next call | ||
138 | */ | ||
139 | static int set_rde = -1; | ||
140 | |||
141 | static DECLARE_COMPLETION(on_exit); | ||
142 | static struct timer_list udc_pollstall_timer; | ||
143 | static int stop_pollstall_timer; | ||
144 | static DECLARE_COMPLETION(on_pollstall_exit); | ||
145 | |||
146 | /* tasklet for usb disconnect */ | ||
147 | static DECLARE_TASKLET(disconnect_tasklet, udc_tasklet_disconnect, | ||
148 | (unsigned long) &udc); | ||
149 | |||
150 | |||
151 | /* endpoint names used for print */ | ||
152 | static const char ep0_string[] = "ep0in"; | ||
153 | static const char *ep_string[] = { | ||
154 | ep0_string, | ||
155 | "ep1in-int", "ep2in-bulk", "ep3in-bulk", "ep4in-bulk", "ep5in-bulk", | ||
156 | "ep6in-bulk", "ep7in-bulk", "ep8in-bulk", "ep9in-bulk", "ep10in-bulk", | ||
157 | "ep11in-bulk", "ep12in-bulk", "ep13in-bulk", "ep14in-bulk", | ||
158 | "ep15in-bulk", "ep0out", "ep1out-bulk", "ep2out-bulk", "ep3out-bulk", | ||
159 | "ep4out-bulk", "ep5out-bulk", "ep6out-bulk", "ep7out-bulk", | ||
160 | "ep8out-bulk", "ep9out-bulk", "ep10out-bulk", "ep11out-bulk", | ||
161 | "ep12out-bulk", "ep13out-bulk", "ep14out-bulk", "ep15out-bulk" | ||
162 | }; | ||
163 | |||
164 | /* DMA usage flag */ | ||
165 | static int use_dma = 1; | ||
166 | /* packet per buffer dma */ | ||
167 | static int use_dma_ppb = 1; | ||
168 | /* with per descr. update */ | ||
169 | static int use_dma_ppb_du; | ||
170 | /* buffer fill mode */ | ||
171 | static int use_dma_bufferfill_mode; | ||
172 | /* full speed only mode */ | ||
173 | static int use_fullspeed; | ||
174 | /* tx buffer size for high speed */ | ||
175 | static unsigned long hs_tx_buf = UDC_EPIN_BUFF_SIZE; | ||
176 | |||
177 | /* module parameters */ | ||
178 | module_param(use_dma, bool, S_IRUGO); | ||
179 | MODULE_PARM_DESC(use_dma, "true for DMA"); | ||
180 | module_param(use_dma_ppb, bool, S_IRUGO); | ||
181 | MODULE_PARM_DESC(use_dma_ppb, "true for DMA in packet per buffer mode"); | ||
182 | module_param(use_dma_ppb_du, bool, S_IRUGO); | ||
183 | MODULE_PARM_DESC(use_dma_ppb_du, | ||
184 | "true for DMA in packet per buffer mode with descriptor update"); | ||
185 | module_param(use_fullspeed, bool, S_IRUGO); | ||
186 | MODULE_PARM_DESC(use_fullspeed, "true for fullspeed only"); | ||
187 | |||
188 | /*---------------------------------------------------------------------------*/ | ||
189 | /* Prints UDC device registers and endpoint irq registers */ | ||
190 | static void print_regs(struct udc *dev) | ||
191 | { | ||
192 | DBG(dev, "------- Device registers -------\n"); | ||
193 | DBG(dev, "dev config = %08x\n", readl(&dev->regs->cfg)); | ||
194 | DBG(dev, "dev control = %08x\n", readl(&dev->regs->ctl)); | ||
195 | DBG(dev, "dev status = %08x\n", readl(&dev->regs->sts)); | ||
196 | DBG(dev, "\n"); | ||
197 | DBG(dev, "dev int's = %08x\n", readl(&dev->regs->irqsts)); | ||
198 | DBG(dev, "dev intmask = %08x\n", readl(&dev->regs->irqmsk)); | ||
199 | DBG(dev, "\n"); | ||
200 | DBG(dev, "dev ep int's = %08x\n", readl(&dev->regs->ep_irqsts)); | ||
201 | DBG(dev, "dev ep intmask = %08x\n", readl(&dev->regs->ep_irqmsk)); | ||
202 | DBG(dev, "\n"); | ||
203 | DBG(dev, "USE DMA = %d\n", use_dma); | ||
204 | if (use_dma && use_dma_ppb && !use_dma_ppb_du) { | ||
205 | DBG(dev, "DMA mode = PPBNDU (packet per buffer " | ||
206 | "WITHOUT desc. update)\n"); | ||
207 | dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "PPBNDU"); | ||
208 | } else if (use_dma && use_dma_ppb_du && use_dma_ppb_du) { | ||
209 | DBG(dev, "DMA mode = PPBDU (packet per buffer " | ||
210 | "WITH desc. update)\n"); | ||
211 | dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "PPBDU"); | ||
212 | } | ||
213 | if (use_dma && use_dma_bufferfill_mode) { | ||
214 | DBG(dev, "DMA mode = BF (buffer fill mode)\n"); | ||
215 | dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "BF"); | ||
216 | } | ||
217 | if (!use_dma) { | ||
218 | dev_info(&dev->pdev->dev, "FIFO mode\n"); | ||
219 | } | ||
220 | DBG(dev, "-------------------------------------------------------\n"); | ||
221 | } | ||
222 | |||
223 | /* Masks unused interrupts */ | ||
224 | static int udc_mask_unused_interrupts(struct udc *dev) | ||
225 | { | ||
226 | u32 tmp; | ||
227 | |||
228 | /* mask all dev interrupts */ | ||
229 | tmp = AMD_BIT(UDC_DEVINT_SVC) | | ||
230 | AMD_BIT(UDC_DEVINT_ENUM) | | ||
231 | AMD_BIT(UDC_DEVINT_US) | | ||
232 | AMD_BIT(UDC_DEVINT_UR) | | ||
233 | AMD_BIT(UDC_DEVINT_ES) | | ||
234 | AMD_BIT(UDC_DEVINT_SI) | | ||
235 | AMD_BIT(UDC_DEVINT_SOF)| | ||
236 | AMD_BIT(UDC_DEVINT_SC); | ||
237 | writel(tmp, &dev->regs->irqmsk); | ||
238 | |||
239 | /* mask all ep interrupts */ | ||
240 | writel(UDC_EPINT_MSK_DISABLE_ALL, &dev->regs->ep_irqmsk); | ||
241 | |||
242 | return 0; | ||
243 | } | ||
244 | |||
245 | /* Enables endpoint 0 interrupts */ | ||
246 | static int udc_enable_ep0_interrupts(struct udc *dev) | ||
247 | { | ||
248 | u32 tmp; | ||
249 | |||
250 | DBG(dev, "udc_enable_ep0_interrupts()\n"); | ||
251 | |||
252 | /* read irq mask */ | ||
253 | tmp = readl(&dev->regs->ep_irqmsk); | ||
254 | /* enable ep0 irq's */ | ||
255 | tmp &= AMD_UNMASK_BIT(UDC_EPINT_IN_EP0) | ||
256 | & AMD_UNMASK_BIT(UDC_EPINT_OUT_EP0); | ||
257 | writel(tmp, &dev->regs->ep_irqmsk); | ||
258 | |||
259 | return 0; | ||
260 | } | ||
261 | |||
262 | /* Enables device interrupts for SET_INTF and SET_CONFIG */ | ||
263 | static int udc_enable_dev_setup_interrupts(struct udc *dev) | ||
264 | { | ||
265 | u32 tmp; | ||
266 | |||
267 | DBG(dev, "enable device interrupts for setup data\n"); | ||
268 | |||
269 | /* read irq mask */ | ||
270 | tmp = readl(&dev->regs->irqmsk); | ||
271 | |||
272 | /* enable SET_INTERFACE, SET_CONFIG and other needed irq's */ | ||
273 | tmp &= AMD_UNMASK_BIT(UDC_DEVINT_SI) | ||
274 | & AMD_UNMASK_BIT(UDC_DEVINT_SC) | ||
275 | & AMD_UNMASK_BIT(UDC_DEVINT_UR) | ||
276 | & AMD_UNMASK_BIT(UDC_DEVINT_SVC) | ||
277 | & AMD_UNMASK_BIT(UDC_DEVINT_ENUM); | ||
278 | writel(tmp, &dev->regs->irqmsk); | ||
279 | |||
280 | return 0; | ||
281 | } | ||
282 | |||
283 | /* Calculates fifo start of endpoint based on preceeding endpoints */ | ||
284 | static int udc_set_txfifo_addr(struct udc_ep *ep) | ||
285 | { | ||
286 | struct udc *dev; | ||
287 | u32 tmp; | ||
288 | int i; | ||
289 | |||
290 | if (!ep || !(ep->in)) | ||
291 | return -EINVAL; | ||
292 | |||
293 | dev = ep->dev; | ||
294 | ep->txfifo = dev->txfifo; | ||
295 | |||
296 | /* traverse ep's */ | ||
297 | for (i = 0; i < ep->num; i++) { | ||
298 | if (dev->ep[i].regs) { | ||
299 | /* read fifo size */ | ||
300 | tmp = readl(&dev->ep[i].regs->bufin_framenum); | ||
301 | tmp = AMD_GETBITS(tmp, UDC_EPIN_BUFF_SIZE); | ||
302 | ep->txfifo += tmp; | ||
303 | } | ||
304 | } | ||
305 | return 0; | ||
306 | } | ||
307 | |||
308 | /* CNAK pending field: bit0 = ep0in, bit16 = ep0out */ | ||
309 | static u32 cnak_pending; | ||
310 | |||
311 | static void UDC_QUEUE_CNAK(struct udc_ep *ep, unsigned num) | ||
312 | { | ||
313 | if (readl(&ep->regs->ctl) & AMD_BIT(UDC_EPCTL_NAK)) { | ||
314 | DBG(ep->dev, "NAK could not be cleared for ep%d\n", num); | ||
315 | cnak_pending |= 1 << (num); | ||
316 | ep->naking = 1; | ||
317 | } else | ||
318 | cnak_pending = cnak_pending & (~(1 << (num))); | ||
319 | } | ||
320 | |||
321 | |||
322 | /* Enables endpoint, is called by gadget driver */ | ||
323 | static int | ||
324 | udc_ep_enable(struct usb_ep *usbep, const struct usb_endpoint_descriptor *desc) | ||
325 | { | ||
326 | struct udc_ep *ep; | ||
327 | struct udc *dev; | ||
328 | u32 tmp; | ||
329 | unsigned long iflags; | ||
330 | u8 udc_csr_epix; | ||
331 | |||
332 | if (!usbep | ||
333 | || usbep->name == ep0_string | ||
334 | || !desc | ||
335 | || desc->bDescriptorType != USB_DT_ENDPOINT) | ||
336 | return -EINVAL; | ||
337 | |||
338 | ep = container_of(usbep, struct udc_ep, ep); | ||
339 | dev = ep->dev; | ||
340 | |||
341 | DBG(dev, "udc_ep_enable() ep %d\n", ep->num); | ||
342 | |||
343 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
344 | return -ESHUTDOWN; | ||
345 | |||
346 | spin_lock_irqsave(&dev->lock, iflags); | ||
347 | ep->desc = desc; | ||
348 | |||
349 | ep->halted = 0; | ||
350 | |||
351 | /* set traffic type */ | ||
352 | tmp = readl(&dev->ep[ep->num].regs->ctl); | ||
353 | tmp = AMD_ADDBITS(tmp, desc->bmAttributes, UDC_EPCTL_ET); | ||
354 | writel(tmp, &dev->ep[ep->num].regs->ctl); | ||
355 | |||
356 | /* set max packet size */ | ||
357 | tmp = readl(&dev->ep[ep->num].regs->bufout_maxpkt); | ||
358 | tmp = AMD_ADDBITS(tmp, desc->wMaxPacketSize, UDC_EP_MAX_PKT_SIZE); | ||
359 | ep->ep.maxpacket = desc->wMaxPacketSize; | ||
360 | writel(tmp, &dev->ep[ep->num].regs->bufout_maxpkt); | ||
361 | |||
362 | /* IN ep */ | ||
363 | if (ep->in) { | ||
364 | |||
365 | /* ep ix in UDC CSR register space */ | ||
366 | udc_csr_epix = ep->num; | ||
367 | |||
368 | /* set buffer size (tx fifo entries) */ | ||
369 | tmp = readl(&dev->ep[ep->num].regs->bufin_framenum); | ||
370 | /* double buffering: fifo size = 2 x max packet size */ | ||
371 | tmp = AMD_ADDBITS( | ||
372 | tmp, | ||
373 | desc->wMaxPacketSize * UDC_EPIN_BUFF_SIZE_MULT | ||
374 | / UDC_DWORD_BYTES, | ||
375 | UDC_EPIN_BUFF_SIZE); | ||
376 | writel(tmp, &dev->ep[ep->num].regs->bufin_framenum); | ||
377 | |||
378 | /* calc. tx fifo base addr */ | ||
379 | udc_set_txfifo_addr(ep); | ||
380 | |||
381 | /* flush fifo */ | ||
382 | tmp = readl(&ep->regs->ctl); | ||
383 | tmp |= AMD_BIT(UDC_EPCTL_F); | ||
384 | writel(tmp, &ep->regs->ctl); | ||
385 | |||
386 | /* OUT ep */ | ||
387 | } else { | ||
388 | /* ep ix in UDC CSR register space */ | ||
389 | udc_csr_epix = ep->num - UDC_CSR_EP_OUT_IX_OFS; | ||
390 | |||
391 | /* set max packet size UDC CSR */ | ||
392 | tmp = readl(&dev->csr->ne[ep->num - UDC_CSR_EP_OUT_IX_OFS]); | ||
393 | tmp = AMD_ADDBITS(tmp, desc->wMaxPacketSize, | ||
394 | UDC_CSR_NE_MAX_PKT); | ||
395 | writel(tmp, &dev->csr->ne[ep->num - UDC_CSR_EP_OUT_IX_OFS]); | ||
396 | |||
397 | if (use_dma && !ep->in) { | ||
398 | /* alloc and init BNA dummy request */ | ||
399 | ep->bna_dummy_req = udc_alloc_bna_dummy(ep); | ||
400 | ep->bna_occurred = 0; | ||
401 | } | ||
402 | |||
403 | if (ep->num != UDC_EP0OUT_IX) | ||
404 | dev->data_ep_enabled = 1; | ||
405 | } | ||
406 | |||
407 | /* set ep values */ | ||
408 | tmp = readl(&dev->csr->ne[udc_csr_epix]); | ||
409 | /* max packet */ | ||
410 | tmp = AMD_ADDBITS(tmp, desc->wMaxPacketSize, UDC_CSR_NE_MAX_PKT); | ||
411 | /* ep number */ | ||
412 | tmp = AMD_ADDBITS(tmp, desc->bEndpointAddress, UDC_CSR_NE_NUM); | ||
413 | /* ep direction */ | ||
414 | tmp = AMD_ADDBITS(tmp, ep->in, UDC_CSR_NE_DIR); | ||
415 | /* ep type */ | ||
416 | tmp = AMD_ADDBITS(tmp, desc->bmAttributes, UDC_CSR_NE_TYPE); | ||
417 | /* ep config */ | ||
418 | tmp = AMD_ADDBITS(tmp, ep->dev->cur_config, UDC_CSR_NE_CFG); | ||
419 | /* ep interface */ | ||
420 | tmp = AMD_ADDBITS(tmp, ep->dev->cur_intf, UDC_CSR_NE_INTF); | ||
421 | /* ep alt */ | ||
422 | tmp = AMD_ADDBITS(tmp, ep->dev->cur_alt, UDC_CSR_NE_ALT); | ||
423 | /* write reg */ | ||
424 | writel(tmp, &dev->csr->ne[udc_csr_epix]); | ||
425 | |||
426 | /* enable ep irq */ | ||
427 | tmp = readl(&dev->regs->ep_irqmsk); | ||
428 | tmp &= AMD_UNMASK_BIT(ep->num); | ||
429 | writel(tmp, &dev->regs->ep_irqmsk); | ||
430 | |||
431 | /* | ||
432 | * clear NAK by writing CNAK | ||
433 | * avoid BNA for OUT DMA, don't clear NAK until DMA desc. written | ||
434 | */ | ||
435 | if (!use_dma || ep->in) { | ||
436 | tmp = readl(&ep->regs->ctl); | ||
437 | tmp |= AMD_BIT(UDC_EPCTL_CNAK); | ||
438 | writel(tmp, &ep->regs->ctl); | ||
439 | ep->naking = 0; | ||
440 | UDC_QUEUE_CNAK(ep, ep->num); | ||
441 | } | ||
442 | tmp = desc->bEndpointAddress; | ||
443 | DBG(dev, "%s enabled\n", usbep->name); | ||
444 | |||
445 | spin_unlock_irqrestore(&dev->lock, iflags); | ||
446 | return 0; | ||
447 | } | ||
448 | |||
449 | /* Resets endpoint */ | ||
450 | static void ep_init(struct udc_regs __iomem *regs, struct udc_ep *ep) | ||
451 | { | ||
452 | u32 tmp; | ||
453 | |||
454 | VDBG(ep->dev, "ep-%d reset\n", ep->num); | ||
455 | ep->desc = NULL; | ||
456 | ep->ep.ops = &udc_ep_ops; | ||
457 | INIT_LIST_HEAD(&ep->queue); | ||
458 | |||
459 | ep->ep.maxpacket = (u16) ~0; | ||
460 | /* set NAK */ | ||
461 | tmp = readl(&ep->regs->ctl); | ||
462 | tmp |= AMD_BIT(UDC_EPCTL_SNAK); | ||
463 | writel(tmp, &ep->regs->ctl); | ||
464 | ep->naking = 1; | ||
465 | |||
466 | /* disable interrupt */ | ||
467 | tmp = readl(®s->ep_irqmsk); | ||
468 | tmp |= AMD_BIT(ep->num); | ||
469 | writel(tmp, ®s->ep_irqmsk); | ||
470 | |||
471 | if (ep->in) { | ||
472 | /* unset P and IN bit of potential former DMA */ | ||
473 | tmp = readl(&ep->regs->ctl); | ||
474 | tmp &= AMD_UNMASK_BIT(UDC_EPCTL_P); | ||
475 | writel(tmp, &ep->regs->ctl); | ||
476 | |||
477 | tmp = readl(&ep->regs->sts); | ||
478 | tmp |= AMD_BIT(UDC_EPSTS_IN); | ||
479 | writel(tmp, &ep->regs->sts); | ||
480 | |||
481 | /* flush the fifo */ | ||
482 | tmp = readl(&ep->regs->ctl); | ||
483 | tmp |= AMD_BIT(UDC_EPCTL_F); | ||
484 | writel(tmp, &ep->regs->ctl); | ||
485 | |||
486 | } | ||
487 | /* reset desc pointer */ | ||
488 | writel(0, &ep->regs->desptr); | ||
489 | } | ||
490 | |||
491 | /* Disables endpoint, is called by gadget driver */ | ||
492 | static int udc_ep_disable(struct usb_ep *usbep) | ||
493 | { | ||
494 | struct udc_ep *ep = NULL; | ||
495 | unsigned long iflags; | ||
496 | |||
497 | if (!usbep) | ||
498 | return -EINVAL; | ||
499 | |||
500 | ep = container_of(usbep, struct udc_ep, ep); | ||
501 | if (usbep->name == ep0_string || !ep->desc) | ||
502 | return -EINVAL; | ||
503 | |||
504 | DBG(ep->dev, "Disable ep-%d\n", ep->num); | ||
505 | |||
506 | spin_lock_irqsave(&ep->dev->lock, iflags); | ||
507 | udc_free_request(&ep->ep, &ep->bna_dummy_req->req); | ||
508 | empty_req_queue(ep); | ||
509 | ep_init(ep->dev->regs, ep); | ||
510 | spin_unlock_irqrestore(&ep->dev->lock, iflags); | ||
511 | |||
512 | return 0; | ||
513 | } | ||
514 | |||
515 | /* Allocates request packet, called by gadget driver */ | ||
516 | static struct usb_request * | ||
517 | udc_alloc_request(struct usb_ep *usbep, gfp_t gfp) | ||
518 | { | ||
519 | struct udc_request *req; | ||
520 | struct udc_data_dma *dma_desc; | ||
521 | struct udc_ep *ep; | ||
522 | |||
523 | if (!usbep) | ||
524 | return NULL; | ||
525 | |||
526 | ep = container_of(usbep, struct udc_ep, ep); | ||
527 | |||
528 | VDBG(ep->dev, "udc_alloc_req(): ep%d\n", ep->num); | ||
529 | req = kzalloc(sizeof(struct udc_request), gfp); | ||
530 | if (!req) | ||
531 | return NULL; | ||
532 | |||
533 | req->req.dma = DMA_DONT_USE; | ||
534 | INIT_LIST_HEAD(&req->queue); | ||
535 | |||
536 | if (ep->dma) { | ||
537 | /* ep0 in requests are allocated from data pool here */ | ||
538 | dma_desc = pci_pool_alloc(ep->dev->data_requests, gfp, | ||
539 | &req->td_phys); | ||
540 | if (!dma_desc) { | ||
541 | kfree(req); | ||
542 | return NULL; | ||
543 | } | ||
544 | |||
545 | VDBG(ep->dev, "udc_alloc_req: req = %p dma_desc = %p, " | ||
546 | "td_phys = %lx\n", | ||
547 | req, dma_desc, | ||
548 | (unsigned long)req->td_phys); | ||
549 | /* prevent from using desc. - set HOST BUSY */ | ||
550 | dma_desc->status = AMD_ADDBITS(dma_desc->status, | ||
551 | UDC_DMA_STP_STS_BS_HOST_BUSY, | ||
552 | UDC_DMA_STP_STS_BS); | ||
553 | dma_desc->bufptr = __constant_cpu_to_le32(DMA_DONT_USE); | ||
554 | req->td_data = dma_desc; | ||
555 | req->td_data_last = NULL; | ||
556 | req->chain_len = 1; | ||
557 | } | ||
558 | |||
559 | return &req->req; | ||
560 | } | ||
561 | |||
562 | /* Frees request packet, called by gadget driver */ | ||
563 | static void | ||
564 | udc_free_request(struct usb_ep *usbep, struct usb_request *usbreq) | ||
565 | { | ||
566 | struct udc_ep *ep; | ||
567 | struct udc_request *req; | ||
568 | |||
569 | if (!usbep || !usbreq) | ||
570 | return; | ||
571 | |||
572 | ep = container_of(usbep, struct udc_ep, ep); | ||
573 | req = container_of(usbreq, struct udc_request, req); | ||
574 | VDBG(ep->dev, "free_req req=%p\n", req); | ||
575 | BUG_ON(!list_empty(&req->queue)); | ||
576 | if (req->td_data) { | ||
577 | VDBG(ep->dev, "req->td_data=%p\n", req->td_data); | ||
578 | |||
579 | /* free dma chain if created */ | ||
580 | if (req->chain_len > 1) { | ||
581 | udc_free_dma_chain(ep->dev, req); | ||
582 | } | ||
583 | |||
584 | pci_pool_free(ep->dev->data_requests, req->td_data, | ||
585 | req->td_phys); | ||
586 | } | ||
587 | kfree(req); | ||
588 | } | ||
589 | |||
590 | /* Init BNA dummy descriptor for HOST BUSY and pointing to itself */ | ||
591 | static void udc_init_bna_dummy(struct udc_request *req) | ||
592 | { | ||
593 | if (req) { | ||
594 | /* set last bit */ | ||
595 | req->td_data->status |= AMD_BIT(UDC_DMA_IN_STS_L); | ||
596 | /* set next pointer to itself */ | ||
597 | req->td_data->next = req->td_phys; | ||
598 | /* set HOST BUSY */ | ||
599 | req->td_data->status | ||
600 | = AMD_ADDBITS(req->td_data->status, | ||
601 | UDC_DMA_STP_STS_BS_DMA_DONE, | ||
602 | UDC_DMA_STP_STS_BS); | ||
603 | #ifdef UDC_VERBOSE | ||
604 | pr_debug("bna desc = %p, sts = %08x\n", | ||
605 | req->td_data, req->td_data->status); | ||
606 | #endif | ||
607 | } | ||
608 | } | ||
609 | |||
610 | /* Allocate BNA dummy descriptor */ | ||
611 | static struct udc_request *udc_alloc_bna_dummy(struct udc_ep *ep) | ||
612 | { | ||
613 | struct udc_request *req = NULL; | ||
614 | struct usb_request *_req = NULL; | ||
615 | |||
616 | /* alloc the dummy request */ | ||
617 | _req = udc_alloc_request(&ep->ep, GFP_ATOMIC); | ||
618 | if (_req) { | ||
619 | req = container_of(_req, struct udc_request, req); | ||
620 | ep->bna_dummy_req = req; | ||
621 | udc_init_bna_dummy(req); | ||
622 | } | ||
623 | return req; | ||
624 | } | ||
625 | |||
626 | /* Write data to TX fifo for IN packets */ | ||
627 | static void | ||
628 | udc_txfifo_write(struct udc_ep *ep, struct usb_request *req) | ||
629 | { | ||
630 | u8 *req_buf; | ||
631 | u32 *buf; | ||
632 | int i, j; | ||
633 | unsigned bytes = 0; | ||
634 | unsigned remaining = 0; | ||
635 | |||
636 | if (!req || !ep) | ||
637 | return; | ||
638 | |||
639 | req_buf = req->buf + req->actual; | ||
640 | prefetch(req_buf); | ||
641 | remaining = req->length - req->actual; | ||
642 | |||
643 | buf = (u32 *) req_buf; | ||
644 | |||
645 | bytes = ep->ep.maxpacket; | ||
646 | if (bytes > remaining) | ||
647 | bytes = remaining; | ||
648 | |||
649 | /* dwords first */ | ||
650 | for (i = 0; i < bytes / UDC_DWORD_BYTES; i++) { | ||
651 | writel(*(buf + i), ep->txfifo); | ||
652 | } | ||
653 | |||
654 | /* remaining bytes must be written by byte access */ | ||
655 | for (j = 0; j < bytes % UDC_DWORD_BYTES; j++) { | ||
656 | writeb((u8)(*(buf + i) >> (j << UDC_BITS_PER_BYTE_SHIFT)), | ||
657 | ep->txfifo); | ||
658 | } | ||
659 | |||
660 | /* dummy write confirm */ | ||
661 | writel(0, &ep->regs->confirm); | ||
662 | } | ||
663 | |||
664 | /* Read dwords from RX fifo for OUT transfers */ | ||
665 | static int udc_rxfifo_read_dwords(struct udc *dev, u32 *buf, int dwords) | ||
666 | { | ||
667 | int i; | ||
668 | |||
669 | VDBG(dev, "udc_read_dwords(): %d dwords\n", dwords); | ||
670 | |||
671 | for (i = 0; i < dwords; i++) { | ||
672 | *(buf + i) = readl(dev->rxfifo); | ||
673 | } | ||
674 | return 0; | ||
675 | } | ||
676 | |||
677 | /* Read bytes from RX fifo for OUT transfers */ | ||
678 | static int udc_rxfifo_read_bytes(struct udc *dev, u8 *buf, int bytes) | ||
679 | { | ||
680 | int i, j; | ||
681 | u32 tmp; | ||
682 | |||
683 | VDBG(dev, "udc_read_bytes(): %d bytes\n", bytes); | ||
684 | |||
685 | /* dwords first */ | ||
686 | for (i = 0; i < bytes / UDC_DWORD_BYTES; i++) { | ||
687 | *((u32 *)(buf + (i<<2))) = readl(dev->rxfifo); | ||
688 | } | ||
689 | |||
690 | /* remaining bytes must be read by byte access */ | ||
691 | if (bytes % UDC_DWORD_BYTES) { | ||
692 | tmp = readl(dev->rxfifo); | ||
693 | for (j = 0; j < bytes % UDC_DWORD_BYTES; j++) { | ||
694 | *(buf + (i<<2) + j) = (u8)(tmp & UDC_BYTE_MASK); | ||
695 | tmp = tmp >> UDC_BITS_PER_BYTE; | ||
696 | } | ||
697 | } | ||
698 | |||
699 | return 0; | ||
700 | } | ||
701 | |||
702 | /* Read data from RX fifo for OUT transfers */ | ||
703 | static int | ||
704 | udc_rxfifo_read(struct udc_ep *ep, struct udc_request *req) | ||
705 | { | ||
706 | u8 *buf; | ||
707 | unsigned buf_space; | ||
708 | unsigned bytes = 0; | ||
709 | unsigned finished = 0; | ||
710 | |||
711 | /* received number bytes */ | ||
712 | bytes = readl(&ep->regs->sts); | ||
713 | bytes = AMD_GETBITS(bytes, UDC_EPSTS_RX_PKT_SIZE); | ||
714 | |||
715 | buf_space = req->req.length - req->req.actual; | ||
716 | buf = req->req.buf + req->req.actual; | ||
717 | if (bytes > buf_space) { | ||
718 | if ((buf_space % ep->ep.maxpacket) != 0) { | ||
719 | DBG(ep->dev, | ||
720 | "%s: rx %d bytes, rx-buf space = %d bytesn\n", | ||
721 | ep->ep.name, bytes, buf_space); | ||
722 | req->req.status = -EOVERFLOW; | ||
723 | } | ||
724 | bytes = buf_space; | ||
725 | } | ||
726 | req->req.actual += bytes; | ||
727 | |||
728 | /* last packet ? */ | ||
729 | if (((bytes % ep->ep.maxpacket) != 0) || (!bytes) | ||
730 | || ((req->req.actual == req->req.length) && !req->req.zero)) | ||
731 | finished = 1; | ||
732 | |||
733 | /* read rx fifo bytes */ | ||
734 | VDBG(ep->dev, "ep %s: rxfifo read %d bytes\n", ep->ep.name, bytes); | ||
735 | udc_rxfifo_read_bytes(ep->dev, buf, bytes); | ||
736 | |||
737 | return finished; | ||
738 | } | ||
739 | |||
740 | /* create/re-init a DMA descriptor or a DMA descriptor chain */ | ||
741 | static int prep_dma(struct udc_ep *ep, struct udc_request *req, gfp_t gfp) | ||
742 | { | ||
743 | int retval = 0; | ||
744 | u32 tmp; | ||
745 | |||
746 | VDBG(ep->dev, "prep_dma\n"); | ||
747 | VDBG(ep->dev, "prep_dma ep%d req->td_data=%p\n", | ||
748 | ep->num, req->td_data); | ||
749 | |||
750 | /* set buffer pointer */ | ||
751 | req->td_data->bufptr = req->req.dma; | ||
752 | |||
753 | /* set last bit */ | ||
754 | req->td_data->status |= AMD_BIT(UDC_DMA_IN_STS_L); | ||
755 | |||
756 | /* build/re-init dma chain if maxpkt scatter mode, not for EP0 */ | ||
757 | if (use_dma_ppb) { | ||
758 | |||
759 | retval = udc_create_dma_chain(ep, req, ep->ep.maxpacket, gfp); | ||
760 | if (retval != 0) { | ||
761 | if (retval == -ENOMEM) | ||
762 | DBG(ep->dev, "Out of DMA memory\n"); | ||
763 | return retval; | ||
764 | } | ||
765 | if (ep->in) { | ||
766 | if (req->req.length == ep->ep.maxpacket) { | ||
767 | /* write tx bytes */ | ||
768 | req->td_data->status = | ||
769 | AMD_ADDBITS(req->td_data->status, | ||
770 | ep->ep.maxpacket, | ||
771 | UDC_DMA_IN_STS_TXBYTES); | ||
772 | |||
773 | } | ||
774 | } | ||
775 | |||
776 | } | ||
777 | |||
778 | if (ep->in) { | ||
779 | VDBG(ep->dev, "IN: use_dma_ppb=%d req->req.len=%d " | ||
780 | "maxpacket=%d ep%d\n", | ||
781 | use_dma_ppb, req->req.length, | ||
782 | ep->ep.maxpacket, ep->num); | ||
783 | /* | ||
784 | * if bytes < max packet then tx bytes must | ||
785 | * be written in packet per buffer mode | ||
786 | */ | ||
787 | if (!use_dma_ppb || req->req.length < ep->ep.maxpacket | ||
788 | || ep->num == UDC_EP0OUT_IX | ||
789 | || ep->num == UDC_EP0IN_IX) { | ||
790 | /* write tx bytes */ | ||
791 | req->td_data->status = | ||
792 | AMD_ADDBITS(req->td_data->status, | ||
793 | req->req.length, | ||
794 | UDC_DMA_IN_STS_TXBYTES); | ||
795 | /* reset frame num */ | ||
796 | req->td_data->status = | ||
797 | AMD_ADDBITS(req->td_data->status, | ||
798 | 0, | ||
799 | UDC_DMA_IN_STS_FRAMENUM); | ||
800 | } | ||
801 | /* set HOST BUSY */ | ||
802 | req->td_data->status = | ||
803 | AMD_ADDBITS(req->td_data->status, | ||
804 | UDC_DMA_STP_STS_BS_HOST_BUSY, | ||
805 | UDC_DMA_STP_STS_BS); | ||
806 | } else { | ||
807 | VDBG(ep->dev, "OUT set host ready\n"); | ||
808 | /* set HOST READY */ | ||
809 | req->td_data->status = | ||
810 | AMD_ADDBITS(req->td_data->status, | ||
811 | UDC_DMA_STP_STS_BS_HOST_READY, | ||
812 | UDC_DMA_STP_STS_BS); | ||
813 | |||
814 | |||
815 | /* clear NAK by writing CNAK */ | ||
816 | if (ep->naking) { | ||
817 | tmp = readl(&ep->regs->ctl); | ||
818 | tmp |= AMD_BIT(UDC_EPCTL_CNAK); | ||
819 | writel(tmp, &ep->regs->ctl); | ||
820 | ep->naking = 0; | ||
821 | UDC_QUEUE_CNAK(ep, ep->num); | ||
822 | } | ||
823 | |||
824 | } | ||
825 | |||
826 | return retval; | ||
827 | } | ||
828 | |||
829 | /* Completes request packet ... caller MUST hold lock */ | ||
830 | static void | ||
831 | complete_req(struct udc_ep *ep, struct udc_request *req, int sts) | ||
832 | __releases(ep->dev->lock) | ||
833 | __acquires(ep->dev->lock) | ||
834 | { | ||
835 | struct udc *dev; | ||
836 | unsigned halted; | ||
837 | |||
838 | VDBG(ep->dev, "complete_req(): ep%d\n", ep->num); | ||
839 | |||
840 | dev = ep->dev; | ||
841 | /* unmap DMA */ | ||
842 | if (req->dma_mapping) { | ||
843 | if (ep->in) | ||
844 | pci_unmap_single(dev->pdev, | ||
845 | req->req.dma, | ||
846 | req->req.length, | ||
847 | PCI_DMA_TODEVICE); | ||
848 | else | ||
849 | pci_unmap_single(dev->pdev, | ||
850 | req->req.dma, | ||
851 | req->req.length, | ||
852 | PCI_DMA_FROMDEVICE); | ||
853 | req->dma_mapping = 0; | ||
854 | req->req.dma = DMA_DONT_USE; | ||
855 | } | ||
856 | |||
857 | halted = ep->halted; | ||
858 | ep->halted = 1; | ||
859 | |||
860 | /* set new status if pending */ | ||
861 | if (req->req.status == -EINPROGRESS) | ||
862 | req->req.status = sts; | ||
863 | |||
864 | /* remove from ep queue */ | ||
865 | list_del_init(&req->queue); | ||
866 | |||
867 | VDBG(ep->dev, "req %p => complete %d bytes at %s with sts %d\n", | ||
868 | &req->req, req->req.length, ep->ep.name, sts); | ||
869 | |||
870 | spin_unlock(&dev->lock); | ||
871 | req->req.complete(&ep->ep, &req->req); | ||
872 | spin_lock(&dev->lock); | ||
873 | ep->halted = halted; | ||
874 | } | ||
875 | |||
876 | /* frees pci pool descriptors of a DMA chain */ | ||
877 | static int udc_free_dma_chain(struct udc *dev, struct udc_request *req) | ||
878 | { | ||
879 | |||
880 | int ret_val = 0; | ||
881 | struct udc_data_dma *td; | ||
882 | struct udc_data_dma *td_last = NULL; | ||
883 | unsigned int i; | ||
884 | |||
885 | DBG(dev, "free chain req = %p\n", req); | ||
886 | |||
887 | /* do not free first desc., will be done by free for request */ | ||
888 | td_last = req->td_data; | ||
889 | td = phys_to_virt(td_last->next); | ||
890 | |||
891 | for (i = 1; i < req->chain_len; i++) { | ||
892 | |||
893 | pci_pool_free(dev->data_requests, td, | ||
894 | (dma_addr_t) td_last->next); | ||
895 | td_last = td; | ||
896 | td = phys_to_virt(td_last->next); | ||
897 | } | ||
898 | |||
899 | return ret_val; | ||
900 | } | ||
901 | |||
902 | /* Iterates to the end of a DMA chain and returns last descriptor */ | ||
903 | static struct udc_data_dma *udc_get_last_dma_desc(struct udc_request *req) | ||
904 | { | ||
905 | struct udc_data_dma *td; | ||
906 | |||
907 | td = req->td_data; | ||
908 | while (td && !(td->status & AMD_BIT(UDC_DMA_IN_STS_L))) { | ||
909 | td = phys_to_virt(td->next); | ||
910 | } | ||
911 | |||
912 | return td; | ||
913 | |||
914 | } | ||
915 | |||
916 | /* Iterates to the end of a DMA chain and counts bytes received */ | ||
917 | static u32 udc_get_ppbdu_rxbytes(struct udc_request *req) | ||
918 | { | ||
919 | struct udc_data_dma *td; | ||
920 | u32 count; | ||
921 | |||
922 | td = req->td_data; | ||
923 | /* received number bytes */ | ||
924 | count = AMD_GETBITS(td->status, UDC_DMA_OUT_STS_RXBYTES); | ||
925 | |||
926 | while (td && !(td->status & AMD_BIT(UDC_DMA_IN_STS_L))) { | ||
927 | td = phys_to_virt(td->next); | ||
928 | /* received number bytes */ | ||
929 | if (td) { | ||
930 | count += AMD_GETBITS(td->status, | ||
931 | UDC_DMA_OUT_STS_RXBYTES); | ||
932 | } | ||
933 | } | ||
934 | |||
935 | return count; | ||
936 | |||
937 | } | ||
938 | |||
939 | /* Creates or re-inits a DMA chain */ | ||
940 | static int udc_create_dma_chain( | ||
941 | struct udc_ep *ep, | ||
942 | struct udc_request *req, | ||
943 | unsigned long buf_len, gfp_t gfp_flags | ||
944 | ) | ||
945 | { | ||
946 | unsigned long bytes = req->req.length; | ||
947 | unsigned int i; | ||
948 | dma_addr_t dma_addr; | ||
949 | struct udc_data_dma *td = NULL; | ||
950 | struct udc_data_dma *last = NULL; | ||
951 | unsigned long txbytes; | ||
952 | unsigned create_new_chain = 0; | ||
953 | unsigned len; | ||
954 | |||
955 | VDBG(ep->dev, "udc_create_dma_chain: bytes=%ld buf_len=%ld\n", | ||
956 | bytes, buf_len); | ||
957 | dma_addr = DMA_DONT_USE; | ||
958 | |||
959 | /* unset L bit in first desc for OUT */ | ||
960 | if (!ep->in) { | ||
961 | req->td_data->status &= AMD_CLEAR_BIT(UDC_DMA_IN_STS_L); | ||
962 | } | ||
963 | |||
964 | /* alloc only new desc's if not already available */ | ||
965 | len = req->req.length / ep->ep.maxpacket; | ||
966 | if (req->req.length % ep->ep.maxpacket) { | ||
967 | len++; | ||
968 | } | ||
969 | |||
970 | if (len > req->chain_len) { | ||
971 | /* shorter chain already allocated before */ | ||
972 | if (req->chain_len > 1) { | ||
973 | udc_free_dma_chain(ep->dev, req); | ||
974 | } | ||
975 | req->chain_len = len; | ||
976 | create_new_chain = 1; | ||
977 | } | ||
978 | |||
979 | td = req->td_data; | ||
980 | /* gen. required number of descriptors and buffers */ | ||
981 | for (i = buf_len; i < bytes; i += buf_len) { | ||
982 | /* create or determine next desc. */ | ||
983 | if (create_new_chain) { | ||
984 | |||
985 | td = pci_pool_alloc(ep->dev->data_requests, | ||
986 | gfp_flags, &dma_addr); | ||
987 | if (!td) | ||
988 | return -ENOMEM; | ||
989 | |||
990 | td->status = 0; | ||
991 | } else if (i == buf_len) { | ||
992 | /* first td */ | ||
993 | td = (struct udc_data_dma *) phys_to_virt( | ||
994 | req->td_data->next); | ||
995 | td->status = 0; | ||
996 | } else { | ||
997 | td = (struct udc_data_dma *) phys_to_virt(last->next); | ||
998 | td->status = 0; | ||
999 | } | ||
1000 | |||
1001 | |||
1002 | if (td) | ||
1003 | td->bufptr = req->req.dma + i; /* assign buffer */ | ||
1004 | else | ||
1005 | break; | ||
1006 | |||
1007 | /* short packet ? */ | ||
1008 | if ((bytes - i) >= buf_len) { | ||
1009 | txbytes = buf_len; | ||
1010 | } else { | ||
1011 | /* short packet */ | ||
1012 | txbytes = bytes - i; | ||
1013 | } | ||
1014 | |||
1015 | /* link td and assign tx bytes */ | ||
1016 | if (i == buf_len) { | ||
1017 | if (create_new_chain) { | ||
1018 | req->td_data->next = dma_addr; | ||
1019 | } else { | ||
1020 | /* req->td_data->next = virt_to_phys(td); */ | ||
1021 | } | ||
1022 | /* write tx bytes */ | ||
1023 | if (ep->in) { | ||
1024 | /* first desc */ | ||
1025 | req->td_data->status = | ||
1026 | AMD_ADDBITS(req->td_data->status, | ||
1027 | ep->ep.maxpacket, | ||
1028 | UDC_DMA_IN_STS_TXBYTES); | ||
1029 | /* second desc */ | ||
1030 | td->status = AMD_ADDBITS(td->status, | ||
1031 | txbytes, | ||
1032 | UDC_DMA_IN_STS_TXBYTES); | ||
1033 | } | ||
1034 | } else { | ||
1035 | if (create_new_chain) { | ||
1036 | last->next = dma_addr; | ||
1037 | } else { | ||
1038 | /* last->next = virt_to_phys(td); */ | ||
1039 | } | ||
1040 | if (ep->in) { | ||
1041 | /* write tx bytes */ | ||
1042 | td->status = AMD_ADDBITS(td->status, | ||
1043 | txbytes, | ||
1044 | UDC_DMA_IN_STS_TXBYTES); | ||
1045 | } | ||
1046 | } | ||
1047 | last = td; | ||
1048 | } | ||
1049 | /* set last bit */ | ||
1050 | if (td) { | ||
1051 | td->status |= AMD_BIT(UDC_DMA_IN_STS_L); | ||
1052 | /* last desc. points to itself */ | ||
1053 | req->td_data_last = td; | ||
1054 | } | ||
1055 | |||
1056 | return 0; | ||
1057 | } | ||
1058 | |||
1059 | /* Enabling RX DMA */ | ||
1060 | static void udc_set_rde(struct udc *dev) | ||
1061 | { | ||
1062 | u32 tmp; | ||
1063 | |||
1064 | VDBG(dev, "udc_set_rde()\n"); | ||
1065 | /* stop RDE timer */ | ||
1066 | if (timer_pending(&udc_timer)) { | ||
1067 | set_rde = 0; | ||
1068 | mod_timer(&udc_timer, jiffies - 1); | ||
1069 | } | ||
1070 | /* set RDE */ | ||
1071 | tmp = readl(&dev->regs->ctl); | ||
1072 | tmp |= AMD_BIT(UDC_DEVCTL_RDE); | ||
1073 | writel(tmp, &dev->regs->ctl); | ||
1074 | } | ||
1075 | |||
1076 | /* Queues a request packet, called by gadget driver */ | ||
1077 | static int | ||
1078 | udc_queue(struct usb_ep *usbep, struct usb_request *usbreq, gfp_t gfp) | ||
1079 | { | ||
1080 | int retval = 0; | ||
1081 | u8 open_rxfifo = 0; | ||
1082 | unsigned long iflags; | ||
1083 | struct udc_ep *ep; | ||
1084 | struct udc_request *req; | ||
1085 | struct udc *dev; | ||
1086 | u32 tmp; | ||
1087 | |||
1088 | /* check the inputs */ | ||
1089 | req = container_of(usbreq, struct udc_request, req); | ||
1090 | |||
1091 | if (!usbep || !usbreq || !usbreq->complete || !usbreq->buf | ||
1092 | || !list_empty(&req->queue)) | ||
1093 | return -EINVAL; | ||
1094 | |||
1095 | ep = container_of(usbep, struct udc_ep, ep); | ||
1096 | if (!ep->desc && (ep->num != 0 && ep->num != UDC_EP0OUT_IX)) | ||
1097 | return -EINVAL; | ||
1098 | |||
1099 | VDBG(ep->dev, "udc_queue(): ep%d-in=%d\n", ep->num, ep->in); | ||
1100 | dev = ep->dev; | ||
1101 | |||
1102 | if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
1103 | return -ESHUTDOWN; | ||
1104 | |||
1105 | /* map dma (usually done before) */ | ||
1106 | if (ep->dma && usbreq->length != 0 | ||
1107 | && (usbreq->dma == DMA_DONT_USE || usbreq->dma == 0)) { | ||
1108 | VDBG(dev, "DMA map req %p\n", req); | ||
1109 | if (ep->in) | ||
1110 | usbreq->dma = pci_map_single(dev->pdev, | ||
1111 | usbreq->buf, | ||
1112 | usbreq->length, | ||
1113 | PCI_DMA_TODEVICE); | ||
1114 | else | ||
1115 | usbreq->dma = pci_map_single(dev->pdev, | ||
1116 | usbreq->buf, | ||
1117 | usbreq->length, | ||
1118 | PCI_DMA_FROMDEVICE); | ||
1119 | req->dma_mapping = 1; | ||
1120 | } | ||
1121 | |||
1122 | VDBG(dev, "%s queue req %p, len %d req->td_data=%p buf %p\n", | ||
1123 | usbep->name, usbreq, usbreq->length, | ||
1124 | req->td_data, usbreq->buf); | ||
1125 | |||
1126 | spin_lock_irqsave(&dev->lock, iflags); | ||
1127 | usbreq->actual = 0; | ||
1128 | usbreq->status = -EINPROGRESS; | ||
1129 | req->dma_done = 0; | ||
1130 | |||
1131 | /* on empty queue just do first transfer */ | ||
1132 | if (list_empty(&ep->queue)) { | ||
1133 | /* zlp */ | ||
1134 | if (usbreq->length == 0) { | ||
1135 | /* IN zlp's are handled by hardware */ | ||
1136 | complete_req(ep, req, 0); | ||
1137 | VDBG(dev, "%s: zlp\n", ep->ep.name); | ||
1138 | /* | ||
1139 | * if set_config or set_intf is waiting for ack by zlp | ||
1140 | * then set CSR_DONE | ||
1141 | */ | ||
1142 | if (dev->set_cfg_not_acked) { | ||
1143 | tmp = readl(&dev->regs->ctl); | ||
1144 | tmp |= AMD_BIT(UDC_DEVCTL_CSR_DONE); | ||
1145 | writel(tmp, &dev->regs->ctl); | ||
1146 | dev->set_cfg_not_acked = 0; | ||
1147 | } | ||
1148 | /* setup command is ACK'ed now by zlp */ | ||
1149 | if (dev->waiting_zlp_ack_ep0in) { | ||
1150 | /* clear NAK by writing CNAK in EP0_IN */ | ||
1151 | tmp = readl(&dev->ep[UDC_EP0IN_IX].regs->ctl); | ||
1152 | tmp |= AMD_BIT(UDC_EPCTL_CNAK); | ||
1153 | writel(tmp, &dev->ep[UDC_EP0IN_IX].regs->ctl); | ||
1154 | dev->ep[UDC_EP0IN_IX].naking = 0; | ||
1155 | UDC_QUEUE_CNAK(&dev->ep[UDC_EP0IN_IX], | ||
1156 | UDC_EP0IN_IX); | ||
1157 | dev->waiting_zlp_ack_ep0in = 0; | ||
1158 | } | ||
1159 | goto finished; | ||
1160 | } | ||
1161 | if (ep->dma) { | ||
1162 | retval = prep_dma(ep, req, gfp); | ||
1163 | if (retval != 0) | ||
1164 | goto finished; | ||
1165 | /* write desc pointer to enable DMA */ | ||
1166 | if (ep->in) { | ||
1167 | /* set HOST READY */ | ||
1168 | req->td_data->status = | ||
1169 | AMD_ADDBITS(req->td_data->status, | ||
1170 | UDC_DMA_IN_STS_BS_HOST_READY, | ||
1171 | UDC_DMA_IN_STS_BS); | ||
1172 | } | ||
1173 | |||
1174 | /* disabled rx dma while descriptor update */ | ||
1175 | if (!ep->in) { | ||
1176 | /* stop RDE timer */ | ||
1177 | if (timer_pending(&udc_timer)) { | ||
1178 | set_rde = 0; | ||
1179 | mod_timer(&udc_timer, jiffies - 1); | ||
1180 | } | ||
1181 | /* clear RDE */ | ||
1182 | tmp = readl(&dev->regs->ctl); | ||
1183 | tmp &= AMD_UNMASK_BIT(UDC_DEVCTL_RDE); | ||
1184 | writel(tmp, &dev->regs->ctl); | ||
1185 | open_rxfifo = 1; | ||
1186 | |||
1187 | /* | ||
1188 | * if BNA occurred then let BNA dummy desc. | ||
1189 | * point to current desc. | ||
1190 | */ | ||
1191 | if (ep->bna_occurred) { | ||
1192 | VDBG(dev, "copy to BNA dummy desc.\n"); | ||
1193 | memcpy(ep->bna_dummy_req->td_data, | ||
1194 | req->td_data, | ||
1195 | sizeof(struct udc_data_dma)); | ||
1196 | } | ||
1197 | } | ||
1198 | /* write desc pointer */ | ||
1199 | writel(req->td_phys, &ep->regs->desptr); | ||
1200 | |||
1201 | /* clear NAK by writing CNAK */ | ||
1202 | if (ep->naking) { | ||
1203 | tmp = readl(&ep->regs->ctl); | ||
1204 | tmp |= AMD_BIT(UDC_EPCTL_CNAK); | ||
1205 | writel(tmp, &ep->regs->ctl); | ||
1206 | ep->naking = 0; | ||
1207 | UDC_QUEUE_CNAK(ep, ep->num); | ||
1208 | } | ||
1209 | |||
1210 | if (ep->in) { | ||
1211 | /* enable ep irq */ | ||
1212 | tmp = readl(&dev->regs->ep_irqmsk); | ||
1213 | tmp &= AMD_UNMASK_BIT(ep->num); | ||
1214 | writel(tmp, &dev->regs->ep_irqmsk); | ||
1215 | } | ||
1216 | } | ||
1217 | |||
1218 | } else if (ep->dma) { | ||
1219 | |||
1220 | /* | ||
1221 | * prep_dma not used for OUT ep's, this is not possible | ||
1222 | * for PPB modes, because of chain creation reasons | ||
1223 | */ | ||
1224 | if (ep->in) { | ||
1225 | retval = prep_dma(ep, req, gfp); | ||
1226 | if (retval != 0) | ||
1227 | goto finished; | ||
1228 | } | ||
1229 | } | ||
1230 | VDBG(dev, "list_add\n"); | ||
1231 | /* add request to ep queue */ | ||
1232 | if (req) { | ||
1233 | |||
1234 | list_add_tail(&req->queue, &ep->queue); | ||
1235 | |||
1236 | /* open rxfifo if out data queued */ | ||
1237 | if (open_rxfifo) { | ||
1238 | /* enable DMA */ | ||
1239 | req->dma_going = 1; | ||
1240 | udc_set_rde(dev); | ||
1241 | if (ep->num != UDC_EP0OUT_IX) | ||
1242 | dev->data_ep_queued = 1; | ||
1243 | } | ||
1244 | /* stop OUT naking */ | ||
1245 | if (!ep->in) { | ||
1246 | if (!use_dma && udc_rxfifo_pending) { | ||
1247 | DBG(dev, "udc_queue(): pending bytes in" | ||
1248 | "rxfifo after nyet\n"); | ||
1249 | /* | ||
1250 | * read pending bytes afer nyet: | ||
1251 | * referring to isr | ||
1252 | */ | ||
1253 | if (udc_rxfifo_read(ep, req)) { | ||
1254 | /* finish */ | ||
1255 | complete_req(ep, req, 0); | ||
1256 | } | ||
1257 | udc_rxfifo_pending = 0; | ||
1258 | |||
1259 | } | ||
1260 | } | ||
1261 | } | ||
1262 | |||
1263 | finished: | ||
1264 | spin_unlock_irqrestore(&dev->lock, iflags); | ||
1265 | return retval; | ||
1266 | } | ||
1267 | |||
1268 | /* Empty request queue of an endpoint; caller holds spinlock */ | ||
1269 | static void empty_req_queue(struct udc_ep *ep) | ||
1270 | { | ||
1271 | struct udc_request *req; | ||
1272 | |||
1273 | ep->halted = 1; | ||
1274 | while (!list_empty(&ep->queue)) { | ||
1275 | req = list_entry(ep->queue.next, | ||
1276 | struct udc_request, | ||
1277 | queue); | ||
1278 | complete_req(ep, req, -ESHUTDOWN); | ||
1279 | } | ||
1280 | } | ||
1281 | |||
1282 | /* Dequeues a request packet, called by gadget driver */ | ||
1283 | static int udc_dequeue(struct usb_ep *usbep, struct usb_request *usbreq) | ||
1284 | { | ||
1285 | struct udc_ep *ep; | ||
1286 | struct udc_request *req; | ||
1287 | unsigned halted; | ||
1288 | unsigned long iflags; | ||
1289 | |||
1290 | ep = container_of(usbep, struct udc_ep, ep); | ||
1291 | if (!usbep || !usbreq || (!ep->desc && (ep->num != 0 | ||
1292 | && ep->num != UDC_EP0OUT_IX))) | ||
1293 | return -EINVAL; | ||
1294 | |||
1295 | req = container_of(usbreq, struct udc_request, req); | ||
1296 | |||
1297 | spin_lock_irqsave(&ep->dev->lock, iflags); | ||
1298 | halted = ep->halted; | ||
1299 | ep->halted = 1; | ||
1300 | /* request in processing or next one */ | ||
1301 | if (ep->queue.next == &req->queue) { | ||
1302 | if (ep->dma && req->dma_going) { | ||
1303 | if (ep->in) | ||
1304 | ep->cancel_transfer = 1; | ||
1305 | else { | ||
1306 | u32 tmp; | ||
1307 | u32 dma_sts; | ||
1308 | /* stop potential receive DMA */ | ||
1309 | tmp = readl(&udc->regs->ctl); | ||
1310 | writel(tmp & AMD_UNMASK_BIT(UDC_DEVCTL_RDE), | ||
1311 | &udc->regs->ctl); | ||
1312 | /* | ||
1313 | * Cancel transfer later in ISR | ||
1314 | * if descriptor was touched. | ||
1315 | */ | ||
1316 | dma_sts = AMD_GETBITS(req->td_data->status, | ||
1317 | UDC_DMA_OUT_STS_BS); | ||
1318 | if (dma_sts != UDC_DMA_OUT_STS_BS_HOST_READY) | ||
1319 | ep->cancel_transfer = 1; | ||
1320 | else { | ||
1321 | udc_init_bna_dummy(ep->req); | ||
1322 | writel(ep->bna_dummy_req->td_phys, | ||
1323 | &ep->regs->desptr); | ||
1324 | } | ||
1325 | writel(tmp, &udc->regs->ctl); | ||
1326 | } | ||
1327 | } | ||
1328 | } | ||
1329 | complete_req(ep, req, -ECONNRESET); | ||
1330 | ep->halted = halted; | ||
1331 | |||
1332 | spin_unlock_irqrestore(&ep->dev->lock, iflags); | ||
1333 | return 0; | ||
1334 | } | ||
1335 | |||
1336 | /* Halt or clear halt of endpoint */ | ||
1337 | static int | ||
1338 | udc_set_halt(struct usb_ep *usbep, int halt) | ||
1339 | { | ||
1340 | struct udc_ep *ep; | ||
1341 | u32 tmp; | ||
1342 | unsigned long iflags; | ||
1343 | int retval = 0; | ||
1344 | |||
1345 | if (!usbep) | ||
1346 | return -EINVAL; | ||
1347 | |||
1348 | pr_debug("set_halt %s: halt=%d\n", usbep->name, halt); | ||
1349 | |||
1350 | ep = container_of(usbep, struct udc_ep, ep); | ||
1351 | if (!ep->desc && (ep->num != 0 && ep->num != UDC_EP0OUT_IX)) | ||
1352 | return -EINVAL; | ||
1353 | if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN) | ||
1354 | return -ESHUTDOWN; | ||
1355 | |||
1356 | spin_lock_irqsave(&udc_stall_spinlock, iflags); | ||
1357 | /* halt or clear halt */ | ||
1358 | if (halt) { | ||
1359 | if (ep->num == 0) | ||
1360 | ep->dev->stall_ep0in = 1; | ||
1361 | else { | ||
1362 | /* | ||
1363 | * set STALL | ||
1364 | * rxfifo empty not taken into acount | ||
1365 | */ | ||
1366 | tmp = readl(&ep->regs->ctl); | ||
1367 | tmp |= AMD_BIT(UDC_EPCTL_S); | ||
1368 | writel(tmp, &ep->regs->ctl); | ||
1369 | ep->halted = 1; | ||
1370 | |||
1371 | /* setup poll timer */ | ||
1372 | if (!timer_pending(&udc_pollstall_timer)) { | ||
1373 | udc_pollstall_timer.expires = jiffies + | ||
1374 | HZ * UDC_POLLSTALL_TIMER_USECONDS | ||
1375 | / (1000 * 1000); | ||
1376 | if (!stop_pollstall_timer) { | ||
1377 | DBG(ep->dev, "start polltimer\n"); | ||
1378 | add_timer(&udc_pollstall_timer); | ||
1379 | } | ||
1380 | } | ||
1381 | } | ||
1382 | } else { | ||
1383 | /* ep is halted by set_halt() before */ | ||
1384 | if (ep->halted) { | ||
1385 | tmp = readl(&ep->regs->ctl); | ||
1386 | /* clear stall bit */ | ||
1387 | tmp = tmp & AMD_CLEAR_BIT(UDC_EPCTL_S); | ||
1388 | /* clear NAK by writing CNAK */ | ||
1389 | tmp |= AMD_BIT(UDC_EPCTL_CNAK); | ||
1390 | writel(tmp, &ep->regs->ctl); | ||
1391 | ep->halted = 0; | ||
1392 | UDC_QUEUE_CNAK(ep, ep->num); | ||
1393 | } | ||
1394 | } | ||
1395 | spin_unlock_irqrestore(&udc_stall_spinlock, iflags); | ||
1396 | return retval; | ||
1397 | } | ||
1398 | |||
1399 | /* gadget interface */ | ||
1400 | static const struct usb_ep_ops udc_ep_ops = { | ||
1401 | .enable = udc_ep_enable, | ||
1402 | .disable = udc_ep_disable, | ||
1403 | |||
1404 | .alloc_request = udc_alloc_request, | ||
1405 | .free_request = udc_free_request, | ||
1406 | |||
1407 | .queue = udc_queue, | ||
1408 | .dequeue = udc_dequeue, | ||
1409 | |||
1410 | .set_halt = udc_set_halt, | ||
1411 | /* fifo ops not implemented */ | ||
1412 | }; | ||
1413 | |||
1414 | /*-------------------------------------------------------------------------*/ | ||
1415 | |||
1416 | /* Get frame counter (not implemented) */ | ||
1417 | static int udc_get_frame(struct usb_gadget *gadget) | ||
1418 | { | ||
1419 | return -EOPNOTSUPP; | ||
1420 | } | ||
1421 | |||
1422 | /* Remote wakeup gadget interface */ | ||
1423 | static int udc_wakeup(struct usb_gadget *gadget) | ||
1424 | { | ||
1425 | struct udc *dev; | ||
1426 | |||
1427 | if (!gadget) | ||
1428 | return -EINVAL; | ||
1429 | dev = container_of(gadget, struct udc, gadget); | ||
1430 | udc_remote_wakeup(dev); | ||
1431 | |||
1432 | return 0; | ||
1433 | } | ||
1434 | |||
1435 | /* gadget operations */ | ||
1436 | static const struct usb_gadget_ops udc_ops = { | ||
1437 | .wakeup = udc_wakeup, | ||
1438 | .get_frame = udc_get_frame, | ||
1439 | }; | ||
1440 | |||
1441 | /* Setups endpoint parameters, adds endpoints to linked list */ | ||
1442 | static void make_ep_lists(struct udc *dev) | ||
1443 | { | ||
1444 | /* make gadget ep lists */ | ||
1445 | INIT_LIST_HEAD(&dev->gadget.ep_list); | ||
1446 | list_add_tail(&dev->ep[UDC_EPIN_STATUS_IX].ep.ep_list, | ||
1447 | &dev->gadget.ep_list); | ||
1448 | list_add_tail(&dev->ep[UDC_EPIN_IX].ep.ep_list, | ||
1449 | &dev->gadget.ep_list); | ||
1450 | list_add_tail(&dev->ep[UDC_EPOUT_IX].ep.ep_list, | ||
1451 | &dev->gadget.ep_list); | ||
1452 | |||
1453 | /* fifo config */ | ||
1454 | dev->ep[UDC_EPIN_STATUS_IX].fifo_depth = UDC_EPIN_SMALLINT_BUFF_SIZE; | ||
1455 | if (dev->gadget.speed == USB_SPEED_FULL) | ||
1456 | dev->ep[UDC_EPIN_IX].fifo_depth = UDC_FS_EPIN_BUFF_SIZE; | ||
1457 | else if (dev->gadget.speed == USB_SPEED_HIGH) | ||
1458 | dev->ep[UDC_EPIN_IX].fifo_depth = hs_tx_buf; | ||
1459 | dev->ep[UDC_EPOUT_IX].fifo_depth = UDC_RXFIFO_SIZE; | ||
1460 | } | ||
1461 | |||
1462 | /* init registers at driver load time */ | ||
1463 | static int startup_registers(struct udc *dev) | ||
1464 | { | ||
1465 | u32 tmp; | ||
1466 | |||
1467 | /* init controller by soft reset */ | ||
1468 | udc_soft_reset(dev); | ||
1469 | |||
1470 | /* mask not needed interrupts */ | ||
1471 | udc_mask_unused_interrupts(dev); | ||
1472 | |||
1473 | /* put into initial config */ | ||
1474 | udc_basic_init(dev); | ||
1475 | /* link up all endpoints */ | ||
1476 | udc_setup_endpoints(dev); | ||
1477 | |||
1478 | /* program speed */ | ||
1479 | tmp = readl(&dev->regs->cfg); | ||
1480 | if (use_fullspeed) { | ||
1481 | tmp = AMD_ADDBITS(tmp, UDC_DEVCFG_SPD_FS, UDC_DEVCFG_SPD); | ||
1482 | } else { | ||
1483 | tmp = AMD_ADDBITS(tmp, UDC_DEVCFG_SPD_HS, UDC_DEVCFG_SPD); | ||
1484 | } | ||
1485 | writel(tmp, &dev->regs->cfg); | ||
1486 | |||
1487 | return 0; | ||
1488 | } | ||
1489 | |||
1490 | /* Inits UDC context */ | ||
1491 | static void udc_basic_init(struct udc *dev) | ||
1492 | { | ||
1493 | u32 tmp; | ||
1494 | |||
1495 | DBG(dev, "udc_basic_init()\n"); | ||
1496 | |||
1497 | dev->gadget.speed = USB_SPEED_UNKNOWN; | ||
1498 | |||
1499 | /* stop RDE timer */ | ||
1500 | if (timer_pending(&udc_timer)) { | ||
1501 | set_rde = 0; | ||
1502 | mod_timer(&udc_timer, jiffies - 1); | ||
1503 | } | ||
1504 | /* stop poll stall timer */ | ||
1505 | if (timer_pending(&udc_pollstall_timer)) { | ||
1506 | mod_timer(&udc_pollstall_timer, jiffies - 1); | ||
1507 | } | ||
1508 | /* disable DMA */ | ||
1509 | tmp = readl(&dev->regs->ctl); | ||
1510 | tmp &= AMD_UNMASK_BIT(UDC_DEVCTL_RDE); | ||
1511 | tmp &= AMD_UNMASK_BIT(UDC_DEVCTL_TDE); | ||
1512 | writel(tmp, &dev->regs->ctl); | ||
1513 | |||
1514 | /* enable dynamic CSR programming */ | ||
1515 | tmp = readl(&dev->regs->cfg); | ||
1516 | tmp |= AMD_BIT(UDC_DEVCFG_CSR_PRG); | ||
1517 | /* set self powered */ | ||
1518 | tmp |= AMD_BIT(UDC_DEVCFG_SP); | ||
1519 | /* set remote wakeupable */ | ||
1520 | tmp |= AMD_BIT(UDC_DEVCFG_RWKP); | ||
1521 | writel(tmp, &dev->regs->cfg); | ||
1522 | |||
1523 | make_ep_lists(dev); | ||
1524 | |||
1525 | dev->data_ep_enabled = 0; | ||
1526 | dev->data_ep_queued = 0; | ||
1527 | } | ||
1528 | |||
1529 | /* Sets initial endpoint parameters */ | ||
1530 | static void udc_setup_endpoints(struct udc *dev) | ||
1531 | { | ||
1532 | struct udc_ep *ep; | ||
1533 | u32 tmp; | ||
1534 | u32 reg; | ||
1535 | |||
1536 | DBG(dev, "udc_setup_endpoints()\n"); | ||
1537 | |||
1538 | /* read enum speed */ | ||
1539 | tmp = readl(&dev->regs->sts); | ||
1540 | tmp = AMD_GETBITS(tmp, UDC_DEVSTS_ENUM_SPEED); | ||
1541 | if (tmp == UDC_DEVSTS_ENUM_SPEED_HIGH) { | ||
1542 | dev->gadget.speed = USB_SPEED_HIGH; | ||
1543 | } else if (tmp == UDC_DEVSTS_ENUM_SPEED_FULL) { | ||
1544 | dev->gadget.speed = USB_SPEED_FULL; | ||
1545 | } | ||
1546 | |||
1547 | /* set basic ep parameters */ | ||
1548 | for (tmp = 0; tmp < UDC_EP_NUM; tmp++) { | ||
1549 | ep = &dev->ep[tmp]; | ||
1550 | ep->dev = dev; | ||
1551 | ep->ep.name = ep_string[tmp]; | ||
1552 | ep->num = tmp; | ||
1553 | /* txfifo size is calculated at enable time */ | ||
1554 | ep->txfifo = dev->txfifo; | ||
1555 | |||
1556 | /* fifo size */ | ||
1557 | if (tmp < UDC_EPIN_NUM) { | ||
1558 | ep->fifo_depth = UDC_TXFIFO_SIZE; | ||
1559 | ep->in = 1; | ||
1560 | } else { | ||
1561 | ep->fifo_depth = UDC_RXFIFO_SIZE; | ||
1562 | ep->in = 0; | ||
1563 | |||
1564 | } | ||
1565 | ep->regs = &dev->ep_regs[tmp]; | ||
1566 | /* | ||
1567 | * ep will be reset only if ep was not enabled before to avoid | ||
1568 | * disabling ep interrupts when ENUM interrupt occurs but ep is | ||
1569 | * not enabled by gadget driver | ||
1570 | */ | ||
1571 | if (!ep->desc) { | ||
1572 | ep_init(dev->regs, ep); | ||
1573 | } | ||
1574 | |||
1575 | if (use_dma) { | ||
1576 | /* | ||
1577 | * ep->dma is not really used, just to indicate that | ||
1578 | * DMA is active: remove this | ||
1579 | * dma regs = dev control regs | ||
1580 | */ | ||
1581 | ep->dma = &dev->regs->ctl; | ||
1582 | |||
1583 | /* nak OUT endpoints until enable - not for ep0 */ | ||
1584 | if (tmp != UDC_EP0IN_IX && tmp != UDC_EP0OUT_IX | ||
1585 | && tmp > UDC_EPIN_NUM) { | ||
1586 | /* set NAK */ | ||
1587 | reg = readl(&dev->ep[tmp].regs->ctl); | ||
1588 | reg |= AMD_BIT(UDC_EPCTL_SNAK); | ||
1589 | writel(reg, &dev->ep[tmp].regs->ctl); | ||
1590 | dev->ep[tmp].naking = 1; | ||
1591 | |||
1592 | } | ||
1593 | } | ||
1594 | } | ||
1595 | /* EP0 max packet */ | ||
1596 | if (dev->gadget.speed == USB_SPEED_FULL) { | ||
1597 | dev->ep[UDC_EP0IN_IX].ep.maxpacket = UDC_FS_EP0IN_MAX_PKT_SIZE; | ||
1598 | dev->ep[UDC_EP0OUT_IX].ep.maxpacket = | ||
1599 | UDC_FS_EP0OUT_MAX_PKT_SIZE; | ||
1600 | } else if (dev->gadget.speed == USB_SPEED_HIGH) { | ||
1601 | dev->ep[UDC_EP0IN_IX].ep.maxpacket = UDC_EP0IN_MAX_PKT_SIZE; | ||
1602 | dev->ep[UDC_EP0OUT_IX].ep.maxpacket = UDC_EP0OUT_MAX_PKT_SIZE; | ||
1603 | } | ||
1604 | |||
1605 | /* | ||
1606 | * with suspend bug workaround, ep0 params for gadget driver | ||
1607 | * are set at gadget driver bind() call | ||
1608 | */ | ||
1609 | dev->gadget.ep0 = &dev->ep[UDC_EP0IN_IX].ep; | ||
1610 | dev->ep[UDC_EP0IN_IX].halted = 0; | ||
1611 | INIT_LIST_HEAD(&dev->gadget.ep0->ep_list); | ||
1612 | |||
1613 | /* init cfg/alt/int */ | ||
1614 | dev->cur_config = 0; | ||
1615 | dev->cur_intf = 0; | ||
1616 | dev->cur_alt = 0; | ||
1617 | } | ||
1618 | |||
1619 | /* Bringup after Connect event, initial bringup to be ready for ep0 events */ | ||
1620 | static void usb_connect(struct udc *dev) | ||
1621 | { | ||
1622 | |||
1623 | dev_info(&dev->pdev->dev, "USB Connect\n"); | ||
1624 | |||
1625 | dev->connected = 1; | ||
1626 | |||
1627 | /* put into initial config */ | ||
1628 | udc_basic_init(dev); | ||
1629 | |||
1630 | /* enable device setup interrupts */ | ||
1631 | udc_enable_dev_setup_interrupts(dev); | ||
1632 | } | ||
1633 | |||
1634 | /* | ||
1635 | * Calls gadget with disconnect event and resets the UDC and makes | ||
1636 | * initial bringup to be ready for ep0 events | ||
1637 | */ | ||
1638 | static void usb_disconnect(struct udc *dev) | ||
1639 | { | ||
1640 | |||
1641 | dev_info(&dev->pdev->dev, "USB Disconnect\n"); | ||
1642 | |||
1643 | dev->connected = 0; | ||
1644 | |||
1645 | /* mask interrupts */ | ||
1646 | udc_mask_unused_interrupts(dev); | ||
1647 | |||
1648 | /* REVISIT there doesn't seem to be a point to having this | ||
1649 | * talk to a tasklet ... do it directly, we already hold | ||
1650 | * the spinlock needed to process the disconnect. | ||
1651 | */ | ||
1652 | |||
1653 | tasklet_schedule(&disconnect_tasklet); | ||
1654 | } | ||
1655 | |||
1656 | /* Tasklet for disconnect to be outside of interrupt context */ | ||
1657 | static void udc_tasklet_disconnect(unsigned long par) | ||
1658 | { | ||
1659 | struct udc *dev = (struct udc *)(*((struct udc **) par)); | ||
1660 | u32 tmp; | ||
1661 | |||
1662 | DBG(dev, "Tasklet disconnect\n"); | ||
1663 | spin_lock_irq(&dev->lock); | ||
1664 | |||
1665 | if (dev->driver) { | ||
1666 | spin_unlock(&dev->lock); | ||
1667 | dev->driver->disconnect(&dev->gadget); | ||
1668 | spin_lock(&dev->lock); | ||
1669 | |||
1670 | /* empty queues */ | ||
1671 | for (tmp = 0; tmp < UDC_EP_NUM; tmp++) { | ||
1672 | empty_req_queue(&dev->ep[tmp]); | ||
1673 | } | ||
1674 | |||
1675 | } | ||
1676 | |||
1677 | /* disable ep0 */ | ||
1678 | ep_init(dev->regs, | ||
1679 | &dev->ep[UDC_EP0IN_IX]); | ||
1680 | |||
1681 | |||
1682 | if (!soft_reset_occured) { | ||
1683 | /* init controller by soft reset */ | ||
1684 | udc_soft_reset(dev); | ||
1685 | soft_reset_occured++; | ||
1686 | } | ||
1687 | |||
1688 | /* re-enable dev interrupts */ | ||
1689 | udc_enable_dev_setup_interrupts(dev); | ||
1690 | /* back to full speed ? */ | ||
1691 | if (use_fullspeed) { | ||
1692 | tmp = readl(&dev->regs->cfg); | ||
1693 | tmp = AMD_ADDBITS(tmp, UDC_DEVCFG_SPD_FS, UDC_DEVCFG_SPD); | ||
1694 | writel(tmp, &dev->regs->cfg); | ||
1695 | } | ||
1696 | |||
1697 | spin_unlock_irq(&dev->lock); | ||
1698 | } | ||
1699 | |||
1700 | /* Reset the UDC core */ | ||
1701 | static void udc_soft_reset(struct udc *dev) | ||
1702 | { | ||
1703 | unsigned long flags; | ||
1704 | |||
1705 | DBG(dev, "Soft reset\n"); | ||
1706 | /* | ||
1707 | * reset possible waiting interrupts, because int. | ||
1708 | * status is lost after soft reset, | ||
1709 | * ep int. status reset | ||
1710 | */ | ||
1711 | writel(UDC_EPINT_MSK_DISABLE_ALL, &dev->regs->ep_irqsts); | ||
1712 | /* device int. status reset */ | ||
1713 | writel(UDC_DEV_MSK_DISABLE, &dev->regs->irqsts); | ||
1714 | |||
1715 | spin_lock_irqsave(&udc_irq_spinlock, flags); | ||
1716 | writel(AMD_BIT(UDC_DEVCFG_SOFTRESET), &dev->regs->cfg); | ||
1717 | readl(&dev->regs->cfg); | ||
1718 | spin_unlock_irqrestore(&udc_irq_spinlock, flags); | ||
1719 | |||
1720 | } | ||
1721 | |||
1722 | /* RDE timer callback to set RDE bit */ | ||
1723 | static void udc_timer_function(unsigned long v) | ||
1724 | { | ||
1725 | u32 tmp; | ||
1726 | |||
1727 | spin_lock_irq(&udc_irq_spinlock); | ||
1728 | |||
1729 | if (set_rde > 0) { | ||
1730 | /* | ||
1731 | * open the fifo if fifo was filled on last timer call | ||
1732 | * conditionally | ||
1733 | */ | ||
1734 | if (set_rde > 1) { | ||
1735 | /* set RDE to receive setup data */ | ||
1736 | tmp = readl(&udc->regs->ctl); | ||
1737 | tmp |= AMD_BIT(UDC_DEVCTL_RDE); | ||
1738 | writel(tmp, &udc->regs->ctl); | ||
1739 | set_rde = -1; | ||
1740 | } else if (readl(&udc->regs->sts) | ||
1741 | & AMD_BIT(UDC_DEVSTS_RXFIFO_EMPTY)) { | ||
1742 | /* | ||
1743 | * if fifo empty setup polling, do not just | ||
1744 | * open the fifo | ||
1745 | */ | ||
1746 | udc_timer.expires = jiffies + HZ/UDC_RDE_TIMER_DIV; | ||
1747 | if (!stop_timer) { | ||
1748 | add_timer(&udc_timer); | ||
1749 | } | ||
1750 | } else { | ||
1751 | /* | ||
1752 | * fifo contains data now, setup timer for opening | ||
1753 | * the fifo when timer expires to be able to receive | ||
1754 | * setup packets, when data packets gets queued by | ||
1755 | * gadget layer then timer will forced to expire with | ||
1756 | * set_rde=0 (RDE is set in udc_queue()) | ||
1757 | */ | ||
1758 | set_rde++; | ||
1759 | /* debug: lhadmot_timer_start = 221070 */ | ||
1760 | udc_timer.expires = jiffies + HZ*UDC_RDE_TIMER_SECONDS; | ||
1761 | if (!stop_timer) { | ||
1762 | add_timer(&udc_timer); | ||
1763 | } | ||
1764 | } | ||
1765 | |||
1766 | } else | ||
1767 | set_rde = -1; /* RDE was set by udc_queue() */ | ||
1768 | spin_unlock_irq(&udc_irq_spinlock); | ||
1769 | if (stop_timer) | ||
1770 | complete(&on_exit); | ||
1771 | |||
1772 | } | ||
1773 | |||
1774 | /* Handle halt state, used in stall poll timer */ | ||
1775 | static void udc_handle_halt_state(struct udc_ep *ep) | ||
1776 | { | ||
1777 | u32 tmp; | ||
1778 | /* set stall as long not halted */ | ||
1779 | if (ep->halted == 1) { | ||
1780 | tmp = readl(&ep->regs->ctl); | ||
1781 | /* STALL cleared ? */ | ||
1782 | if (!(tmp & AMD_BIT(UDC_EPCTL_S))) { | ||
1783 | /* | ||
1784 | * FIXME: MSC spec requires that stall remains | ||
1785 | * even on receivng of CLEAR_FEATURE HALT. So | ||
1786 | * we would set STALL again here to be compliant. | ||
1787 | * But with current mass storage drivers this does | ||
1788 | * not work (would produce endless host retries). | ||
1789 | * So we clear halt on CLEAR_FEATURE. | ||
1790 | * | ||
1791 | DBG(ep->dev, "ep %d: set STALL again\n", ep->num); | ||
1792 | tmp |= AMD_BIT(UDC_EPCTL_S); | ||
1793 | writel(tmp, &ep->regs->ctl);*/ | ||
1794 | |||
1795 | /* clear NAK by writing CNAK */ | ||
1796 | tmp |= AMD_BIT(UDC_EPCTL_CNAK); | ||
1797 | writel(tmp, &ep->regs->ctl); | ||
1798 | ep->halted = 0; | ||
1799 | UDC_QUEUE_CNAK(ep, ep->num); | ||
1800 | } | ||
1801 | } | ||
1802 | } | ||
1803 | |||
1804 | /* Stall timer callback to poll S bit and set it again after */ | ||
1805 | static void udc_pollstall_timer_function(unsigned long v) | ||
1806 | { | ||
1807 | struct udc_ep *ep; | ||
1808 | int halted = 0; | ||
1809 | |||
1810 | spin_lock_irq(&udc_stall_spinlock); | ||
1811 | /* | ||
1812 | * only one IN and OUT endpoints are handled | ||
1813 | * IN poll stall | ||
1814 | */ | ||
1815 | ep = &udc->ep[UDC_EPIN_IX]; | ||
1816 | udc_handle_halt_state(ep); | ||
1817 | if (ep->halted) | ||
1818 | halted = 1; | ||
1819 | /* OUT poll stall */ | ||
1820 | ep = &udc->ep[UDC_EPOUT_IX]; | ||
1821 | udc_handle_halt_state(ep); | ||
1822 | if (ep->halted) | ||
1823 | halted = 1; | ||
1824 | |||
1825 | /* setup timer again when still halted */ | ||
1826 | if (!stop_pollstall_timer && halted) { | ||
1827 | udc_pollstall_timer.expires = jiffies + | ||
1828 | HZ * UDC_POLLSTALL_TIMER_USECONDS | ||
1829 | / (1000 * 1000); | ||
1830 | add_timer(&udc_pollstall_timer); | ||
1831 | } | ||
1832 | spin_unlock_irq(&udc_stall_spinlock); | ||
1833 | |||
1834 | if (stop_pollstall_timer) | ||
1835 | complete(&on_pollstall_exit); | ||
1836 | } | ||
1837 | |||
1838 | /* Inits endpoint 0 so that SETUP packets are processed */ | ||
1839 | static void activate_control_endpoints(struct udc *dev) | ||
1840 | { | ||
1841 | u32 tmp; | ||
1842 | |||
1843 | DBG(dev, "activate_control_endpoints\n"); | ||
1844 | |||
1845 | /* flush fifo */ | ||
1846 | tmp = readl(&dev->ep[UDC_EP0IN_IX].regs->ctl); | ||
1847 | tmp |= AMD_BIT(UDC_EPCTL_F); | ||
1848 | writel(tmp, &dev->ep[UDC_EP0IN_IX].regs->ctl); | ||
1849 | |||
1850 | /* set ep0 directions */ | ||
1851 | dev->ep[UDC_EP0IN_IX].in = 1; | ||
1852 | dev->ep[UDC_EP0OUT_IX].in = 0; | ||
1853 | |||
1854 | /* set buffer size (tx fifo entries) of EP0_IN */ | ||
1855 | tmp = readl(&dev->ep[UDC_EP0IN_IX].regs->bufin_framenum); | ||
1856 | if (dev->gadget.speed == USB_SPEED_FULL) | ||
1857 | tmp = AMD_ADDBITS(tmp, UDC_FS_EPIN0_BUFF_SIZE, | ||
1858 | UDC_EPIN_BUFF_SIZE); | ||
1859 | else if (dev->gadget.speed == USB_SPEED_HIGH) | ||
1860 | tmp = AMD_ADDBITS(tmp, UDC_EPIN0_BUFF_SIZE, | ||
1861 | UDC_EPIN_BUFF_SIZE); | ||
1862 | writel(tmp, &dev->ep[UDC_EP0IN_IX].regs->bufin_framenum); | ||
1863 | |||
1864 | /* set max packet size of EP0_IN */ | ||
1865 | tmp = readl(&dev->ep[UDC_EP0IN_IX].regs->bufout_maxpkt); | ||
1866 | if (dev->gadget.speed == USB_SPEED_FULL) | ||
1867 | tmp = AMD_ADDBITS(tmp, UDC_FS_EP0IN_MAX_PKT_SIZE, | ||
1868 | UDC_EP_MAX_PKT_SIZE); | ||
1869 | else if (dev->gadget.speed == USB_SPEED_HIGH) | ||
1870 | tmp = AMD_ADDBITS(tmp, UDC_EP0IN_MAX_PKT_SIZE, | ||
1871 | UDC_EP_MAX_PKT_SIZE); | ||
1872 | writel(tmp, &dev->ep[UDC_EP0IN_IX].regs->bufout_maxpkt); | ||
1873 | |||
1874 | /* set max packet size of EP0_OUT */ | ||
1875 | tmp = readl(&dev->ep[UDC_EP0OUT_IX].regs->bufout_maxpkt); | ||
1876 | if (dev->gadget.speed == USB_SPEED_FULL) | ||
1877 | tmp = AMD_ADDBITS(tmp, UDC_FS_EP0OUT_MAX_PKT_SIZE, | ||
1878 | UDC_EP_MAX_PKT_SIZE); | ||
1879 | else if (dev->gadget.speed == USB_SPEED_HIGH) | ||
1880 | tmp = AMD_ADDBITS(tmp, UDC_EP0OUT_MAX_PKT_SIZE, | ||
1881 | UDC_EP_MAX_PKT_SIZE); | ||
1882 | writel(tmp, &dev->ep[UDC_EP0OUT_IX].regs->bufout_maxpkt); | ||
1883 | |||
1884 | /* set max packet size of EP0 in UDC CSR */ | ||
1885 | tmp = readl(&dev->csr->ne[0]); | ||
1886 | if (dev->gadget.speed == USB_SPEED_FULL) | ||
1887 | tmp = AMD_ADDBITS(tmp, UDC_FS_EP0OUT_MAX_PKT_SIZE, | ||
1888 | UDC_CSR_NE_MAX_PKT); | ||
1889 | else if (dev->gadget.speed == USB_SPEED_HIGH) | ||
1890 | tmp = AMD_ADDBITS(tmp, UDC_EP0OUT_MAX_PKT_SIZE, | ||
1891 | UDC_CSR_NE_MAX_PKT); | ||
1892 | writel(tmp, &dev->csr->ne[0]); | ||
1893 | |||
1894 | if (use_dma) { | ||
1895 | dev->ep[UDC_EP0OUT_IX].td->status |= | ||
1896 | AMD_BIT(UDC_DMA_OUT_STS_L); | ||
1897 | /* write dma desc address */ | ||
1898 | writel(dev->ep[UDC_EP0OUT_IX].td_stp_dma, | ||
1899 | &dev->ep[UDC_EP0OUT_IX].regs->subptr); | ||
1900 | writel(dev->ep[UDC_EP0OUT_IX].td_phys, | ||
1901 | &dev->ep[UDC_EP0OUT_IX].regs->desptr); | ||
1902 | /* stop RDE timer */ | ||
1903 | if (timer_pending(&udc_timer)) { | ||
1904 | set_rde = 0; | ||
1905 | mod_timer(&udc_timer, jiffies - 1); | ||
1906 | } | ||
1907 | /* stop pollstall timer */ | ||
1908 | if (timer_pending(&udc_pollstall_timer)) { | ||
1909 | mod_timer(&udc_pollstall_timer, jiffies - 1); | ||
1910 | } | ||
1911 | /* enable DMA */ | ||
1912 | tmp = readl(&dev->regs->ctl); | ||
1913 | tmp |= AMD_BIT(UDC_DEVCTL_MODE) | ||
1914 | | AMD_BIT(UDC_DEVCTL_RDE) | ||
1915 | | AMD_BIT(UDC_DEVCTL_TDE); | ||
1916 | if (use_dma_bufferfill_mode) { | ||
1917 | tmp |= AMD_BIT(UDC_DEVCTL_BF); | ||
1918 | } else if (use_dma_ppb_du) { | ||
1919 | tmp |= AMD_BIT(UDC_DEVCTL_DU); | ||
1920 | } | ||
1921 | writel(tmp, &dev->regs->ctl); | ||
1922 | } | ||
1923 | |||
1924 | /* clear NAK by writing CNAK for EP0IN */ | ||
1925 | tmp = readl(&dev->ep[UDC_EP0IN_IX].regs->ctl); | ||
1926 | tmp |= AMD_BIT(UDC_EPCTL_CNAK); | ||
1927 | writel(tmp, &dev->ep[UDC_EP0IN_IX].regs->ctl); | ||
1928 | dev->ep[UDC_EP0IN_IX].naking = 0; | ||
1929 | UDC_QUEUE_CNAK(&dev->ep[UDC_EP0IN_IX], UDC_EP0IN_IX); | ||
1930 | |||
1931 | /* clear NAK by writing CNAK for EP0OUT */ | ||
1932 | tmp = readl(&dev->ep[UDC_EP0OUT_IX].regs->ctl); | ||
1933 | tmp |= AMD_BIT(UDC_EPCTL_CNAK); | ||
1934 | writel(tmp, &dev->ep[UDC_EP0OUT_IX].regs->ctl); | ||
1935 | dev->ep[UDC_EP0OUT_IX].naking = 0; | ||
1936 | UDC_QUEUE_CNAK(&dev->ep[UDC_EP0OUT_IX], UDC_EP0OUT_IX); | ||
1937 | } | ||
1938 | |||
1939 | /* Make endpoint 0 ready for control traffic */ | ||
1940 | static int setup_ep0(struct udc *dev) | ||
1941 | { | ||
1942 | activate_control_endpoints(dev); | ||
1943 | /* enable ep0 interrupts */ | ||
1944 | udc_enable_ep0_interrupts(dev); | ||
1945 | /* enable device setup interrupts */ | ||
1946 | udc_enable_dev_setup_interrupts(dev); | ||
1947 | |||
1948 | return 0; | ||
1949 | } | ||
1950 | |||
1951 | /* Called by gadget driver to register itself */ | ||
1952 | int usb_gadget_register_driver(struct usb_gadget_driver *driver) | ||
1953 | { | ||
1954 | struct udc *dev = udc; | ||
1955 | int retval; | ||
1956 | u32 tmp; | ||
1957 | |||
1958 | if (!driver || !driver->bind || !driver->setup | ||
1959 | || driver->speed != USB_SPEED_HIGH) | ||
1960 | return -EINVAL; | ||
1961 | if (!dev) | ||
1962 | return -ENODEV; | ||
1963 | if (dev->driver) | ||
1964 | return -EBUSY; | ||
1965 | |||
1966 | driver->driver.bus = NULL; | ||
1967 | dev->driver = driver; | ||
1968 | dev->gadget.dev.driver = &driver->driver; | ||
1969 | |||
1970 | retval = driver->bind(&dev->gadget); | ||
1971 | |||
1972 | /* Some gadget drivers use both ep0 directions. | ||
1973 | * NOTE: to gadget driver, ep0 is just one endpoint... | ||
1974 | */ | ||
1975 | dev->ep[UDC_EP0OUT_IX].ep.driver_data = | ||
1976 | dev->ep[UDC_EP0IN_IX].ep.driver_data; | ||
1977 | |||
1978 | if (retval) { | ||
1979 | DBG(dev, "binding to %s returning %d\n", | ||
1980 | driver->driver.name, retval); | ||
1981 | dev->driver = NULL; | ||
1982 | dev->gadget.dev.driver = NULL; | ||
1983 | return retval; | ||
1984 | } | ||
1985 | |||
1986 | /* get ready for ep0 traffic */ | ||
1987 | setup_ep0(dev); | ||
1988 | |||
1989 | /* clear SD */ | ||
1990 | tmp = readl(&dev->regs->ctl); | ||
1991 | tmp = tmp & AMD_CLEAR_BIT(UDC_DEVCTL_SD); | ||
1992 | writel(tmp, &dev->regs->ctl); | ||
1993 | |||
1994 | usb_connect(dev); | ||
1995 | |||
1996 | return 0; | ||
1997 | } | ||
1998 | EXPORT_SYMBOL(usb_gadget_register_driver); | ||
1999 | |||
2000 | /* shutdown requests and disconnect from gadget */ | ||
2001 | static void | ||
2002 | shutdown(struct udc *dev, struct usb_gadget_driver *driver) | ||
2003 | __releases(dev->lock) | ||
2004 | __acquires(dev->lock) | ||
2005 | { | ||
2006 | int tmp; | ||
2007 | |||
2008 | /* empty queues and init hardware */ | ||
2009 | udc_basic_init(dev); | ||
2010 | for (tmp = 0; tmp < UDC_EP_NUM; tmp++) { | ||
2011 | empty_req_queue(&dev->ep[tmp]); | ||
2012 | } | ||
2013 | |||
2014 | if (dev->gadget.speed != USB_SPEED_UNKNOWN) { | ||
2015 | spin_unlock(&dev->lock); | ||
2016 | driver->disconnect(&dev->gadget); | ||
2017 | spin_lock(&dev->lock); | ||
2018 | } | ||
2019 | /* init */ | ||
2020 | udc_setup_endpoints(dev); | ||
2021 | } | ||
2022 | |||
2023 | /* Called by gadget driver to unregister itself */ | ||
2024 | int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | ||
2025 | { | ||
2026 | struct udc *dev = udc; | ||
2027 | unsigned long flags; | ||
2028 | u32 tmp; | ||
2029 | |||
2030 | if (!dev) | ||
2031 | return -ENODEV; | ||
2032 | if (!driver || driver != dev->driver || !driver->unbind) | ||
2033 | return -EINVAL; | ||
2034 | |||
2035 | spin_lock_irqsave(&dev->lock, flags); | ||
2036 | udc_mask_unused_interrupts(dev); | ||
2037 | shutdown(dev, driver); | ||
2038 | spin_unlock_irqrestore(&dev->lock, flags); | ||
2039 | |||
2040 | driver->unbind(&dev->gadget); | ||
2041 | dev->driver = NULL; | ||
2042 | |||
2043 | /* set SD */ | ||
2044 | tmp = readl(&dev->regs->ctl); | ||
2045 | tmp |= AMD_BIT(UDC_DEVCTL_SD); | ||
2046 | writel(tmp, &dev->regs->ctl); | ||
2047 | |||
2048 | |||
2049 | DBG(dev, "%s: unregistered\n", driver->driver.name); | ||
2050 | |||
2051 | return 0; | ||
2052 | } | ||
2053 | EXPORT_SYMBOL(usb_gadget_unregister_driver); | ||
2054 | |||
2055 | |||
2056 | /* Clear pending NAK bits */ | ||
2057 | static void udc_process_cnak_queue(struct udc *dev) | ||
2058 | { | ||
2059 | u32 tmp; | ||
2060 | u32 reg; | ||
2061 | |||
2062 | /* check epin's */ | ||
2063 | DBG(dev, "CNAK pending queue processing\n"); | ||
2064 | for (tmp = 0; tmp < UDC_EPIN_NUM_USED; tmp++) { | ||
2065 | if (cnak_pending & (1 << tmp)) { | ||
2066 | DBG(dev, "CNAK pending for ep%d\n", tmp); | ||
2067 | /* clear NAK by writing CNAK */ | ||
2068 | reg = readl(&dev->ep[tmp].regs->ctl); | ||
2069 | reg |= AMD_BIT(UDC_EPCTL_CNAK); | ||
2070 | writel(reg, &dev->ep[tmp].regs->ctl); | ||
2071 | dev->ep[tmp].naking = 0; | ||
2072 | UDC_QUEUE_CNAK(&dev->ep[tmp], dev->ep[tmp].num); | ||
2073 | } | ||
2074 | } | ||
2075 | /* ... and ep0out */ | ||
2076 | if (cnak_pending & (1 << UDC_EP0OUT_IX)) { | ||
2077 | DBG(dev, "CNAK pending for ep%d\n", UDC_EP0OUT_IX); | ||
2078 | /* clear NAK by writing CNAK */ | ||
2079 | reg = readl(&dev->ep[UDC_EP0OUT_IX].regs->ctl); | ||
2080 | reg |= AMD_BIT(UDC_EPCTL_CNAK); | ||
2081 | writel(reg, &dev->ep[UDC_EP0OUT_IX].regs->ctl); | ||
2082 | dev->ep[UDC_EP0OUT_IX].naking = 0; | ||
2083 | UDC_QUEUE_CNAK(&dev->ep[UDC_EP0OUT_IX], | ||
2084 | dev->ep[UDC_EP0OUT_IX].num); | ||
2085 | } | ||
2086 | } | ||
2087 | |||
2088 | /* Enabling RX DMA after setup packet */ | ||
2089 | static void udc_ep0_set_rde(struct udc *dev) | ||
2090 | { | ||
2091 | if (use_dma) { | ||
2092 | /* | ||
2093 | * only enable RXDMA when no data endpoint enabled | ||
2094 | * or data is queued | ||
2095 | */ | ||
2096 | if (!dev->data_ep_enabled || dev->data_ep_queued) { | ||
2097 | udc_set_rde(dev); | ||
2098 | } else { | ||
2099 | /* | ||
2100 | * setup timer for enabling RDE (to not enable | ||
2101 | * RXFIFO DMA for data endpoints to early) | ||
2102 | */ | ||
2103 | if (set_rde != 0 && !timer_pending(&udc_timer)) { | ||
2104 | udc_timer.expires = | ||
2105 | jiffies + HZ/UDC_RDE_TIMER_DIV; | ||
2106 | set_rde = 1; | ||
2107 | if (!stop_timer) { | ||
2108 | add_timer(&udc_timer); | ||
2109 | } | ||
2110 | } | ||
2111 | } | ||
2112 | } | ||
2113 | } | ||
2114 | |||
2115 | |||
2116 | /* Interrupt handler for data OUT traffic */ | ||
2117 | static irqreturn_t udc_data_out_isr(struct udc *dev, int ep_ix) | ||
2118 | { | ||
2119 | irqreturn_t ret_val = IRQ_NONE; | ||
2120 | u32 tmp; | ||
2121 | struct udc_ep *ep; | ||
2122 | struct udc_request *req; | ||
2123 | unsigned int count; | ||
2124 | struct udc_data_dma *td = NULL; | ||
2125 | unsigned dma_done; | ||
2126 | |||
2127 | VDBG(dev, "ep%d irq\n", ep_ix); | ||
2128 | ep = &dev->ep[ep_ix]; | ||
2129 | |||
2130 | tmp = readl(&ep->regs->sts); | ||
2131 | if (use_dma) { | ||
2132 | /* BNA event ? */ | ||
2133 | if (tmp & AMD_BIT(UDC_EPSTS_BNA)) { | ||
2134 | DBG(dev, "BNA ep%dout occured - DESPTR = %x \n", | ||
2135 | ep->num, readl(&ep->regs->desptr)); | ||
2136 | /* clear BNA */ | ||
2137 | writel(tmp | AMD_BIT(UDC_EPSTS_BNA), &ep->regs->sts); | ||
2138 | if (!ep->cancel_transfer) | ||
2139 | ep->bna_occurred = 1; | ||
2140 | else | ||
2141 | ep->cancel_transfer = 0; | ||
2142 | ret_val = IRQ_HANDLED; | ||
2143 | goto finished; | ||
2144 | } | ||
2145 | } | ||
2146 | /* HE event ? */ | ||
2147 | if (tmp & AMD_BIT(UDC_EPSTS_HE)) { | ||
2148 | dev_err(&dev->pdev->dev, "HE ep%dout occured\n", ep->num); | ||
2149 | |||
2150 | /* clear HE */ | ||
2151 | writel(tmp | AMD_BIT(UDC_EPSTS_HE), &ep->regs->sts); | ||
2152 | ret_val = IRQ_HANDLED; | ||
2153 | goto finished; | ||
2154 | } | ||
2155 | |||
2156 | if (!list_empty(&ep->queue)) { | ||
2157 | |||
2158 | /* next request */ | ||
2159 | req = list_entry(ep->queue.next, | ||
2160 | struct udc_request, queue); | ||
2161 | } else { | ||
2162 | req = NULL; | ||
2163 | udc_rxfifo_pending = 1; | ||
2164 | } | ||
2165 | VDBG(dev, "req = %p\n", req); | ||
2166 | /* fifo mode */ | ||
2167 | if (!use_dma) { | ||
2168 | |||
2169 | /* read fifo */ | ||
2170 | if (req && udc_rxfifo_read(ep, req)) { | ||
2171 | ret_val = IRQ_HANDLED; | ||
2172 | |||
2173 | /* finish */ | ||
2174 | complete_req(ep, req, 0); | ||
2175 | /* next request */ | ||
2176 | if (!list_empty(&ep->queue) && !ep->halted) { | ||
2177 | req = list_entry(ep->queue.next, | ||
2178 | struct udc_request, queue); | ||
2179 | } else | ||
2180 | req = NULL; | ||
2181 | } | ||
2182 | |||
2183 | /* DMA */ | ||
2184 | } else if (!ep->cancel_transfer && req != NULL) { | ||
2185 | ret_val = IRQ_HANDLED; | ||
2186 | |||
2187 | /* check for DMA done */ | ||
2188 | if (!use_dma_ppb) { | ||
2189 | dma_done = AMD_GETBITS(req->td_data->status, | ||
2190 | UDC_DMA_OUT_STS_BS); | ||
2191 | /* packet per buffer mode - rx bytes */ | ||
2192 | } else { | ||
2193 | /* | ||
2194 | * if BNA occurred then recover desc. from | ||
2195 | * BNA dummy desc. | ||
2196 | */ | ||
2197 | if (ep->bna_occurred) { | ||
2198 | VDBG(dev, "Recover desc. from BNA dummy\n"); | ||
2199 | memcpy(req->td_data, ep->bna_dummy_req->td_data, | ||
2200 | sizeof(struct udc_data_dma)); | ||
2201 | ep->bna_occurred = 0; | ||
2202 | udc_init_bna_dummy(ep->req); | ||
2203 | } | ||
2204 | td = udc_get_last_dma_desc(req); | ||
2205 | dma_done = AMD_GETBITS(td->status, UDC_DMA_OUT_STS_BS); | ||
2206 | } | ||
2207 | if (dma_done == UDC_DMA_OUT_STS_BS_DMA_DONE) { | ||
2208 | /* buffer fill mode - rx bytes */ | ||
2209 | if (!use_dma_ppb) { | ||
2210 | /* received number bytes */ | ||
2211 | count = AMD_GETBITS(req->td_data->status, | ||
2212 | UDC_DMA_OUT_STS_RXBYTES); | ||
2213 | VDBG(dev, "rx bytes=%u\n", count); | ||
2214 | /* packet per buffer mode - rx bytes */ | ||
2215 | } else { | ||
2216 | VDBG(dev, "req->td_data=%p\n", req->td_data); | ||
2217 | VDBG(dev, "last desc = %p\n", td); | ||
2218 | /* received number bytes */ | ||
2219 | if (use_dma_ppb_du) { | ||
2220 | /* every desc. counts bytes */ | ||
2221 | count = udc_get_ppbdu_rxbytes(req); | ||
2222 | } else { | ||
2223 | /* last desc. counts bytes */ | ||
2224 | count = AMD_GETBITS(td->status, | ||
2225 | UDC_DMA_OUT_STS_RXBYTES); | ||
2226 | if (!count && req->req.length | ||
2227 | == UDC_DMA_MAXPACKET) { | ||
2228 | /* | ||
2229 | * on 64k packets the RXBYTES | ||
2230 | * field is zero | ||
2231 | */ | ||
2232 | count = UDC_DMA_MAXPACKET; | ||
2233 | } | ||
2234 | } | ||
2235 | VDBG(dev, "last desc rx bytes=%u\n", count); | ||
2236 | } | ||
2237 | |||
2238 | tmp = req->req.length - req->req.actual; | ||
2239 | if (count > tmp) { | ||
2240 | if ((tmp % ep->ep.maxpacket) != 0) { | ||
2241 | DBG(dev, "%s: rx %db, space=%db\n", | ||
2242 | ep->ep.name, count, tmp); | ||
2243 | req->req.status = -EOVERFLOW; | ||
2244 | } | ||
2245 | count = tmp; | ||
2246 | } | ||
2247 | req->req.actual += count; | ||
2248 | req->dma_going = 0; | ||
2249 | /* complete request */ | ||
2250 | complete_req(ep, req, 0); | ||
2251 | |||
2252 | /* next request */ | ||
2253 | if (!list_empty(&ep->queue) && !ep->halted) { | ||
2254 | req = list_entry(ep->queue.next, | ||
2255 | struct udc_request, | ||
2256 | queue); | ||
2257 | /* | ||
2258 | * DMA may be already started by udc_queue() | ||
2259 | * called by gadget drivers completion | ||
2260 | * routine. This happens when queue | ||
2261 | * holds one request only. | ||
2262 | */ | ||
2263 | if (req->dma_going == 0) { | ||
2264 | /* next dma */ | ||
2265 | if (prep_dma(ep, req, GFP_ATOMIC) != 0) | ||
2266 | goto finished; | ||
2267 | /* write desc pointer */ | ||
2268 | writel(req->td_phys, | ||
2269 | &ep->regs->desptr); | ||
2270 | req->dma_going = 1; | ||
2271 | /* enable DMA */ | ||
2272 | udc_set_rde(dev); | ||
2273 | } | ||
2274 | } else { | ||
2275 | /* | ||
2276 | * implant BNA dummy descriptor to allow | ||
2277 | * RXFIFO opening by RDE | ||
2278 | */ | ||
2279 | if (ep->bna_dummy_req) { | ||
2280 | /* write desc pointer */ | ||
2281 | writel(ep->bna_dummy_req->td_phys, | ||
2282 | &ep->regs->desptr); | ||
2283 | ep->bna_occurred = 0; | ||
2284 | } | ||
2285 | |||
2286 | /* | ||
2287 | * schedule timer for setting RDE if queue | ||
2288 | * remains empty to allow ep0 packets pass | ||
2289 | * through | ||
2290 | */ | ||
2291 | if (set_rde != 0 | ||
2292 | && !timer_pending(&udc_timer)) { | ||
2293 | udc_timer.expires = | ||
2294 | jiffies | ||
2295 | + HZ*UDC_RDE_TIMER_SECONDS; | ||
2296 | set_rde = 1; | ||
2297 | if (!stop_timer) { | ||
2298 | add_timer(&udc_timer); | ||
2299 | } | ||
2300 | } | ||
2301 | if (ep->num != UDC_EP0OUT_IX) | ||
2302 | dev->data_ep_queued = 0; | ||
2303 | } | ||
2304 | |||
2305 | } else { | ||
2306 | /* | ||
2307 | * RX DMA must be reenabled for each desc in PPBDU mode | ||
2308 | * and must be enabled for PPBNDU mode in case of BNA | ||
2309 | */ | ||
2310 | udc_set_rde(dev); | ||
2311 | } | ||
2312 | |||
2313 | } else if (ep->cancel_transfer) { | ||
2314 | ret_val = IRQ_HANDLED; | ||
2315 | ep->cancel_transfer = 0; | ||
2316 | } | ||
2317 | |||
2318 | /* check pending CNAKS */ | ||
2319 | if (cnak_pending) { | ||
2320 | /* CNAk processing when rxfifo empty only */ | ||
2321 | if (readl(&dev->regs->sts) & AMD_BIT(UDC_DEVSTS_RXFIFO_EMPTY)) { | ||
2322 | udc_process_cnak_queue(dev); | ||
2323 | } | ||
2324 | } | ||
2325 | |||
2326 | /* clear OUT bits in ep status */ | ||
2327 | writel(UDC_EPSTS_OUT_CLEAR, &ep->regs->sts); | ||
2328 | finished: | ||
2329 | return ret_val; | ||
2330 | } | ||
2331 | |||
2332 | /* Interrupt handler for data IN traffic */ | ||
2333 | static irqreturn_t udc_data_in_isr(struct udc *dev, int ep_ix) | ||
2334 | { | ||
2335 | irqreturn_t ret_val = IRQ_NONE; | ||
2336 | u32 tmp; | ||
2337 | u32 epsts; | ||
2338 | struct udc_ep *ep; | ||
2339 | struct udc_request *req; | ||
2340 | struct udc_data_dma *td; | ||
2341 | unsigned dma_done; | ||
2342 | unsigned len; | ||
2343 | |||
2344 | ep = &dev->ep[ep_ix]; | ||
2345 | |||
2346 | epsts = readl(&ep->regs->sts); | ||
2347 | if (use_dma) { | ||
2348 | /* BNA ? */ | ||
2349 | if (epsts & AMD_BIT(UDC_EPSTS_BNA)) { | ||
2350 | dev_err(&dev->pdev->dev, | ||
2351 | "BNA ep%din occured - DESPTR = %08lx \n", | ||
2352 | ep->num, | ||
2353 | (unsigned long) readl(&ep->regs->desptr)); | ||
2354 | |||
2355 | /* clear BNA */ | ||
2356 | writel(epsts, &ep->regs->sts); | ||
2357 | ret_val = IRQ_HANDLED; | ||
2358 | goto finished; | ||
2359 | } | ||
2360 | } | ||
2361 | /* HE event ? */ | ||
2362 | if (epsts & AMD_BIT(UDC_EPSTS_HE)) { | ||
2363 | dev_err(&dev->pdev->dev, | ||
2364 | "HE ep%dn occured - DESPTR = %08lx \n", | ||
2365 | ep->num, (unsigned long) readl(&ep->regs->desptr)); | ||
2366 | |||
2367 | /* clear HE */ | ||
2368 | writel(epsts | AMD_BIT(UDC_EPSTS_HE), &ep->regs->sts); | ||
2369 | ret_val = IRQ_HANDLED; | ||
2370 | goto finished; | ||
2371 | } | ||
2372 | |||
2373 | /* DMA completion */ | ||
2374 | if (epsts & AMD_BIT(UDC_EPSTS_TDC)) { | ||
2375 | VDBG(dev, "TDC set- completion\n"); | ||
2376 | ret_val = IRQ_HANDLED; | ||
2377 | if (!ep->cancel_transfer && !list_empty(&ep->queue)) { | ||
2378 | req = list_entry(ep->queue.next, | ||
2379 | struct udc_request, queue); | ||
2380 | if (req) { | ||
2381 | /* | ||
2382 | * length bytes transfered | ||
2383 | * check dma done of last desc. in PPBDU mode | ||
2384 | */ | ||
2385 | if (use_dma_ppb_du) { | ||
2386 | td = udc_get_last_dma_desc(req); | ||
2387 | if (td) { | ||
2388 | dma_done = | ||
2389 | AMD_GETBITS(td->status, | ||
2390 | UDC_DMA_IN_STS_BS); | ||
2391 | /* don't care DMA done */ | ||
2392 | req->req.actual = | ||
2393 | req->req.length; | ||
2394 | } | ||
2395 | } else { | ||
2396 | /* assume all bytes transferred */ | ||
2397 | req->req.actual = req->req.length; | ||
2398 | } | ||
2399 | |||
2400 | if (req->req.actual == req->req.length) { | ||
2401 | /* complete req */ | ||
2402 | complete_req(ep, req, 0); | ||
2403 | req->dma_going = 0; | ||
2404 | /* further request available ? */ | ||
2405 | if (list_empty(&ep->queue)) { | ||
2406 | /* disable interrupt */ | ||
2407 | tmp = readl( | ||
2408 | &dev->regs->ep_irqmsk); | ||
2409 | tmp |= AMD_BIT(ep->num); | ||
2410 | writel(tmp, | ||
2411 | &dev->regs->ep_irqmsk); | ||
2412 | } | ||
2413 | |||
2414 | } | ||
2415 | } | ||
2416 | } | ||
2417 | ep->cancel_transfer = 0; | ||
2418 | |||
2419 | } | ||
2420 | /* | ||
2421 | * status reg has IN bit set and TDC not set (if TDC was handled, | ||
2422 | * IN must not be handled (UDC defect) ? | ||
2423 | */ | ||
2424 | if ((epsts & AMD_BIT(UDC_EPSTS_IN)) | ||
2425 | && !(epsts & AMD_BIT(UDC_EPSTS_TDC))) { | ||
2426 | ret_val = IRQ_HANDLED; | ||
2427 | if (!list_empty(&ep->queue)) { | ||
2428 | /* next request */ | ||
2429 | req = list_entry(ep->queue.next, | ||
2430 | struct udc_request, queue); | ||
2431 | /* FIFO mode */ | ||
2432 | if (!use_dma) { | ||
2433 | /* write fifo */ | ||
2434 | udc_txfifo_write(ep, &req->req); | ||
2435 | len = req->req.length - req->req.actual; | ||
2436 | if (len > ep->ep.maxpacket) | ||
2437 | len = ep->ep.maxpacket; | ||
2438 | req->req.actual += len; | ||
2439 | if (req->req.actual == req->req.length | ||
2440 | || (len != ep->ep.maxpacket)) { | ||
2441 | /* complete req */ | ||
2442 | complete_req(ep, req, 0); | ||
2443 | } | ||
2444 | /* DMA */ | ||
2445 | } else if (req && !req->dma_going) { | ||
2446 | VDBG(dev, "IN DMA : req=%p req->td_data=%p\n", | ||
2447 | req, req->td_data); | ||
2448 | if (req->td_data) { | ||
2449 | |||
2450 | req->dma_going = 1; | ||
2451 | |||
2452 | /* | ||
2453 | * unset L bit of first desc. | ||
2454 | * for chain | ||
2455 | */ | ||
2456 | if (use_dma_ppb && req->req.length > | ||
2457 | ep->ep.maxpacket) { | ||
2458 | req->td_data->status &= | ||
2459 | AMD_CLEAR_BIT( | ||
2460 | UDC_DMA_IN_STS_L); | ||
2461 | } | ||
2462 | |||
2463 | /* write desc pointer */ | ||
2464 | writel(req->td_phys, &ep->regs->desptr); | ||
2465 | |||
2466 | /* set HOST READY */ | ||
2467 | req->td_data->status = | ||
2468 | AMD_ADDBITS( | ||
2469 | req->td_data->status, | ||
2470 | UDC_DMA_IN_STS_BS_HOST_READY, | ||
2471 | UDC_DMA_IN_STS_BS); | ||
2472 | |||
2473 | /* set poll demand bit */ | ||
2474 | tmp = readl(&ep->regs->ctl); | ||
2475 | tmp |= AMD_BIT(UDC_EPCTL_P); | ||
2476 | writel(tmp, &ep->regs->ctl); | ||
2477 | } | ||
2478 | } | ||
2479 | |||
2480 | } | ||
2481 | } | ||
2482 | /* clear status bits */ | ||
2483 | writel(epsts, &ep->regs->sts); | ||
2484 | |||
2485 | finished: | ||
2486 | return ret_val; | ||
2487 | |||
2488 | } | ||
2489 | |||
2490 | /* Interrupt handler for Control OUT traffic */ | ||
2491 | static irqreturn_t udc_control_out_isr(struct udc *dev) | ||
2492 | __releases(dev->lock) | ||
2493 | __acquires(dev->lock) | ||
2494 | { | ||
2495 | irqreturn_t ret_val = IRQ_NONE; | ||
2496 | u32 tmp; | ||
2497 | int setup_supported; | ||
2498 | u32 count; | ||
2499 | int set = 0; | ||
2500 | struct udc_ep *ep; | ||
2501 | struct udc_ep *ep_tmp; | ||
2502 | |||
2503 | ep = &dev->ep[UDC_EP0OUT_IX]; | ||
2504 | |||
2505 | /* clear irq */ | ||
2506 | writel(AMD_BIT(UDC_EPINT_OUT_EP0), &dev->regs->ep_irqsts); | ||
2507 | |||
2508 | tmp = readl(&dev->ep[UDC_EP0OUT_IX].regs->sts); | ||
2509 | /* check BNA and clear if set */ | ||
2510 | if (tmp & AMD_BIT(UDC_EPSTS_BNA)) { | ||
2511 | VDBG(dev, "ep0: BNA set\n"); | ||
2512 | writel(AMD_BIT(UDC_EPSTS_BNA), | ||
2513 | &dev->ep[UDC_EP0OUT_IX].regs->sts); | ||
2514 | ep->bna_occurred = 1; | ||
2515 | ret_val = IRQ_HANDLED; | ||
2516 | goto finished; | ||
2517 | } | ||
2518 | |||
2519 | /* type of data: SETUP or DATA 0 bytes */ | ||
2520 | tmp = AMD_GETBITS(tmp, UDC_EPSTS_OUT); | ||
2521 | VDBG(dev, "data_typ = %x\n", tmp); | ||
2522 | |||
2523 | /* setup data */ | ||
2524 | if (tmp == UDC_EPSTS_OUT_SETUP) { | ||
2525 | ret_val = IRQ_HANDLED; | ||
2526 | |||
2527 | ep->dev->stall_ep0in = 0; | ||
2528 | dev->waiting_zlp_ack_ep0in = 0; | ||
2529 | |||
2530 | /* set NAK for EP0_IN */ | ||
2531 | tmp = readl(&dev->ep[UDC_EP0IN_IX].regs->ctl); | ||
2532 | tmp |= AMD_BIT(UDC_EPCTL_SNAK); | ||
2533 | writel(tmp, &dev->ep[UDC_EP0IN_IX].regs->ctl); | ||
2534 | dev->ep[UDC_EP0IN_IX].naking = 1; | ||
2535 | /* get setup data */ | ||
2536 | if (use_dma) { | ||
2537 | |||
2538 | /* clear OUT bits in ep status */ | ||
2539 | writel(UDC_EPSTS_OUT_CLEAR, | ||
2540 | &dev->ep[UDC_EP0OUT_IX].regs->sts); | ||
2541 | |||
2542 | setup_data.data[0] = | ||
2543 | dev->ep[UDC_EP0OUT_IX].td_stp->data12; | ||
2544 | setup_data.data[1] = | ||
2545 | dev->ep[UDC_EP0OUT_IX].td_stp->data34; | ||
2546 | /* set HOST READY */ | ||
2547 | dev->ep[UDC_EP0OUT_IX].td_stp->status = | ||
2548 | UDC_DMA_STP_STS_BS_HOST_READY; | ||
2549 | } else { | ||
2550 | /* read fifo */ | ||
2551 | udc_rxfifo_read_dwords(dev, setup_data.data, 2); | ||
2552 | } | ||
2553 | |||
2554 | /* determine direction of control data */ | ||
2555 | if ((setup_data.request.bRequestType & USB_DIR_IN) != 0) { | ||
2556 | dev->gadget.ep0 = &dev->ep[UDC_EP0IN_IX].ep; | ||
2557 | /* enable RDE */ | ||
2558 | udc_ep0_set_rde(dev); | ||
2559 | set = 0; | ||
2560 | } else { | ||
2561 | dev->gadget.ep0 = &dev->ep[UDC_EP0OUT_IX].ep; | ||
2562 | /* | ||
2563 | * implant BNA dummy descriptor to allow RXFIFO opening | ||
2564 | * by RDE | ||
2565 | */ | ||
2566 | if (ep->bna_dummy_req) { | ||
2567 | /* write desc pointer */ | ||
2568 | writel(ep->bna_dummy_req->td_phys, | ||
2569 | &dev->ep[UDC_EP0OUT_IX].regs->desptr); | ||
2570 | ep->bna_occurred = 0; | ||
2571 | } | ||
2572 | |||
2573 | set = 1; | ||
2574 | dev->ep[UDC_EP0OUT_IX].naking = 1; | ||
2575 | /* | ||
2576 | * setup timer for enabling RDE (to not enable | ||
2577 | * RXFIFO DMA for data to early) | ||
2578 | */ | ||
2579 | set_rde = 1; | ||
2580 | if (!timer_pending(&udc_timer)) { | ||
2581 | udc_timer.expires = jiffies + | ||
2582 | HZ/UDC_RDE_TIMER_DIV; | ||
2583 | if (!stop_timer) { | ||
2584 | add_timer(&udc_timer); | ||
2585 | } | ||
2586 | } | ||
2587 | } | ||
2588 | |||
2589 | /* | ||
2590 | * mass storage reset must be processed here because | ||
2591 | * next packet may be a CLEAR_FEATURE HALT which would not | ||
2592 | * clear the stall bit when no STALL handshake was received | ||
2593 | * before (autostall can cause this) | ||
2594 | */ | ||
2595 | if (setup_data.data[0] == UDC_MSCRES_DWORD0 | ||
2596 | && setup_data.data[1] == UDC_MSCRES_DWORD1) { | ||
2597 | DBG(dev, "MSC Reset\n"); | ||
2598 | /* | ||
2599 | * clear stall bits | ||
2600 | * only one IN and OUT endpoints are handled | ||
2601 | */ | ||
2602 | ep_tmp = &udc->ep[UDC_EPIN_IX]; | ||
2603 | udc_set_halt(&ep_tmp->ep, 0); | ||
2604 | ep_tmp = &udc->ep[UDC_EPOUT_IX]; | ||
2605 | udc_set_halt(&ep_tmp->ep, 0); | ||
2606 | } | ||
2607 | |||
2608 | /* call gadget with setup data received */ | ||
2609 | spin_unlock(&dev->lock); | ||
2610 | setup_supported = dev->driver->setup(&dev->gadget, | ||
2611 | &setup_data.request); | ||
2612 | spin_lock(&dev->lock); | ||
2613 | |||
2614 | tmp = readl(&dev->ep[UDC_EP0IN_IX].regs->ctl); | ||
2615 | /* ep0 in returns data (not zlp) on IN phase */ | ||
2616 | if (setup_supported >= 0 && setup_supported < | ||
2617 | UDC_EP0IN_MAXPACKET) { | ||
2618 | /* clear NAK by writing CNAK in EP0_IN */ | ||
2619 | tmp |= AMD_BIT(UDC_EPCTL_CNAK); | ||
2620 | writel(tmp, &dev->ep[UDC_EP0IN_IX].regs->ctl); | ||
2621 | dev->ep[UDC_EP0IN_IX].naking = 0; | ||
2622 | UDC_QUEUE_CNAK(&dev->ep[UDC_EP0IN_IX], UDC_EP0IN_IX); | ||
2623 | |||
2624 | /* if unsupported request then stall */ | ||
2625 | } else if (setup_supported < 0) { | ||
2626 | tmp |= AMD_BIT(UDC_EPCTL_S); | ||
2627 | writel(tmp, &dev->ep[UDC_EP0IN_IX].regs->ctl); | ||
2628 | } else | ||
2629 | dev->waiting_zlp_ack_ep0in = 1; | ||
2630 | |||
2631 | |||
2632 | /* clear NAK by writing CNAK in EP0_OUT */ | ||
2633 | if (!set) { | ||
2634 | tmp = readl(&dev->ep[UDC_EP0OUT_IX].regs->ctl); | ||
2635 | tmp |= AMD_BIT(UDC_EPCTL_CNAK); | ||
2636 | writel(tmp, &dev->ep[UDC_EP0OUT_IX].regs->ctl); | ||
2637 | dev->ep[UDC_EP0OUT_IX].naking = 0; | ||
2638 | UDC_QUEUE_CNAK(&dev->ep[UDC_EP0OUT_IX], UDC_EP0OUT_IX); | ||
2639 | } | ||
2640 | |||
2641 | if (!use_dma) { | ||
2642 | /* clear OUT bits in ep status */ | ||
2643 | writel(UDC_EPSTS_OUT_CLEAR, | ||
2644 | &dev->ep[UDC_EP0OUT_IX].regs->sts); | ||
2645 | } | ||
2646 | |||
2647 | /* data packet 0 bytes */ | ||
2648 | } else if (tmp == UDC_EPSTS_OUT_DATA) { | ||
2649 | /* clear OUT bits in ep status */ | ||
2650 | writel(UDC_EPSTS_OUT_CLEAR, &dev->ep[UDC_EP0OUT_IX].regs->sts); | ||
2651 | |||
2652 | /* get setup data: only 0 packet */ | ||
2653 | if (use_dma) { | ||
2654 | /* no req if 0 packet, just reactivate */ | ||
2655 | if (list_empty(&dev->ep[UDC_EP0OUT_IX].queue)) { | ||
2656 | VDBG(dev, "ZLP\n"); | ||
2657 | |||
2658 | /* set HOST READY */ | ||
2659 | dev->ep[UDC_EP0OUT_IX].td->status = | ||
2660 | AMD_ADDBITS( | ||
2661 | dev->ep[UDC_EP0OUT_IX].td->status, | ||
2662 | UDC_DMA_OUT_STS_BS_HOST_READY, | ||
2663 | UDC_DMA_OUT_STS_BS); | ||
2664 | /* enable RDE */ | ||
2665 | udc_ep0_set_rde(dev); | ||
2666 | ret_val = IRQ_HANDLED; | ||
2667 | |||
2668 | } else { | ||
2669 | /* control write */ | ||
2670 | ret_val |= udc_data_out_isr(dev, UDC_EP0OUT_IX); | ||
2671 | /* re-program desc. pointer for possible ZLPs */ | ||
2672 | writel(dev->ep[UDC_EP0OUT_IX].td_phys, | ||
2673 | &dev->ep[UDC_EP0OUT_IX].regs->desptr); | ||
2674 | /* enable RDE */ | ||
2675 | udc_ep0_set_rde(dev); | ||
2676 | } | ||
2677 | } else { | ||
2678 | |||
2679 | /* received number bytes */ | ||
2680 | count = readl(&dev->ep[UDC_EP0OUT_IX].regs->sts); | ||
2681 | count = AMD_GETBITS(count, UDC_EPSTS_RX_PKT_SIZE); | ||
2682 | /* out data for fifo mode not working */ | ||
2683 | count = 0; | ||
2684 | |||
2685 | /* 0 packet or real data ? */ | ||
2686 | if (count != 0) { | ||
2687 | ret_val |= udc_data_out_isr(dev, UDC_EP0OUT_IX); | ||
2688 | } else { | ||
2689 | /* dummy read confirm */ | ||
2690 | readl(&dev->ep[UDC_EP0OUT_IX].regs->confirm); | ||
2691 | ret_val = IRQ_HANDLED; | ||
2692 | } | ||
2693 | } | ||
2694 | } | ||
2695 | |||
2696 | /* check pending CNAKS */ | ||
2697 | if (cnak_pending) { | ||
2698 | /* CNAk processing when rxfifo empty only */ | ||
2699 | if (readl(&dev->regs->sts) & AMD_BIT(UDC_DEVSTS_RXFIFO_EMPTY)) { | ||
2700 | udc_process_cnak_queue(dev); | ||
2701 | } | ||
2702 | } | ||
2703 | |||
2704 | finished: | ||
2705 | return ret_val; | ||
2706 | } | ||
2707 | |||
2708 | /* Interrupt handler for Control IN traffic */ | ||
2709 | static irqreturn_t udc_control_in_isr(struct udc *dev) | ||
2710 | { | ||
2711 | irqreturn_t ret_val = IRQ_NONE; | ||
2712 | u32 tmp; | ||
2713 | struct udc_ep *ep; | ||
2714 | struct udc_request *req; | ||
2715 | unsigned len; | ||
2716 | |||
2717 | ep = &dev->ep[UDC_EP0IN_IX]; | ||
2718 | |||
2719 | /* clear irq */ | ||
2720 | writel(AMD_BIT(UDC_EPINT_IN_EP0), &dev->regs->ep_irqsts); | ||
2721 | |||
2722 | tmp = readl(&dev->ep[UDC_EP0IN_IX].regs->sts); | ||
2723 | /* DMA completion */ | ||
2724 | if (tmp & AMD_BIT(UDC_EPSTS_TDC)) { | ||
2725 | VDBG(dev, "isr: TDC clear \n"); | ||
2726 | ret_val = IRQ_HANDLED; | ||
2727 | |||
2728 | /* clear TDC bit */ | ||
2729 | writel(AMD_BIT(UDC_EPSTS_TDC), | ||
2730 | &dev->ep[UDC_EP0IN_IX].regs->sts); | ||
2731 | |||
2732 | /* status reg has IN bit set ? */ | ||
2733 | } else if (tmp & AMD_BIT(UDC_EPSTS_IN)) { | ||
2734 | ret_val = IRQ_HANDLED; | ||
2735 | |||
2736 | if (ep->dma) { | ||
2737 | /* clear IN bit */ | ||
2738 | writel(AMD_BIT(UDC_EPSTS_IN), | ||
2739 | &dev->ep[UDC_EP0IN_IX].regs->sts); | ||
2740 | } | ||
2741 | if (dev->stall_ep0in) { | ||
2742 | DBG(dev, "stall ep0in\n"); | ||
2743 | /* halt ep0in */ | ||
2744 | tmp = readl(&ep->regs->ctl); | ||
2745 | tmp |= AMD_BIT(UDC_EPCTL_S); | ||
2746 | writel(tmp, &ep->regs->ctl); | ||
2747 | } else { | ||
2748 | if (!list_empty(&ep->queue)) { | ||
2749 | /* next request */ | ||
2750 | req = list_entry(ep->queue.next, | ||
2751 | struct udc_request, queue); | ||
2752 | |||
2753 | if (ep->dma) { | ||
2754 | /* write desc pointer */ | ||
2755 | writel(req->td_phys, &ep->regs->desptr); | ||
2756 | /* set HOST READY */ | ||
2757 | req->td_data->status = | ||
2758 | AMD_ADDBITS( | ||
2759 | req->td_data->status, | ||
2760 | UDC_DMA_STP_STS_BS_HOST_READY, | ||
2761 | UDC_DMA_STP_STS_BS); | ||
2762 | |||
2763 | /* set poll demand bit */ | ||
2764 | tmp = | ||
2765 | readl(&dev->ep[UDC_EP0IN_IX].regs->ctl); | ||
2766 | tmp |= AMD_BIT(UDC_EPCTL_P); | ||
2767 | writel(tmp, | ||
2768 | &dev->ep[UDC_EP0IN_IX].regs->ctl); | ||
2769 | |||
2770 | /* all bytes will be transferred */ | ||
2771 | req->req.actual = req->req.length; | ||
2772 | |||
2773 | /* complete req */ | ||
2774 | complete_req(ep, req, 0); | ||
2775 | |||
2776 | } else { | ||
2777 | /* write fifo */ | ||
2778 | udc_txfifo_write(ep, &req->req); | ||
2779 | |||
2780 | /* lengh bytes transfered */ | ||
2781 | len = req->req.length - req->req.actual; | ||
2782 | if (len > ep->ep.maxpacket) | ||
2783 | len = ep->ep.maxpacket; | ||
2784 | |||
2785 | req->req.actual += len; | ||
2786 | if (req->req.actual == req->req.length | ||
2787 | || (len != ep->ep.maxpacket)) { | ||
2788 | /* complete req */ | ||
2789 | complete_req(ep, req, 0); | ||
2790 | } | ||
2791 | } | ||
2792 | |||
2793 | } | ||
2794 | } | ||
2795 | ep->halted = 0; | ||
2796 | dev->stall_ep0in = 0; | ||
2797 | if (!ep->dma) { | ||
2798 | /* clear IN bit */ | ||
2799 | writel(AMD_BIT(UDC_EPSTS_IN), | ||
2800 | &dev->ep[UDC_EP0IN_IX].regs->sts); | ||
2801 | } | ||
2802 | } | ||
2803 | |||
2804 | return ret_val; | ||
2805 | } | ||
2806 | |||
2807 | |||
2808 | /* Interrupt handler for global device events */ | ||
2809 | static irqreturn_t udc_dev_isr(struct udc *dev, u32 dev_irq) | ||
2810 | __releases(dev->lock) | ||
2811 | __acquires(dev->lock) | ||
2812 | { | ||
2813 | irqreturn_t ret_val = IRQ_NONE; | ||
2814 | u32 tmp; | ||
2815 | u32 cfg; | ||
2816 | struct udc_ep *ep; | ||
2817 | u16 i; | ||
2818 | u8 udc_csr_epix; | ||
2819 | |||
2820 | /* SET_CONFIG irq ? */ | ||
2821 | if (dev_irq & AMD_BIT(UDC_DEVINT_SC)) { | ||
2822 | ret_val = IRQ_HANDLED; | ||
2823 | |||
2824 | /* read config value */ | ||
2825 | tmp = readl(&dev->regs->sts); | ||
2826 | cfg = AMD_GETBITS(tmp, UDC_DEVSTS_CFG); | ||
2827 | DBG(dev, "SET_CONFIG interrupt: config=%d\n", cfg); | ||
2828 | dev->cur_config = cfg; | ||
2829 | dev->set_cfg_not_acked = 1; | ||
2830 | |||
2831 | /* make usb request for gadget driver */ | ||
2832 | memset(&setup_data, 0 , sizeof(union udc_setup_data)); | ||
2833 | setup_data.request.bRequest = USB_REQ_SET_CONFIGURATION; | ||
2834 | setup_data.request.wValue = dev->cur_config; | ||
2835 | |||
2836 | /* programm the NE registers */ | ||
2837 | for (i = 0; i < UDC_EP_NUM; i++) { | ||
2838 | ep = &dev->ep[i]; | ||
2839 | if (ep->in) { | ||
2840 | |||
2841 | /* ep ix in UDC CSR register space */ | ||
2842 | udc_csr_epix = ep->num; | ||
2843 | |||
2844 | |||
2845 | /* OUT ep */ | ||
2846 | } else { | ||
2847 | /* ep ix in UDC CSR register space */ | ||
2848 | udc_csr_epix = ep->num - UDC_CSR_EP_OUT_IX_OFS; | ||
2849 | } | ||
2850 | |||
2851 | tmp = readl(&dev->csr->ne[udc_csr_epix]); | ||
2852 | /* ep cfg */ | ||
2853 | tmp = AMD_ADDBITS(tmp, ep->dev->cur_config, | ||
2854 | UDC_CSR_NE_CFG); | ||
2855 | /* write reg */ | ||
2856 | writel(tmp, &dev->csr->ne[udc_csr_epix]); | ||
2857 | |||
2858 | /* clear stall bits */ | ||
2859 | ep->halted = 0; | ||
2860 | tmp = readl(&ep->regs->ctl); | ||
2861 | tmp = tmp & AMD_CLEAR_BIT(UDC_EPCTL_S); | ||
2862 | writel(tmp, &ep->regs->ctl); | ||
2863 | } | ||
2864 | /* call gadget zero with setup data received */ | ||
2865 | spin_unlock(&dev->lock); | ||
2866 | tmp = dev->driver->setup(&dev->gadget, &setup_data.request); | ||
2867 | spin_lock(&dev->lock); | ||
2868 | |||
2869 | } /* SET_INTERFACE ? */ | ||
2870 | if (dev_irq & AMD_BIT(UDC_DEVINT_SI)) { | ||
2871 | ret_val = IRQ_HANDLED; | ||
2872 | |||
2873 | dev->set_cfg_not_acked = 1; | ||
2874 | /* read interface and alt setting values */ | ||
2875 | tmp = readl(&dev->regs->sts); | ||
2876 | dev->cur_alt = AMD_GETBITS(tmp, UDC_DEVSTS_ALT); | ||
2877 | dev->cur_intf = AMD_GETBITS(tmp, UDC_DEVSTS_INTF); | ||
2878 | |||
2879 | /* make usb request for gadget driver */ | ||
2880 | memset(&setup_data, 0 , sizeof(union udc_setup_data)); | ||
2881 | setup_data.request.bRequest = USB_REQ_SET_INTERFACE; | ||
2882 | setup_data.request.bRequestType = USB_RECIP_INTERFACE; | ||
2883 | setup_data.request.wValue = dev->cur_alt; | ||
2884 | setup_data.request.wIndex = dev->cur_intf; | ||
2885 | |||
2886 | DBG(dev, "SET_INTERFACE interrupt: alt=%d intf=%d\n", | ||
2887 | dev->cur_alt, dev->cur_intf); | ||
2888 | |||
2889 | /* programm the NE registers */ | ||
2890 | for (i = 0; i < UDC_EP_NUM; i++) { | ||
2891 | ep = &dev->ep[i]; | ||
2892 | if (ep->in) { | ||
2893 | |||
2894 | /* ep ix in UDC CSR register space */ | ||
2895 | udc_csr_epix = ep->num; | ||
2896 | |||
2897 | |||
2898 | /* OUT ep */ | ||
2899 | } else { | ||
2900 | /* ep ix in UDC CSR register space */ | ||
2901 | udc_csr_epix = ep->num - UDC_CSR_EP_OUT_IX_OFS; | ||
2902 | } | ||
2903 | |||
2904 | /* UDC CSR reg */ | ||
2905 | /* set ep values */ | ||
2906 | tmp = readl(&dev->csr->ne[udc_csr_epix]); | ||
2907 | /* ep interface */ | ||
2908 | tmp = AMD_ADDBITS(tmp, ep->dev->cur_intf, | ||
2909 | UDC_CSR_NE_INTF); | ||
2910 | /* tmp = AMD_ADDBITS(tmp, 2, UDC_CSR_NE_INTF); */ | ||
2911 | /* ep alt */ | ||
2912 | tmp = AMD_ADDBITS(tmp, ep->dev->cur_alt, | ||
2913 | UDC_CSR_NE_ALT); | ||
2914 | /* write reg */ | ||
2915 | writel(tmp, &dev->csr->ne[udc_csr_epix]); | ||
2916 | |||
2917 | /* clear stall bits */ | ||
2918 | ep->halted = 0; | ||
2919 | tmp = readl(&ep->regs->ctl); | ||
2920 | tmp = tmp & AMD_CLEAR_BIT(UDC_EPCTL_S); | ||
2921 | writel(tmp, &ep->regs->ctl); | ||
2922 | } | ||
2923 | |||
2924 | /* call gadget zero with setup data received */ | ||
2925 | spin_unlock(&dev->lock); | ||
2926 | tmp = dev->driver->setup(&dev->gadget, &setup_data.request); | ||
2927 | spin_lock(&dev->lock); | ||
2928 | |||
2929 | } /* USB reset */ | ||
2930 | if (dev_irq & AMD_BIT(UDC_DEVINT_UR)) { | ||
2931 | DBG(dev, "USB Reset interrupt\n"); | ||
2932 | ret_val = IRQ_HANDLED; | ||
2933 | |||
2934 | /* allow soft reset when suspend occurs */ | ||
2935 | soft_reset_occured = 0; | ||
2936 | |||
2937 | dev->waiting_zlp_ack_ep0in = 0; | ||
2938 | dev->set_cfg_not_acked = 0; | ||
2939 | |||
2940 | /* mask not needed interrupts */ | ||
2941 | udc_mask_unused_interrupts(dev); | ||
2942 | |||
2943 | /* call gadget to resume and reset configs etc. */ | ||
2944 | spin_unlock(&dev->lock); | ||
2945 | if (dev->sys_suspended && dev->driver->resume) { | ||
2946 | dev->driver->resume(&dev->gadget); | ||
2947 | dev->sys_suspended = 0; | ||
2948 | } | ||
2949 | dev->driver->disconnect(&dev->gadget); | ||
2950 | spin_lock(&dev->lock); | ||
2951 | |||
2952 | /* disable ep0 to empty req queue */ | ||
2953 | empty_req_queue(&dev->ep[UDC_EP0IN_IX]); | ||
2954 | ep_init(dev->regs, &dev->ep[UDC_EP0IN_IX]); | ||
2955 | |||
2956 | /* soft reset when rxfifo not empty */ | ||
2957 | tmp = readl(&dev->regs->sts); | ||
2958 | if (!(tmp & AMD_BIT(UDC_DEVSTS_RXFIFO_EMPTY)) | ||
2959 | && !soft_reset_after_usbreset_occured) { | ||
2960 | udc_soft_reset(dev); | ||
2961 | soft_reset_after_usbreset_occured++; | ||
2962 | } | ||
2963 | |||
2964 | /* | ||
2965 | * DMA reset to kill potential old DMA hw hang, | ||
2966 | * POLL bit is already reset by ep_init() through | ||
2967 | * disconnect() | ||
2968 | */ | ||
2969 | DBG(dev, "DMA machine reset\n"); | ||
2970 | tmp = readl(&dev->regs->cfg); | ||
2971 | writel(tmp | AMD_BIT(UDC_DEVCFG_DMARST), &dev->regs->cfg); | ||
2972 | writel(tmp, &dev->regs->cfg); | ||
2973 | |||
2974 | /* put into initial config */ | ||
2975 | udc_basic_init(dev); | ||
2976 | |||
2977 | /* enable device setup interrupts */ | ||
2978 | udc_enable_dev_setup_interrupts(dev); | ||
2979 | |||
2980 | /* enable suspend interrupt */ | ||
2981 | tmp = readl(&dev->regs->irqmsk); | ||
2982 | tmp &= AMD_UNMASK_BIT(UDC_DEVINT_US); | ||
2983 | writel(tmp, &dev->regs->irqmsk); | ||
2984 | |||
2985 | } /* USB suspend */ | ||
2986 | if (dev_irq & AMD_BIT(UDC_DEVINT_US)) { | ||
2987 | DBG(dev, "USB Suspend interrupt\n"); | ||
2988 | ret_val = IRQ_HANDLED; | ||
2989 | if (dev->driver->suspend) { | ||
2990 | spin_unlock(&dev->lock); | ||
2991 | dev->sys_suspended = 1; | ||
2992 | dev->driver->suspend(&dev->gadget); | ||
2993 | spin_lock(&dev->lock); | ||
2994 | } | ||
2995 | } /* new speed ? */ | ||
2996 | if (dev_irq & AMD_BIT(UDC_DEVINT_ENUM)) { | ||
2997 | DBG(dev, "ENUM interrupt\n"); | ||
2998 | ret_val = IRQ_HANDLED; | ||
2999 | soft_reset_after_usbreset_occured = 0; | ||
3000 | |||
3001 | /* disable ep0 to empty req queue */ | ||
3002 | empty_req_queue(&dev->ep[UDC_EP0IN_IX]); | ||
3003 | ep_init(dev->regs, &dev->ep[UDC_EP0IN_IX]); | ||
3004 | |||
3005 | /* link up all endpoints */ | ||
3006 | udc_setup_endpoints(dev); | ||
3007 | if (dev->gadget.speed == USB_SPEED_HIGH) { | ||
3008 | dev_info(&dev->pdev->dev, "Connect: speed = %s\n", | ||
3009 | "high"); | ||
3010 | } else if (dev->gadget.speed == USB_SPEED_FULL) { | ||
3011 | dev_info(&dev->pdev->dev, "Connect: speed = %s\n", | ||
3012 | "full"); | ||
3013 | } | ||
3014 | |||
3015 | /* init ep 0 */ | ||
3016 | activate_control_endpoints(dev); | ||
3017 | |||
3018 | /* enable ep0 interrupts */ | ||
3019 | udc_enable_ep0_interrupts(dev); | ||
3020 | } | ||
3021 | /* session valid change interrupt */ | ||
3022 | if (dev_irq & AMD_BIT(UDC_DEVINT_SVC)) { | ||
3023 | DBG(dev, "USB SVC interrupt\n"); | ||
3024 | ret_val = IRQ_HANDLED; | ||
3025 | |||
3026 | /* check that session is not valid to detect disconnect */ | ||
3027 | tmp = readl(&dev->regs->sts); | ||
3028 | if (!(tmp & AMD_BIT(UDC_DEVSTS_SESSVLD))) { | ||
3029 | /* disable suspend interrupt */ | ||
3030 | tmp = readl(&dev->regs->irqmsk); | ||
3031 | tmp |= AMD_BIT(UDC_DEVINT_US); | ||
3032 | writel(tmp, &dev->regs->irqmsk); | ||
3033 | DBG(dev, "USB Disconnect (session valid low)\n"); | ||
3034 | /* cleanup on disconnect */ | ||
3035 | usb_disconnect(udc); | ||
3036 | } | ||
3037 | |||
3038 | } | ||
3039 | |||
3040 | return ret_val; | ||
3041 | } | ||
3042 | |||
3043 | /* Interrupt Service Routine, see Linux Kernel Doc for parameters */ | ||
3044 | static irqreturn_t udc_irq(int irq, void *pdev) | ||
3045 | { | ||
3046 | struct udc *dev = pdev; | ||
3047 | u32 reg; | ||
3048 | u16 i; | ||
3049 | u32 ep_irq; | ||
3050 | irqreturn_t ret_val = IRQ_NONE; | ||
3051 | |||
3052 | spin_lock(&dev->lock); | ||
3053 | |||
3054 | /* check for ep irq */ | ||
3055 | reg = readl(&dev->regs->ep_irqsts); | ||
3056 | if (reg) { | ||
3057 | if (reg & AMD_BIT(UDC_EPINT_OUT_EP0)) | ||
3058 | ret_val |= udc_control_out_isr(dev); | ||
3059 | if (reg & AMD_BIT(UDC_EPINT_IN_EP0)) | ||
3060 | ret_val |= udc_control_in_isr(dev); | ||
3061 | |||
3062 | /* | ||
3063 | * data endpoint | ||
3064 | * iterate ep's | ||
3065 | */ | ||
3066 | for (i = 1; i < UDC_EP_NUM; i++) { | ||
3067 | ep_irq = 1 << i; | ||
3068 | if (!(reg & ep_irq) || i == UDC_EPINT_OUT_EP0) | ||
3069 | continue; | ||
3070 | |||
3071 | /* clear irq status */ | ||
3072 | writel(ep_irq, &dev->regs->ep_irqsts); | ||
3073 | |||
3074 | /* irq for out ep ? */ | ||
3075 | if (i > UDC_EPIN_NUM) | ||
3076 | ret_val |= udc_data_out_isr(dev, i); | ||
3077 | else | ||
3078 | ret_val |= udc_data_in_isr(dev, i); | ||
3079 | } | ||
3080 | |||
3081 | } | ||
3082 | |||
3083 | |||
3084 | /* check for dev irq */ | ||
3085 | reg = readl(&dev->regs->irqsts); | ||
3086 | if (reg) { | ||
3087 | /* clear irq */ | ||
3088 | writel(reg, &dev->regs->irqsts); | ||
3089 | ret_val |= udc_dev_isr(dev, reg); | ||
3090 | } | ||
3091 | |||
3092 | |||
3093 | spin_unlock(&dev->lock); | ||
3094 | return ret_val; | ||
3095 | } | ||
3096 | |||
3097 | /* Tears down device */ | ||
3098 | static void gadget_release(struct device *pdev) | ||
3099 | { | ||
3100 | struct amd5536udc *dev = dev_get_drvdata(pdev); | ||
3101 | kfree(dev); | ||
3102 | } | ||
3103 | |||
3104 | /* Cleanup on device remove */ | ||
3105 | static void udc_remove(struct udc *dev) | ||
3106 | { | ||
3107 | /* remove timer */ | ||
3108 | stop_timer++; | ||
3109 | if (timer_pending(&udc_timer)) | ||
3110 | wait_for_completion(&on_exit); | ||
3111 | if (udc_timer.data) | ||
3112 | del_timer_sync(&udc_timer); | ||
3113 | /* remove pollstall timer */ | ||
3114 | stop_pollstall_timer++; | ||
3115 | if (timer_pending(&udc_pollstall_timer)) | ||
3116 | wait_for_completion(&on_pollstall_exit); | ||
3117 | if (udc_pollstall_timer.data) | ||
3118 | del_timer_sync(&udc_pollstall_timer); | ||
3119 | udc = NULL; | ||
3120 | } | ||
3121 | |||
3122 | /* Reset all pci context */ | ||
3123 | static void udc_pci_remove(struct pci_dev *pdev) | ||
3124 | { | ||
3125 | struct udc *dev; | ||
3126 | |||
3127 | dev = pci_get_drvdata(pdev); | ||
3128 | |||
3129 | /* gadget driver must not be registered */ | ||
3130 | BUG_ON(dev->driver != NULL); | ||
3131 | |||
3132 | /* dma pool cleanup */ | ||
3133 | if (dev->data_requests) | ||
3134 | pci_pool_destroy(dev->data_requests); | ||
3135 | |||
3136 | if (dev->stp_requests) { | ||
3137 | /* cleanup DMA desc's for ep0in */ | ||
3138 | pci_pool_free(dev->stp_requests, | ||
3139 | dev->ep[UDC_EP0OUT_IX].td_stp, | ||
3140 | dev->ep[UDC_EP0OUT_IX].td_stp_dma); | ||
3141 | pci_pool_free(dev->stp_requests, | ||
3142 | dev->ep[UDC_EP0OUT_IX].td, | ||
3143 | dev->ep[UDC_EP0OUT_IX].td_phys); | ||
3144 | |||
3145 | pci_pool_destroy(dev->stp_requests); | ||
3146 | } | ||
3147 | |||
3148 | /* reset controller */ | ||
3149 | writel(AMD_BIT(UDC_DEVCFG_SOFTRESET), &dev->regs->cfg); | ||
3150 | if (dev->irq_registered) | ||
3151 | free_irq(pdev->irq, dev); | ||
3152 | if (dev->regs) | ||
3153 | iounmap(dev->regs); | ||
3154 | if (dev->mem_region) | ||
3155 | release_mem_region(pci_resource_start(pdev, 0), | ||
3156 | pci_resource_len(pdev, 0)); | ||
3157 | if (dev->active) | ||
3158 | pci_disable_device(pdev); | ||
3159 | |||
3160 | device_unregister(&dev->gadget.dev); | ||
3161 | pci_set_drvdata(pdev, NULL); | ||
3162 | |||
3163 | udc_remove(dev); | ||
3164 | } | ||
3165 | |||
3166 | /* create dma pools on init */ | ||
3167 | static int init_dma_pools(struct udc *dev) | ||
3168 | { | ||
3169 | struct udc_stp_dma *td_stp; | ||
3170 | struct udc_data_dma *td_data; | ||
3171 | int retval; | ||
3172 | |||
3173 | /* consistent DMA mode setting ? */ | ||
3174 | if (use_dma_ppb) { | ||
3175 | use_dma_bufferfill_mode = 0; | ||
3176 | } else { | ||
3177 | use_dma_ppb_du = 0; | ||
3178 | use_dma_bufferfill_mode = 1; | ||
3179 | } | ||
3180 | |||
3181 | /* DMA setup */ | ||
3182 | dev->data_requests = dma_pool_create("data_requests", NULL, | ||
3183 | sizeof(struct udc_data_dma), 0, 0); | ||
3184 | if (!dev->data_requests) { | ||
3185 | DBG(dev, "can't get request data pool\n"); | ||
3186 | retval = -ENOMEM; | ||
3187 | goto finished; | ||
3188 | } | ||
3189 | |||
3190 | /* EP0 in dma regs = dev control regs */ | ||
3191 | dev->ep[UDC_EP0IN_IX].dma = &dev->regs->ctl; | ||
3192 | |||
3193 | /* dma desc for setup data */ | ||
3194 | dev->stp_requests = dma_pool_create("setup requests", NULL, | ||
3195 | sizeof(struct udc_stp_dma), 0, 0); | ||
3196 | if (!dev->stp_requests) { | ||
3197 | DBG(dev, "can't get stp request pool\n"); | ||
3198 | retval = -ENOMEM; | ||
3199 | goto finished; | ||
3200 | } | ||
3201 | /* setup */ | ||
3202 | td_stp = dma_pool_alloc(dev->stp_requests, GFP_KERNEL, | ||
3203 | &dev->ep[UDC_EP0OUT_IX].td_stp_dma); | ||
3204 | if (td_stp == NULL) { | ||
3205 | retval = -ENOMEM; | ||
3206 | goto finished; | ||
3207 | } | ||
3208 | dev->ep[UDC_EP0OUT_IX].td_stp = td_stp; | ||
3209 | |||
3210 | /* data: 0 packets !? */ | ||
3211 | td_data = dma_pool_alloc(dev->stp_requests, GFP_KERNEL, | ||
3212 | &dev->ep[UDC_EP0OUT_IX].td_phys); | ||
3213 | if (td_data == NULL) { | ||
3214 | retval = -ENOMEM; | ||
3215 | goto finished; | ||
3216 | } | ||
3217 | dev->ep[UDC_EP0OUT_IX].td = td_data; | ||
3218 | return 0; | ||
3219 | |||
3220 | finished: | ||
3221 | return retval; | ||
3222 | } | ||
3223 | |||
3224 | /* Called by pci bus driver to init pci context */ | ||
3225 | static int udc_pci_probe( | ||
3226 | struct pci_dev *pdev, | ||
3227 | const struct pci_device_id *id | ||
3228 | ) | ||
3229 | { | ||
3230 | struct udc *dev; | ||
3231 | unsigned long resource; | ||
3232 | unsigned long len; | ||
3233 | int retval = 0; | ||
3234 | |||
3235 | /* one udc only */ | ||
3236 | if (udc) { | ||
3237 | dev_dbg(&pdev->dev, "already probed\n"); | ||
3238 | return -EBUSY; | ||
3239 | } | ||
3240 | |||
3241 | /* init */ | ||
3242 | dev = kzalloc(sizeof(struct udc), GFP_KERNEL); | ||
3243 | if (!dev) { | ||
3244 | retval = -ENOMEM; | ||
3245 | goto finished; | ||
3246 | } | ||
3247 | memset(dev, 0, sizeof(struct udc)); | ||
3248 | |||
3249 | /* pci setup */ | ||
3250 | if (pci_enable_device(pdev) < 0) { | ||
3251 | retval = -ENODEV; | ||
3252 | goto finished; | ||
3253 | } | ||
3254 | dev->active = 1; | ||
3255 | |||
3256 | /* PCI resource allocation */ | ||
3257 | resource = pci_resource_start(pdev, 0); | ||
3258 | len = pci_resource_len(pdev, 0); | ||
3259 | |||
3260 | if (!request_mem_region(resource, len, name)) { | ||
3261 | dev_dbg(&pdev->dev, "pci device used already\n"); | ||
3262 | retval = -EBUSY; | ||
3263 | goto finished; | ||
3264 | } | ||
3265 | dev->mem_region = 1; | ||
3266 | |||
3267 | dev->virt_addr = ioremap_nocache(resource, len); | ||
3268 | if (dev->virt_addr == NULL) { | ||
3269 | dev_dbg(&pdev->dev, "start address cannot be mapped\n"); | ||
3270 | retval = -EFAULT; | ||
3271 | goto finished; | ||
3272 | } | ||
3273 | |||
3274 | if (!pdev->irq) { | ||
3275 | dev_err(&dev->pdev->dev, "irq not set\n"); | ||
3276 | retval = -ENODEV; | ||
3277 | goto finished; | ||
3278 | } | ||
3279 | |||
3280 | if (request_irq(pdev->irq, udc_irq, IRQF_SHARED, name, dev) != 0) { | ||
3281 | dev_dbg(&dev->pdev->dev, "request_irq(%d) fail\n", pdev->irq); | ||
3282 | retval = -EBUSY; | ||
3283 | goto finished; | ||
3284 | } | ||
3285 | dev->irq_registered = 1; | ||
3286 | |||
3287 | pci_set_drvdata(pdev, dev); | ||
3288 | |||
3289 | /* chip revision */ | ||
3290 | dev->chiprev = 0; | ||
3291 | |||
3292 | pci_set_master(pdev); | ||
3293 | pci_set_mwi(pdev); | ||
3294 | |||
3295 | /* chip rev for Hs AMD5536 */ | ||
3296 | pci_read_config_byte(pdev, PCI_REVISION_ID, (u8 *) &dev->chiprev); | ||
3297 | /* init dma pools */ | ||
3298 | if (use_dma) { | ||
3299 | retval = init_dma_pools(dev); | ||
3300 | if (retval != 0) | ||
3301 | goto finished; | ||
3302 | } | ||
3303 | |||
3304 | dev->phys_addr = resource; | ||
3305 | dev->irq = pdev->irq; | ||
3306 | dev->pdev = pdev; | ||
3307 | dev->gadget.dev.parent = &pdev->dev; | ||
3308 | dev->gadget.dev.dma_mask = pdev->dev.dma_mask; | ||
3309 | |||
3310 | /* general probing */ | ||
3311 | if (udc_probe(dev) == 0) | ||
3312 | return 0; | ||
3313 | |||
3314 | finished: | ||
3315 | if (dev) | ||
3316 | udc_pci_remove(pdev); | ||
3317 | return retval; | ||
3318 | } | ||
3319 | |||
3320 | /* general probe */ | ||
3321 | static int udc_probe(struct udc *dev) | ||
3322 | { | ||
3323 | char tmp[128]; | ||
3324 | u32 reg; | ||
3325 | int retval; | ||
3326 | |||
3327 | /* mark timer as not initialized */ | ||
3328 | udc_timer.data = 0; | ||
3329 | udc_pollstall_timer.data = 0; | ||
3330 | |||
3331 | /* device struct setup */ | ||
3332 | spin_lock_init(&dev->lock); | ||
3333 | dev->gadget.ops = &udc_ops; | ||
3334 | |||
3335 | strcpy(dev->gadget.dev.bus_id, "gadget"); | ||
3336 | dev->gadget.dev.release = gadget_release; | ||
3337 | dev->gadget.name = name; | ||
3338 | dev->gadget.name = name; | ||
3339 | dev->gadget.is_dualspeed = 1; | ||
3340 | |||
3341 | /* udc csr registers base */ | ||
3342 | dev->csr = dev->virt_addr + UDC_CSR_ADDR; | ||
3343 | /* dev registers base */ | ||
3344 | dev->regs = dev->virt_addr + UDC_DEVCFG_ADDR; | ||
3345 | /* ep registers base */ | ||
3346 | dev->ep_regs = dev->virt_addr + UDC_EPREGS_ADDR; | ||
3347 | /* fifo's base */ | ||
3348 | dev->rxfifo = (u32 __iomem *)(dev->virt_addr + UDC_RXFIFO_ADDR); | ||
3349 | dev->txfifo = (u32 __iomem *)(dev->virt_addr + UDC_TXFIFO_ADDR); | ||
3350 | |||
3351 | /* init registers, interrupts, ... */ | ||
3352 | startup_registers(dev); | ||
3353 | |||
3354 | dev_info(&dev->pdev->dev, "%s\n", mod_desc); | ||
3355 | |||
3356 | snprintf(tmp, sizeof tmp, "%d", dev->irq); | ||
3357 | dev_info(&dev->pdev->dev, | ||
3358 | "irq %s, pci mem %08lx, chip rev %02x(Geode5536 %s)\n", | ||
3359 | tmp, dev->phys_addr, dev->chiprev, | ||
3360 | (dev->chiprev == UDC_HSA0_REV) ? "A0" : "B1"); | ||
3361 | strcpy(tmp, UDC_DRIVER_VERSION_STRING); | ||
3362 | if (dev->chiprev == UDC_HSA0_REV) { | ||
3363 | dev_err(&dev->pdev->dev, "chip revision is A0; too old\n"); | ||
3364 | retval = -ENODEV; | ||
3365 | goto finished; | ||
3366 | } | ||
3367 | dev_info(&dev->pdev->dev, | ||
3368 | "driver version: %s(for Geode5536 B1)\n", tmp); | ||
3369 | udc = dev; | ||
3370 | |||
3371 | retval = device_register(&dev->gadget.dev); | ||
3372 | if (retval) | ||
3373 | goto finished; | ||
3374 | |||
3375 | /* timer init */ | ||
3376 | init_timer(&udc_timer); | ||
3377 | udc_timer.function = udc_timer_function; | ||
3378 | udc_timer.data = 1; | ||
3379 | /* timer pollstall init */ | ||
3380 | init_timer(&udc_pollstall_timer); | ||
3381 | udc_pollstall_timer.function = udc_pollstall_timer_function; | ||
3382 | udc_pollstall_timer.data = 1; | ||
3383 | |||
3384 | /* set SD */ | ||
3385 | reg = readl(&dev->regs->ctl); | ||
3386 | reg |= AMD_BIT(UDC_DEVCTL_SD); | ||
3387 | writel(reg, &dev->regs->ctl); | ||
3388 | |||
3389 | /* print dev register info */ | ||
3390 | print_regs(dev); | ||
3391 | |||
3392 | return 0; | ||
3393 | |||
3394 | finished: | ||
3395 | return retval; | ||
3396 | } | ||
3397 | |||
3398 | /* Initiates a remote wakeup */ | ||
3399 | static int udc_remote_wakeup(struct udc *dev) | ||
3400 | { | ||
3401 | unsigned long flags; | ||
3402 | u32 tmp; | ||
3403 | |||
3404 | DBG(dev, "UDC initiates remote wakeup\n"); | ||
3405 | |||
3406 | spin_lock_irqsave(&dev->lock, flags); | ||
3407 | |||
3408 | tmp = readl(&dev->regs->ctl); | ||
3409 | tmp |= AMD_BIT(UDC_DEVCTL_RES); | ||
3410 | writel(tmp, &dev->regs->ctl); | ||
3411 | tmp &= AMD_CLEAR_BIT(UDC_DEVCTL_RES); | ||
3412 | writel(tmp, &dev->regs->ctl); | ||
3413 | |||
3414 | spin_unlock_irqrestore(&dev->lock, flags); | ||
3415 | return 0; | ||
3416 | } | ||
3417 | |||
3418 | /* PCI device parameters */ | ||
3419 | static const struct pci_device_id pci_id[] = { | ||
3420 | { | ||
3421 | PCI_DEVICE(PCI_VENDOR_ID_AMD, 0x2096), | ||
3422 | .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe, | ||
3423 | .class_mask = 0xffffffff, | ||
3424 | }, | ||
3425 | {}, | ||
3426 | }; | ||
3427 | MODULE_DEVICE_TABLE(pci, pci_id); | ||
3428 | |||
3429 | /* PCI functions */ | ||
3430 | static struct pci_driver udc_pci_driver = { | ||
3431 | .name = (char *) name, | ||
3432 | .id_table = pci_id, | ||
3433 | .probe = udc_pci_probe, | ||
3434 | .remove = udc_pci_remove, | ||
3435 | }; | ||
3436 | |||
3437 | /* Inits driver */ | ||
3438 | static int __init init(void) | ||
3439 | { | ||
3440 | return pci_register_driver(&udc_pci_driver); | ||
3441 | } | ||
3442 | module_init(init); | ||
3443 | |||
3444 | /* Cleans driver */ | ||
3445 | static void __exit cleanup(void) | ||
3446 | { | ||
3447 | pci_unregister_driver(&udc_pci_driver); | ||
3448 | } | ||
3449 | module_exit(cleanup); | ||
3450 | |||
3451 | MODULE_DESCRIPTION(UDC_MOD_DESCRIPTION); | ||
3452 | MODULE_AUTHOR("Thomas Dahlmann"); | ||
3453 | MODULE_LICENSE("GPL"); | ||
3454 | |||
diff --git a/drivers/usb/gadget/amd5536udc.h b/drivers/usb/gadget/amd5536udc.h new file mode 100644 index 000000000000..4bbabbbfc93f --- /dev/null +++ b/drivers/usb/gadget/amd5536udc.h | |||
@@ -0,0 +1,626 @@ | |||
1 | /* | ||
2 | * amd5536.h -- header for AMD 5536 UDC high/full speed USB device controller | ||
3 | * | ||
4 | * Copyright (C) 2007 AMD (http://www.amd.com) | ||
5 | * Author: Thomas Dahlmann | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | ||
21 | |||
22 | #ifndef AMD5536UDC_H | ||
23 | #define AMD5536UDC_H | ||
24 | |||
25 | /* various constants */ | ||
26 | #define UDC_RDE_TIMER_SECONDS 1 | ||
27 | #define UDC_RDE_TIMER_DIV 10 | ||
28 | #define UDC_POLLSTALL_TIMER_USECONDS 500 | ||
29 | |||
30 | /* Hs AMD5536 chip rev. */ | ||
31 | #define UDC_HSA0_REV 1 | ||
32 | #define UDC_HSB1_REV 2 | ||
33 | |||
34 | /* | ||
35 | * SETUP usb commands | ||
36 | * needed, because some SETUP's are handled in hw, but must be passed to | ||
37 | * gadget driver above | ||
38 | * SET_CONFIG | ||
39 | */ | ||
40 | #define UDC_SETCONFIG_DWORD0 0x00000900 | ||
41 | #define UDC_SETCONFIG_DWORD0_VALUE_MASK 0xffff0000 | ||
42 | #define UDC_SETCONFIG_DWORD0_VALUE_OFS 16 | ||
43 | |||
44 | #define UDC_SETCONFIG_DWORD1 0x00000000 | ||
45 | |||
46 | /* SET_INTERFACE */ | ||
47 | #define UDC_SETINTF_DWORD0 0x00000b00 | ||
48 | #define UDC_SETINTF_DWORD0_ALT_MASK 0xffff0000 | ||
49 | #define UDC_SETINTF_DWORD0_ALT_OFS 16 | ||
50 | |||
51 | #define UDC_SETINTF_DWORD1 0x00000000 | ||
52 | #define UDC_SETINTF_DWORD1_INTF_MASK 0x0000ffff | ||
53 | #define UDC_SETINTF_DWORD1_INTF_OFS 0 | ||
54 | |||
55 | /* Mass storage reset */ | ||
56 | #define UDC_MSCRES_DWORD0 0x0000ff21 | ||
57 | #define UDC_MSCRES_DWORD1 0x00000000 | ||
58 | |||
59 | /* Global CSR's -------------------------------------------------------------*/ | ||
60 | #define UDC_CSR_ADDR 0x500 | ||
61 | |||
62 | /* EP NE bits */ | ||
63 | /* EP number */ | ||
64 | #define UDC_CSR_NE_NUM_MASK 0x0000000f | ||
65 | #define UDC_CSR_NE_NUM_OFS 0 | ||
66 | /* EP direction */ | ||
67 | #define UDC_CSR_NE_DIR_MASK 0x00000010 | ||
68 | #define UDC_CSR_NE_DIR_OFS 4 | ||
69 | /* EP type */ | ||
70 | #define UDC_CSR_NE_TYPE_MASK 0x00000060 | ||
71 | #define UDC_CSR_NE_TYPE_OFS 5 | ||
72 | /* EP config number */ | ||
73 | #define UDC_CSR_NE_CFG_MASK 0x00000780 | ||
74 | #define UDC_CSR_NE_CFG_OFS 7 | ||
75 | /* EP interface number */ | ||
76 | #define UDC_CSR_NE_INTF_MASK 0x00007800 | ||
77 | #define UDC_CSR_NE_INTF_OFS 11 | ||
78 | /* EP alt setting */ | ||
79 | #define UDC_CSR_NE_ALT_MASK 0x00078000 | ||
80 | #define UDC_CSR_NE_ALT_OFS 15 | ||
81 | |||
82 | /* max pkt */ | ||
83 | #define UDC_CSR_NE_MAX_PKT_MASK 0x3ff80000 | ||
84 | #define UDC_CSR_NE_MAX_PKT_OFS 19 | ||
85 | |||
86 | /* Device Config Register ---------------------------------------------------*/ | ||
87 | #define UDC_DEVCFG_ADDR 0x400 | ||
88 | |||
89 | #define UDC_DEVCFG_SOFTRESET 31 | ||
90 | #define UDC_DEVCFG_HNPSFEN 30 | ||
91 | #define UDC_DEVCFG_DMARST 29 | ||
92 | #define UDC_DEVCFG_SET_DESC 18 | ||
93 | #define UDC_DEVCFG_CSR_PRG 17 | ||
94 | #define UDC_DEVCFG_STATUS 7 | ||
95 | #define UDC_DEVCFG_DIR 6 | ||
96 | #define UDC_DEVCFG_PI 5 | ||
97 | #define UDC_DEVCFG_SS 4 | ||
98 | #define UDC_DEVCFG_SP 3 | ||
99 | #define UDC_DEVCFG_RWKP 2 | ||
100 | |||
101 | #define UDC_DEVCFG_SPD_MASK 0x3 | ||
102 | #define UDC_DEVCFG_SPD_OFS 0 | ||
103 | #define UDC_DEVCFG_SPD_HS 0x0 | ||
104 | #define UDC_DEVCFG_SPD_FS 0x1 | ||
105 | #define UDC_DEVCFG_SPD_LS 0x2 | ||
106 | /*#define UDC_DEVCFG_SPD_FS 0x3*/ | ||
107 | |||
108 | |||
109 | /* Device Control Register --------------------------------------------------*/ | ||
110 | #define UDC_DEVCTL_ADDR 0x404 | ||
111 | |||
112 | #define UDC_DEVCTL_THLEN_MASK 0xff000000 | ||
113 | #define UDC_DEVCTL_THLEN_OFS 24 | ||
114 | |||
115 | #define UDC_DEVCTL_BRLEN_MASK 0x00ff0000 | ||
116 | #define UDC_DEVCTL_BRLEN_OFS 16 | ||
117 | |||
118 | #define UDC_DEVCTL_CSR_DONE 13 | ||
119 | #define UDC_DEVCTL_DEVNAK 12 | ||
120 | #define UDC_DEVCTL_SD 10 | ||
121 | #define UDC_DEVCTL_MODE 9 | ||
122 | #define UDC_DEVCTL_BREN 8 | ||
123 | #define UDC_DEVCTL_THE 7 | ||
124 | #define UDC_DEVCTL_BF 6 | ||
125 | #define UDC_DEVCTL_BE 5 | ||
126 | #define UDC_DEVCTL_DU 4 | ||
127 | #define UDC_DEVCTL_TDE 3 | ||
128 | #define UDC_DEVCTL_RDE 2 | ||
129 | #define UDC_DEVCTL_RES 0 | ||
130 | |||
131 | |||
132 | /* Device Status Register ---------------------------------------------------*/ | ||
133 | #define UDC_DEVSTS_ADDR 0x408 | ||
134 | |||
135 | #define UDC_DEVSTS_TS_MASK 0xfffc0000 | ||
136 | #define UDC_DEVSTS_TS_OFS 18 | ||
137 | |||
138 | #define UDC_DEVSTS_SESSVLD 17 | ||
139 | #define UDC_DEVSTS_PHY_ERROR 16 | ||
140 | #define UDC_DEVSTS_RXFIFO_EMPTY 15 | ||
141 | |||
142 | #define UDC_DEVSTS_ENUM_SPEED_MASK 0x00006000 | ||
143 | #define UDC_DEVSTS_ENUM_SPEED_OFS 13 | ||
144 | #define UDC_DEVSTS_ENUM_SPEED_FULL 1 | ||
145 | #define UDC_DEVSTS_ENUM_SPEED_HIGH 0 | ||
146 | |||
147 | #define UDC_DEVSTS_SUSP 12 | ||
148 | |||
149 | #define UDC_DEVSTS_ALT_MASK 0x00000f00 | ||
150 | #define UDC_DEVSTS_ALT_OFS 8 | ||
151 | |||
152 | #define UDC_DEVSTS_INTF_MASK 0x000000f0 | ||
153 | #define UDC_DEVSTS_INTF_OFS 4 | ||
154 | |||
155 | #define UDC_DEVSTS_CFG_MASK 0x0000000f | ||
156 | #define UDC_DEVSTS_CFG_OFS 0 | ||
157 | |||
158 | |||
159 | /* Device Interrupt Register ------------------------------------------------*/ | ||
160 | #define UDC_DEVINT_ADDR 0x40c | ||
161 | |||
162 | #define UDC_DEVINT_SVC 7 | ||
163 | #define UDC_DEVINT_ENUM 6 | ||
164 | #define UDC_DEVINT_SOF 5 | ||
165 | #define UDC_DEVINT_US 4 | ||
166 | #define UDC_DEVINT_UR 3 | ||
167 | #define UDC_DEVINT_ES 2 | ||
168 | #define UDC_DEVINT_SI 1 | ||
169 | #define UDC_DEVINT_SC 0 | ||
170 | |||
171 | /* Device Interrupt Mask Register -------------------------------------------*/ | ||
172 | #define UDC_DEVINT_MSK_ADDR 0x410 | ||
173 | |||
174 | #define UDC_DEVINT_MSK 0x7f | ||
175 | |||
176 | /* Endpoint Interrupt Register ----------------------------------------------*/ | ||
177 | #define UDC_EPINT_ADDR 0x414 | ||
178 | |||
179 | #define UDC_EPINT_OUT_MASK 0xffff0000 | ||
180 | #define UDC_EPINT_OUT_OFS 16 | ||
181 | #define UDC_EPINT_IN_MASK 0x0000ffff | ||
182 | #define UDC_EPINT_IN_OFS 0 | ||
183 | |||
184 | #define UDC_EPINT_IN_EP0 0 | ||
185 | #define UDC_EPINT_IN_EP1 1 | ||
186 | #define UDC_EPINT_IN_EP2 2 | ||
187 | #define UDC_EPINT_IN_EP3 3 | ||
188 | #define UDC_EPINT_OUT_EP0 16 | ||
189 | #define UDC_EPINT_OUT_EP1 17 | ||
190 | #define UDC_EPINT_OUT_EP2 18 | ||
191 | #define UDC_EPINT_OUT_EP3 19 | ||
192 | |||
193 | #define UDC_EPINT_EP0_ENABLE_MSK 0x001e001e | ||
194 | |||
195 | /* Endpoint Interrupt Mask Register -----------------------------------------*/ | ||
196 | #define UDC_EPINT_MSK_ADDR 0x418 | ||
197 | |||
198 | #define UDC_EPINT_OUT_MSK_MASK 0xffff0000 | ||
199 | #define UDC_EPINT_OUT_MSK_OFS 16 | ||
200 | #define UDC_EPINT_IN_MSK_MASK 0x0000ffff | ||
201 | #define UDC_EPINT_IN_MSK_OFS 0 | ||
202 | |||
203 | #define UDC_EPINT_MSK_DISABLE_ALL 0xffffffff | ||
204 | /* mask non-EP0 endpoints */ | ||
205 | #define UDC_EPDATAINT_MSK_DISABLE 0xfffefffe | ||
206 | /* mask all dev interrupts */ | ||
207 | #define UDC_DEV_MSK_DISABLE 0x7f | ||
208 | |||
209 | /* Endpoint-specific CSR's --------------------------------------------------*/ | ||
210 | #define UDC_EPREGS_ADDR 0x0 | ||
211 | #define UDC_EPIN_REGS_ADDR 0x0 | ||
212 | #define UDC_EPOUT_REGS_ADDR 0x200 | ||
213 | |||
214 | #define UDC_EPCTL_ADDR 0x0 | ||
215 | |||
216 | #define UDC_EPCTL_RRDY 9 | ||
217 | #define UDC_EPCTL_CNAK 8 | ||
218 | #define UDC_EPCTL_SNAK 7 | ||
219 | #define UDC_EPCTL_NAK 6 | ||
220 | |||
221 | #define UDC_EPCTL_ET_MASK 0x00000030 | ||
222 | #define UDC_EPCTL_ET_OFS 4 | ||
223 | #define UDC_EPCTL_ET_CONTROL 0 | ||
224 | #define UDC_EPCTL_ET_ISO 1 | ||
225 | #define UDC_EPCTL_ET_BULK 2 | ||
226 | #define UDC_EPCTL_ET_INTERRUPT 3 | ||
227 | |||
228 | #define UDC_EPCTL_P 3 | ||
229 | #define UDC_EPCTL_SN 2 | ||
230 | #define UDC_EPCTL_F 1 | ||
231 | #define UDC_EPCTL_S 0 | ||
232 | |||
233 | /* Endpoint Status Registers ------------------------------------------------*/ | ||
234 | #define UDC_EPSTS_ADDR 0x4 | ||
235 | |||
236 | #define UDC_EPSTS_RX_PKT_SIZE_MASK 0x007ff800 | ||
237 | #define UDC_EPSTS_RX_PKT_SIZE_OFS 11 | ||
238 | |||
239 | #define UDC_EPSTS_TDC 10 | ||
240 | #define UDC_EPSTS_HE 9 | ||
241 | #define UDC_EPSTS_BNA 7 | ||
242 | #define UDC_EPSTS_IN 6 | ||
243 | |||
244 | #define UDC_EPSTS_OUT_MASK 0x00000030 | ||
245 | #define UDC_EPSTS_OUT_OFS 4 | ||
246 | #define UDC_EPSTS_OUT_DATA 1 | ||
247 | #define UDC_EPSTS_OUT_DATA_CLEAR 0x10 | ||
248 | #define UDC_EPSTS_OUT_SETUP 2 | ||
249 | #define UDC_EPSTS_OUT_SETUP_CLEAR 0x20 | ||
250 | #define UDC_EPSTS_OUT_CLEAR 0x30 | ||
251 | |||
252 | /* Endpoint Buffer Size IN/ Receive Packet Frame Number OUT Registers ------*/ | ||
253 | #define UDC_EPIN_BUFF_SIZE_ADDR 0x8 | ||
254 | #define UDC_EPOUT_FRAME_NUMBER_ADDR 0x8 | ||
255 | |||
256 | #define UDC_EPIN_BUFF_SIZE_MASK 0x0000ffff | ||
257 | #define UDC_EPIN_BUFF_SIZE_OFS 0 | ||
258 | /* EP0in txfifo = 128 bytes*/ | ||
259 | #define UDC_EPIN0_BUFF_SIZE 32 | ||
260 | /* EP0in fullspeed txfifo = 128 bytes*/ | ||
261 | #define UDC_FS_EPIN0_BUFF_SIZE 32 | ||
262 | |||
263 | /* fifo size mult = fifo size / max packet */ | ||
264 | #define UDC_EPIN_BUFF_SIZE_MULT 2 | ||
265 | |||
266 | /* EPin data fifo size = 1024 bytes DOUBLE BUFFERING */ | ||
267 | #define UDC_EPIN_BUFF_SIZE 256 | ||
268 | /* EPin small INT data fifo size = 128 bytes */ | ||
269 | #define UDC_EPIN_SMALLINT_BUFF_SIZE 32 | ||
270 | |||
271 | /* EPin fullspeed data fifo size = 128 bytes DOUBLE BUFFERING */ | ||
272 | #define UDC_FS_EPIN_BUFF_SIZE 32 | ||
273 | |||
274 | #define UDC_EPOUT_FRAME_NUMBER_MASK 0x0000ffff | ||
275 | #define UDC_EPOUT_FRAME_NUMBER_OFS 0 | ||
276 | |||
277 | /* Endpoint Buffer Size OUT/Max Packet Size Registers -----------------------*/ | ||
278 | #define UDC_EPOUT_BUFF_SIZE_ADDR 0x0c | ||
279 | #define UDC_EP_MAX_PKT_SIZE_ADDR 0x0c | ||
280 | |||
281 | #define UDC_EPOUT_BUFF_SIZE_MASK 0xffff0000 | ||
282 | #define UDC_EPOUT_BUFF_SIZE_OFS 16 | ||
283 | #define UDC_EP_MAX_PKT_SIZE_MASK 0x0000ffff | ||
284 | #define UDC_EP_MAX_PKT_SIZE_OFS 0 | ||
285 | /* EP0in max packet size = 64 bytes */ | ||
286 | #define UDC_EP0IN_MAX_PKT_SIZE 64 | ||
287 | /* EP0out max packet size = 64 bytes */ | ||
288 | #define UDC_EP0OUT_MAX_PKT_SIZE 64 | ||
289 | /* EP0in fullspeed max packet size = 64 bytes */ | ||
290 | #define UDC_FS_EP0IN_MAX_PKT_SIZE 64 | ||
291 | /* EP0out fullspeed max packet size = 64 bytes */ | ||
292 | #define UDC_FS_EP0OUT_MAX_PKT_SIZE 64 | ||
293 | |||
294 | /* | ||
295 | * Endpoint dma descriptors ------------------------------------------------ | ||
296 | * | ||
297 | * Setup data, Status dword | ||
298 | */ | ||
299 | #define UDC_DMA_STP_STS_CFG_MASK 0x0fff0000 | ||
300 | #define UDC_DMA_STP_STS_CFG_OFS 16 | ||
301 | #define UDC_DMA_STP_STS_CFG_ALT_MASK 0x000f0000 | ||
302 | #define UDC_DMA_STP_STS_CFG_ALT_OFS 16 | ||
303 | #define UDC_DMA_STP_STS_CFG_INTF_MASK 0x00f00000 | ||
304 | #define UDC_DMA_STP_STS_CFG_INTF_OFS 20 | ||
305 | #define UDC_DMA_STP_STS_CFG_NUM_MASK 0x0f000000 | ||
306 | #define UDC_DMA_STP_STS_CFG_NUM_OFS 24 | ||
307 | #define UDC_DMA_STP_STS_RX_MASK 0x30000000 | ||
308 | #define UDC_DMA_STP_STS_RX_OFS 28 | ||
309 | #define UDC_DMA_STP_STS_BS_MASK 0xc0000000 | ||
310 | #define UDC_DMA_STP_STS_BS_OFS 30 | ||
311 | #define UDC_DMA_STP_STS_BS_HOST_READY 0 | ||
312 | #define UDC_DMA_STP_STS_BS_DMA_BUSY 1 | ||
313 | #define UDC_DMA_STP_STS_BS_DMA_DONE 2 | ||
314 | #define UDC_DMA_STP_STS_BS_HOST_BUSY 3 | ||
315 | /* IN data, Status dword */ | ||
316 | #define UDC_DMA_IN_STS_TXBYTES_MASK 0x0000ffff | ||
317 | #define UDC_DMA_IN_STS_TXBYTES_OFS 0 | ||
318 | #define UDC_DMA_IN_STS_FRAMENUM_MASK 0x07ff0000 | ||
319 | #define UDC_DMA_IN_STS_FRAMENUM_OFS 0 | ||
320 | #define UDC_DMA_IN_STS_L 27 | ||
321 | #define UDC_DMA_IN_STS_TX_MASK 0x30000000 | ||
322 | #define UDC_DMA_IN_STS_TX_OFS 28 | ||
323 | #define UDC_DMA_IN_STS_BS_MASK 0xc0000000 | ||
324 | #define UDC_DMA_IN_STS_BS_OFS 30 | ||
325 | #define UDC_DMA_IN_STS_BS_HOST_READY 0 | ||
326 | #define UDC_DMA_IN_STS_BS_DMA_BUSY 1 | ||
327 | #define UDC_DMA_IN_STS_BS_DMA_DONE 2 | ||
328 | #define UDC_DMA_IN_STS_BS_HOST_BUSY 3 | ||
329 | /* OUT data, Status dword */ | ||
330 | #define UDC_DMA_OUT_STS_RXBYTES_MASK 0x0000ffff | ||
331 | #define UDC_DMA_OUT_STS_RXBYTES_OFS 0 | ||
332 | #define UDC_DMA_OUT_STS_FRAMENUM_MASK 0x07ff0000 | ||
333 | #define UDC_DMA_OUT_STS_FRAMENUM_OFS 0 | ||
334 | #define UDC_DMA_OUT_STS_L 27 | ||
335 | #define UDC_DMA_OUT_STS_RX_MASK 0x30000000 | ||
336 | #define UDC_DMA_OUT_STS_RX_OFS 28 | ||
337 | #define UDC_DMA_OUT_STS_BS_MASK 0xc0000000 | ||
338 | #define UDC_DMA_OUT_STS_BS_OFS 30 | ||
339 | #define UDC_DMA_OUT_STS_BS_HOST_READY 0 | ||
340 | #define UDC_DMA_OUT_STS_BS_DMA_BUSY 1 | ||
341 | #define UDC_DMA_OUT_STS_BS_DMA_DONE 2 | ||
342 | #define UDC_DMA_OUT_STS_BS_HOST_BUSY 3 | ||
343 | /* max ep0in packet */ | ||
344 | #define UDC_EP0IN_MAXPACKET 1000 | ||
345 | /* max dma packet */ | ||
346 | #define UDC_DMA_MAXPACKET 65536 | ||
347 | |||
348 | /* un-usable DMA address */ | ||
349 | #define DMA_DONT_USE (~(dma_addr_t) 0 ) | ||
350 | |||
351 | /* other Endpoint register addresses and values-----------------------------*/ | ||
352 | #define UDC_EP_SUBPTR_ADDR 0x10 | ||
353 | #define UDC_EP_DESPTR_ADDR 0x14 | ||
354 | #define UDC_EP_WRITE_CONFIRM_ADDR 0x1c | ||
355 | |||
356 | /* EP number as layouted in AHB space */ | ||
357 | #define UDC_EP_NUM 32 | ||
358 | #define UDC_EPIN_NUM 16 | ||
359 | #define UDC_EPIN_NUM_USED 5 | ||
360 | #define UDC_EPOUT_NUM 16 | ||
361 | /* EP number of EP's really used = EP0 + 8 data EP's */ | ||
362 | #define UDC_USED_EP_NUM 9 | ||
363 | /* UDC CSR regs are aligned but AHB regs not - offset for OUT EP's */ | ||
364 | #define UDC_CSR_EP_OUT_IX_OFS 12 | ||
365 | |||
366 | #define UDC_EP0OUT_IX 16 | ||
367 | #define UDC_EP0IN_IX 0 | ||
368 | |||
369 | /* Rx fifo address and size = 1k -------------------------------------------*/ | ||
370 | #define UDC_RXFIFO_ADDR 0x800 | ||
371 | #define UDC_RXFIFO_SIZE 0x400 | ||
372 | |||
373 | /* Tx fifo address and size = 1.5k -----------------------------------------*/ | ||
374 | #define UDC_TXFIFO_ADDR 0xc00 | ||
375 | #define UDC_TXFIFO_SIZE 0x600 | ||
376 | |||
377 | /* default data endpoints --------------------------------------------------*/ | ||
378 | #define UDC_EPIN_STATUS_IX 1 | ||
379 | #define UDC_EPIN_IX 2 | ||
380 | #define UDC_EPOUT_IX 18 | ||
381 | |||
382 | /* general constants -------------------------------------------------------*/ | ||
383 | #define UDC_DWORD_BYTES 4 | ||
384 | #define UDC_BITS_PER_BYTE_SHIFT 3 | ||
385 | #define UDC_BYTE_MASK 0xff | ||
386 | #define UDC_BITS_PER_BYTE 8 | ||
387 | |||
388 | /*---------------------------------------------------------------------------*/ | ||
389 | /* UDC CSR's */ | ||
390 | struct udc_csrs { | ||
391 | |||
392 | /* sca - setup command address */ | ||
393 | u32 sca; | ||
394 | |||
395 | /* ep ne's */ | ||
396 | u32 ne[UDC_USED_EP_NUM]; | ||
397 | } __attribute__ ((packed)); | ||
398 | |||
399 | /* AHB subsystem CSR registers */ | ||
400 | struct udc_regs { | ||
401 | |||
402 | /* device configuration */ | ||
403 | u32 cfg; | ||
404 | |||
405 | /* device control */ | ||
406 | u32 ctl; | ||
407 | |||
408 | /* device status */ | ||
409 | u32 sts; | ||
410 | |||
411 | /* device interrupt */ | ||
412 | u32 irqsts; | ||
413 | |||
414 | /* device interrupt mask */ | ||
415 | u32 irqmsk; | ||
416 | |||
417 | /* endpoint interrupt */ | ||
418 | u32 ep_irqsts; | ||
419 | |||
420 | /* endpoint interrupt mask */ | ||
421 | u32 ep_irqmsk; | ||
422 | } __attribute__ ((packed)); | ||
423 | |||
424 | /* endpoint specific registers */ | ||
425 | struct udc_ep_regs { | ||
426 | |||
427 | /* endpoint control */ | ||
428 | u32 ctl; | ||
429 | |||
430 | /* endpoint status */ | ||
431 | u32 sts; | ||
432 | |||
433 | /* endpoint buffer size in/ receive packet frame number out */ | ||
434 | u32 bufin_framenum; | ||
435 | |||
436 | /* endpoint buffer size out/max packet size */ | ||
437 | u32 bufout_maxpkt; | ||
438 | |||
439 | /* endpoint setup buffer pointer */ | ||
440 | u32 subptr; | ||
441 | |||
442 | /* endpoint data descriptor pointer */ | ||
443 | u32 desptr; | ||
444 | |||
445 | /* reserverd */ | ||
446 | u32 reserved; | ||
447 | |||
448 | /* write/read confirmation */ | ||
449 | u32 confirm; | ||
450 | |||
451 | } __attribute__ ((packed)); | ||
452 | |||
453 | /* control data DMA desc */ | ||
454 | struct udc_stp_dma { | ||
455 | /* status quadlet */ | ||
456 | u32 status; | ||
457 | /* reserved */ | ||
458 | u32 _reserved; | ||
459 | /* first setup word */ | ||
460 | u32 data12; | ||
461 | /* second setup word */ | ||
462 | u32 data34; | ||
463 | } __attribute__ ((aligned (16))); | ||
464 | |||
465 | /* normal data DMA desc */ | ||
466 | struct udc_data_dma { | ||
467 | /* status quadlet */ | ||
468 | u32 status; | ||
469 | /* reserved */ | ||
470 | u32 _reserved; | ||
471 | /* buffer pointer */ | ||
472 | u32 bufptr; | ||
473 | /* next descriptor pointer */ | ||
474 | u32 next; | ||
475 | } __attribute__ ((aligned (16))); | ||
476 | |||
477 | /* request packet */ | ||
478 | struct udc_request { | ||
479 | /* embedded gadget ep */ | ||
480 | struct usb_request req; | ||
481 | |||
482 | /* flags */ | ||
483 | unsigned dma_going : 1, | ||
484 | dma_mapping : 1, | ||
485 | dma_done : 1; | ||
486 | /* phys. address */ | ||
487 | dma_addr_t td_phys; | ||
488 | /* first dma desc. of chain */ | ||
489 | struct udc_data_dma *td_data; | ||
490 | /* last dma desc. of chain */ | ||
491 | struct udc_data_dma *td_data_last; | ||
492 | struct list_head queue; | ||
493 | |||
494 | /* chain length */ | ||
495 | unsigned chain_len; | ||
496 | |||
497 | }; | ||
498 | |||
499 | /* UDC specific endpoint parameters */ | ||
500 | struct udc_ep { | ||
501 | struct usb_ep ep; | ||
502 | struct udc_ep_regs __iomem *regs; | ||
503 | u32 __iomem *txfifo; | ||
504 | u32 __iomem *dma; | ||
505 | dma_addr_t td_phys; | ||
506 | dma_addr_t td_stp_dma; | ||
507 | struct udc_stp_dma *td_stp; | ||
508 | struct udc_data_dma *td; | ||
509 | /* temp request */ | ||
510 | struct udc_request *req; | ||
511 | unsigned req_used; | ||
512 | unsigned req_completed; | ||
513 | /* dummy DMA desc for BNA dummy */ | ||
514 | struct udc_request *bna_dummy_req; | ||
515 | unsigned bna_occurred; | ||
516 | |||
517 | /* NAK state */ | ||
518 | unsigned naking; | ||
519 | |||
520 | struct udc *dev; | ||
521 | |||
522 | /* queue for requests */ | ||
523 | struct list_head queue; | ||
524 | const struct usb_endpoint_descriptor *desc; | ||
525 | unsigned halted; | ||
526 | unsigned cancel_transfer; | ||
527 | unsigned num : 5, | ||
528 | fifo_depth : 14, | ||
529 | in : 1; | ||
530 | }; | ||
531 | |||
532 | /* device struct */ | ||
533 | struct udc { | ||
534 | struct usb_gadget gadget; | ||
535 | spinlock_t lock; /* protects all state */ | ||
536 | /* all endpoints */ | ||
537 | struct udc_ep ep[UDC_EP_NUM]; | ||
538 | struct usb_gadget_driver *driver; | ||
539 | /* operational flags */ | ||
540 | unsigned active : 1, | ||
541 | stall_ep0in : 1, | ||
542 | waiting_zlp_ack_ep0in : 1, | ||
543 | set_cfg_not_acked : 1, | ||
544 | irq_registered : 1, | ||
545 | data_ep_enabled : 1, | ||
546 | data_ep_queued : 1, | ||
547 | mem_region : 1, | ||
548 | sys_suspended : 1, | ||
549 | connected; | ||
550 | |||
551 | u16 chiprev; | ||
552 | |||
553 | /* registers */ | ||
554 | struct pci_dev *pdev; | ||
555 | struct udc_csrs __iomem *csr; | ||
556 | struct udc_regs __iomem *regs; | ||
557 | struct udc_ep_regs __iomem *ep_regs; | ||
558 | u32 __iomem *rxfifo; | ||
559 | u32 __iomem *txfifo; | ||
560 | |||
561 | /* DMA desc pools */ | ||
562 | struct pci_pool *data_requests; | ||
563 | struct pci_pool *stp_requests; | ||
564 | |||
565 | /* device data */ | ||
566 | unsigned long phys_addr; | ||
567 | void __iomem *virt_addr; | ||
568 | unsigned irq; | ||
569 | |||
570 | /* states */ | ||
571 | u16 cur_config; | ||
572 | u16 cur_intf; | ||
573 | u16 cur_alt; | ||
574 | }; | ||
575 | |||
576 | /* setup request data */ | ||
577 | union udc_setup_data { | ||
578 | u32 data[2]; | ||
579 | struct usb_ctrlrequest request; | ||
580 | }; | ||
581 | |||
582 | /* | ||
583 | *--------------------------------------------------------------------------- | ||
584 | * SET and GET bitfields in u32 values | ||
585 | * via constants for mask/offset: | ||
586 | * <bit_field_stub_name> is the text between | ||
587 | * UDC_ and _MASK|_OFS of appropiate | ||
588 | * constant | ||
589 | * | ||
590 | * set bitfield value in u32 u32Val | ||
591 | */ | ||
592 | #define AMD_ADDBITS(u32Val, bitfield_val, bitfield_stub_name) \ | ||
593 | (((u32Val) & (((u32) ~((u32) bitfield_stub_name##_MASK)))) \ | ||
594 | | (((bitfield_val) << ((u32) bitfield_stub_name##_OFS)) \ | ||
595 | & ((u32) bitfield_stub_name##_MASK))) | ||
596 | |||
597 | /* | ||
598 | * set bitfield value in zero-initialized u32 u32Val | ||
599 | * => bitfield bits in u32Val are all zero | ||
600 | */ | ||
601 | #define AMD_INIT_SETBITS(u32Val, bitfield_val, bitfield_stub_name) \ | ||
602 | ((u32Val) \ | ||
603 | | (((bitfield_val) << ((u32) bitfield_stub_name##_OFS)) \ | ||
604 | & ((u32) bitfield_stub_name##_MASK))) | ||
605 | |||
606 | /* get bitfield value from u32 u32Val */ | ||
607 | #define AMD_GETBITS(u32Val, bitfield_stub_name) \ | ||
608 | ((u32Val & ((u32) bitfield_stub_name##_MASK)) \ | ||
609 | >> ((u32) bitfield_stub_name##_OFS)) | ||
610 | |||
611 | /* SET and GET bits in u32 values ------------------------------------------*/ | ||
612 | #define AMD_BIT(bit_stub_name) (1 << bit_stub_name) | ||
613 | #define AMD_UNMASK_BIT(bit_stub_name) (~AMD_BIT(bit_stub_name)) | ||
614 | #define AMD_CLEAR_BIT(bit_stub_name) (~AMD_BIT(bit_stub_name)) | ||
615 | |||
616 | /* debug macros ------------------------------------------------------------*/ | ||
617 | |||
618 | #define DBG(udc , args...) dev_dbg(&(udc)->pdev->dev, args) | ||
619 | |||
620 | #ifdef UDC_VERBOSE | ||
621 | #define VDBG DBG | ||
622 | #else | ||
623 | #define VDBG(udc , args...) do {} while (0) | ||
624 | #endif | ||
625 | |||
626 | #endif /* #ifdef AMD5536UDC_H */ | ||
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index dbaf867436df..a3376739a81b 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c | |||
@@ -305,6 +305,10 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address"); | |||
305 | #define DEV_CONFIG_CDC | 305 | #define DEV_CONFIG_CDC |
306 | #endif | 306 | #endif |
307 | 307 | ||
308 | #ifdef CONFIG_USB_GADGET_AMD5536UDC | ||
309 | #define DEV_CONFIG_CDC | ||
310 | #endif | ||
311 | |||
308 | 312 | ||
309 | /*-------------------------------------------------------------------------*/ | 313 | /*-------------------------------------------------------------------------*/ |
310 | 314 | ||
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h index 53e9139ba388..f7f159c1002b 100644 --- a/drivers/usb/gadget/gadget_chips.h +++ b/drivers/usb/gadget/gadget_chips.h | |||
@@ -17,6 +17,12 @@ | |||
17 | #define gadget_is_net2280(g) 0 | 17 | #define gadget_is_net2280(g) 0 |
18 | #endif | 18 | #endif |
19 | 19 | ||
20 | #ifdef CONFIG_USB_GADGET_AMD5536UDC | ||
21 | #define gadget_is_amd5536udc(g) !strcmp("amd5536udc", (g)->name) | ||
22 | #else | ||
23 | #define gadget_is_amd5536udc(g) 0 | ||
24 | #endif | ||
25 | |||
20 | #ifdef CONFIG_USB_GADGET_DUMMY_HCD | 26 | #ifdef CONFIG_USB_GADGET_DUMMY_HCD |
21 | #define gadget_is_dummy(g) !strcmp("dummy_udc", (g)->name) | 27 | #define gadget_is_dummy(g) !strcmp("dummy_udc", (g)->name) |
22 | #else | 28 | #else |
@@ -202,7 +208,9 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget) | |||
202 | return 0x18; | 208 | return 0x18; |
203 | else if (gadget_is_fsl_usb2(gadget)) | 209 | else if (gadget_is_fsl_usb2(gadget)) |
204 | return 0x19; | 210 | return 0x19; |
205 | else if (gadget_is_m66592(gadget)) | 211 | else if (gadget_is_amd5536udc(gadget)) |
206 | return 0x20; | 212 | return 0x20; |
213 | else if (gadget_is_m66592(gadget)) | ||
214 | return 0x21; | ||
207 | return -ENOENT; | 215 | return -ENOENT; |
208 | } | 216 | } |
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c index 0174a322e007..700dda8a9157 100644 --- a/drivers/usb/gadget/m66592-udc.c +++ b/drivers/usb/gadget/m66592-udc.c | |||
@@ -21,26 +21,18 @@ | |||
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <linux/module.h> | 23 | #include <linux/module.h> |
24 | #include <linux/kernel.h> | ||
25 | #include <linux/sched.h> | ||
26 | #include <linux/smp_lock.h> | ||
27 | #include <linux/errno.h> | ||
28 | #include <linux/init.h> | ||
29 | #include <linux/timer.h> | ||
30 | #include <linux/delay.h> | ||
31 | #include <linux/list.h> | ||
32 | #include <linux/interrupt.h> | 24 | #include <linux/interrupt.h> |
25 | #include <linux/delay.h> | ||
26 | #include <linux/io.h> | ||
33 | #include <linux/platform_device.h> | 27 | #include <linux/platform_device.h> |
28 | |||
34 | #include <linux/usb/ch9.h> | 29 | #include <linux/usb/ch9.h> |
35 | #include <linux/usb_gadget.h> | 30 | #include <linux/usb_gadget.h> |
36 | 31 | ||
37 | #include <asm/io.h> | ||
38 | #include <asm/irq.h> | ||
39 | #include <asm/system.h> | ||
40 | |||
41 | #include "m66592-udc.h" | 32 | #include "m66592-udc.h" |
42 | 33 | ||
43 | MODULE_DESCRIPTION("M66592 USB gadget driiver"); | 34 | |
35 | MODULE_DESCRIPTION("M66592 USB gadget driver"); | ||
44 | MODULE_LICENSE("GPL"); | 36 | MODULE_LICENSE("GPL"); |
45 | MODULE_AUTHOR("Yoshihiro Shimoda"); | 37 | MODULE_AUTHOR("Yoshihiro Shimoda"); |
46 | 38 | ||
@@ -49,16 +41,21 @@ MODULE_AUTHOR("Yoshihiro Shimoda"); | |||
49 | /* module parameters */ | 41 | /* module parameters */ |
50 | static unsigned short clock = M66592_XTAL24; | 42 | static unsigned short clock = M66592_XTAL24; |
51 | module_param(clock, ushort, 0644); | 43 | module_param(clock, ushort, 0644); |
52 | MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0(default=16384)"); | 44 | MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0 " |
45 | "(default=16384)"); | ||
46 | |||
53 | static unsigned short vif = M66592_LDRV; | 47 | static unsigned short vif = M66592_LDRV; |
54 | module_param(vif, ushort, 0644); | 48 | module_param(vif, ushort, 0644); |
55 | MODULE_PARM_DESC(vif, "input VIF: 3.3V=32768, 1.5V=0(default=32768)"); | 49 | MODULE_PARM_DESC(vif, "input VIF: 3.3V=32768, 1.5V=0 (default=32768)"); |
56 | static unsigned short endian = 0; | 50 | |
51 | static unsigned short endian; | ||
57 | module_param(endian, ushort, 0644); | 52 | module_param(endian, ushort, 0644); |
58 | MODULE_PARM_DESC(endian, "data endian: big=256, little=0(default=0)"); | 53 | MODULE_PARM_DESC(endian, "data endian: big=256, little=0 (default=0)"); |
54 | |||
59 | static unsigned short irq_sense = M66592_INTL; | 55 | static unsigned short irq_sense = M66592_INTL; |
60 | module_param(irq_sense, ushort, 0644); | 56 | module_param(irq_sense, ushort, 0644); |
61 | MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=2, falling edge=0(default=2)"); | 57 | MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=2, falling edge=0 " |
58 | "(default=2)"); | ||
62 | 59 | ||
63 | static const char udc_name[] = "m66592_udc"; | 60 | static const char udc_name[] = "m66592_udc"; |
64 | static const char *m66592_ep_name[] = { | 61 | static const char *m66592_ep_name[] = { |
@@ -72,8 +69,8 @@ static int m66592_queue(struct usb_ep *_ep, struct usb_request *_req, | |||
72 | gfp_t gfp_flags); | 69 | gfp_t gfp_flags); |
73 | 70 | ||
74 | static void transfer_complete(struct m66592_ep *ep, | 71 | static void transfer_complete(struct m66592_ep *ep, |
75 | struct m66592_request *req, | 72 | struct m66592_request *req, int status); |
76 | int status); | 73 | |
77 | /*-------------------------------------------------------------------------*/ | 74 | /*-------------------------------------------------------------------------*/ |
78 | static inline u16 get_usb_speed(struct m66592 *m66592) | 75 | static inline u16 get_usb_speed(struct m66592 *m66592) |
79 | { | 76 | { |
@@ -81,25 +78,25 @@ static inline u16 get_usb_speed(struct m66592 *m66592) | |||
81 | } | 78 | } |
82 | 79 | ||
83 | static void enable_pipe_irq(struct m66592 *m66592, u16 pipenum, | 80 | static void enable_pipe_irq(struct m66592 *m66592, u16 pipenum, |
84 | unsigned long reg) | 81 | unsigned long reg) |
85 | { | 82 | { |
86 | u16 tmp; | 83 | u16 tmp; |
87 | 84 | ||
88 | tmp = m66592_read(m66592, M66592_INTENB0); | 85 | tmp = m66592_read(m66592, M66592_INTENB0); |
89 | m66592_bclr(m66592, M66592_BEMPE | M66592_NRDYE | M66592_BRDYE, | 86 | m66592_bclr(m66592, M66592_BEMPE | M66592_NRDYE | M66592_BRDYE, |
90 | M66592_INTENB0); | 87 | M66592_INTENB0); |
91 | m66592_bset(m66592, (1 << pipenum), reg); | 88 | m66592_bset(m66592, (1 << pipenum), reg); |
92 | m66592_write(m66592, tmp, M66592_INTENB0); | 89 | m66592_write(m66592, tmp, M66592_INTENB0); |
93 | } | 90 | } |
94 | 91 | ||
95 | static void disable_pipe_irq(struct m66592 *m66592, u16 pipenum, | 92 | static void disable_pipe_irq(struct m66592 *m66592, u16 pipenum, |
96 | unsigned long reg) | 93 | unsigned long reg) |
97 | { | 94 | { |
98 | u16 tmp; | 95 | u16 tmp; |
99 | 96 | ||
100 | tmp = m66592_read(m66592, M66592_INTENB0); | 97 | tmp = m66592_read(m66592, M66592_INTENB0); |
101 | m66592_bclr(m66592, M66592_BEMPE | M66592_NRDYE | M66592_BRDYE, | 98 | m66592_bclr(m66592, M66592_BEMPE | M66592_NRDYE | M66592_BRDYE, |
102 | M66592_INTENB0); | 99 | M66592_INTENB0); |
103 | m66592_bclr(m66592, (1 << pipenum), reg); | 100 | m66592_bclr(m66592, (1 << pipenum), reg); |
104 | m66592_write(m66592, tmp, M66592_INTENB0); | 101 | m66592_write(m66592, tmp, M66592_INTENB0); |
105 | } | 102 | } |
@@ -108,17 +105,19 @@ static void m66592_usb_connect(struct m66592 *m66592) | |||
108 | { | 105 | { |
109 | m66592_bset(m66592, M66592_CTRE, M66592_INTENB0); | 106 | m66592_bset(m66592, M66592_CTRE, M66592_INTENB0); |
110 | m66592_bset(m66592, M66592_WDST | M66592_RDST | M66592_CMPL, | 107 | m66592_bset(m66592, M66592_WDST | M66592_RDST | M66592_CMPL, |
111 | M66592_INTENB0); | 108 | M66592_INTENB0); |
112 | m66592_bset(m66592, M66592_BEMPE | M66592_BRDYE, M66592_INTENB0); | 109 | m66592_bset(m66592, M66592_BEMPE | M66592_BRDYE, M66592_INTENB0); |
113 | 110 | ||
114 | m66592_bset(m66592, M66592_DPRPU, M66592_SYSCFG); | 111 | m66592_bset(m66592, M66592_DPRPU, M66592_SYSCFG); |
115 | } | 112 | } |
116 | 113 | ||
117 | static void m66592_usb_disconnect(struct m66592 *m66592) | 114 | static void m66592_usb_disconnect(struct m66592 *m66592) |
115 | __releases(m66592->lock) | ||
116 | __acquires(m66592->lock) | ||
118 | { | 117 | { |
119 | m66592_bclr(m66592, M66592_CTRE, M66592_INTENB0); | 118 | m66592_bclr(m66592, M66592_CTRE, M66592_INTENB0); |
120 | m66592_bclr(m66592, M66592_WDST | M66592_RDST | M66592_CMPL, | 119 | m66592_bclr(m66592, M66592_WDST | M66592_RDST | M66592_CMPL, |
121 | M66592_INTENB0); | 120 | M66592_INTENB0); |
122 | m66592_bclr(m66592, M66592_BEMPE | M66592_BRDYE, M66592_INTENB0); | 121 | m66592_bclr(m66592, M66592_BEMPE | M66592_BRDYE, M66592_INTENB0); |
123 | m66592_bclr(m66592, M66592_DPRPU, M66592_SYSCFG); | 122 | m66592_bclr(m66592, M66592_DPRPU, M66592_SYSCFG); |
124 | 123 | ||
@@ -148,7 +147,7 @@ static inline u16 control_reg_get_pid(struct m66592 *m66592, u16 pipenum) | |||
148 | } | 147 | } |
149 | 148 | ||
150 | static inline void control_reg_set_pid(struct m66592 *m66592, u16 pipenum, | 149 | static inline void control_reg_set_pid(struct m66592 *m66592, u16 pipenum, |
151 | u16 pid) | 150 | u16 pid) |
152 | { | 151 | { |
153 | unsigned long offset; | 152 | unsigned long offset; |
154 | 153 | ||
@@ -250,7 +249,7 @@ static inline void pipe_change(struct m66592 *m66592, u16 pipenum) | |||
250 | } | 249 | } |
251 | 250 | ||
252 | static int pipe_buffer_setting(struct m66592 *m66592, | 251 | static int pipe_buffer_setting(struct m66592 *m66592, |
253 | struct m66592_pipe_info *info) | 252 | struct m66592_pipe_info *info) |
254 | { | 253 | { |
255 | u16 bufnum = 0, buf_bsize = 0; | 254 | u16 bufnum = 0, buf_bsize = 0; |
256 | u16 pipecfg = 0; | 255 | u16 pipecfg = 0; |
@@ -287,7 +286,7 @@ static int pipe_buffer_setting(struct m66592 *m66592, | |||
287 | } | 286 | } |
288 | if (m66592->bi_bufnum > M66592_MAX_BUFNUM) { | 287 | if (m66592->bi_bufnum > M66592_MAX_BUFNUM) { |
289 | printk(KERN_ERR "m66592 pipe memory is insufficient(%d)\n", | 288 | printk(KERN_ERR "m66592 pipe memory is insufficient(%d)\n", |
290 | m66592->bi_bufnum); | 289 | m66592->bi_bufnum); |
291 | return -ENOMEM; | 290 | return -ENOMEM; |
292 | } | 291 | } |
293 | 292 | ||
@@ -328,7 +327,7 @@ static void pipe_buffer_release(struct m66592 *m66592, | |||
328 | m66592->bulk--; | 327 | m66592->bulk--; |
329 | } else | 328 | } else |
330 | printk(KERN_ERR "ep_release: unexpect pipenum (%d)\n", | 329 | printk(KERN_ERR "ep_release: unexpect pipenum (%d)\n", |
331 | info->pipe); | 330 | info->pipe); |
332 | } | 331 | } |
333 | 332 | ||
334 | static void pipe_initialize(struct m66592_ep *ep) | 333 | static void pipe_initialize(struct m66592_ep *ep) |
@@ -350,8 +349,8 @@ static void pipe_initialize(struct m66592_ep *ep) | |||
350 | } | 349 | } |
351 | 350 | ||
352 | static void m66592_ep_setting(struct m66592 *m66592, struct m66592_ep *ep, | 351 | static void m66592_ep_setting(struct m66592 *m66592, struct m66592_ep *ep, |
353 | const struct usb_endpoint_descriptor *desc, | 352 | const struct usb_endpoint_descriptor *desc, |
354 | u16 pipenum, int dma) | 353 | u16 pipenum, int dma) |
355 | { | 354 | { |
356 | if ((pipenum != 0) && dma) { | 355 | if ((pipenum != 0) && dma) { |
357 | if (m66592->num_dma == 0) { | 356 | if (m66592->num_dma == 0) { |
@@ -385,7 +384,7 @@ static void m66592_ep_setting(struct m66592 *m66592, struct m66592_ep *ep, | |||
385 | 384 | ||
386 | ep->pipectr = get_pipectr_addr(pipenum); | 385 | ep->pipectr = get_pipectr_addr(pipenum); |
387 | ep->pipenum = pipenum; | 386 | ep->pipenum = pipenum; |
388 | ep->ep.maxpacket = desc->wMaxPacketSize; | 387 | ep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize); |
389 | m66592->pipenum2ep[pipenum] = ep; | 388 | m66592->pipenum2ep[pipenum] = ep; |
390 | m66592->epaddr2ep[desc->bEndpointAddress&USB_ENDPOINT_NUMBER_MASK] = ep; | 389 | m66592->epaddr2ep[desc->bEndpointAddress&USB_ENDPOINT_NUMBER_MASK] = ep; |
391 | INIT_LIST_HEAD(&ep->queue); | 390 | INIT_LIST_HEAD(&ep->queue); |
@@ -407,7 +406,7 @@ static void m66592_ep_release(struct m66592_ep *ep) | |||
407 | } | 406 | } |
408 | 407 | ||
409 | static int alloc_pipe_config(struct m66592_ep *ep, | 408 | static int alloc_pipe_config(struct m66592_ep *ep, |
410 | const struct usb_endpoint_descriptor *desc) | 409 | const struct usb_endpoint_descriptor *desc) |
411 | { | 410 | { |
412 | struct m66592 *m66592 = ep->m66592; | 411 | struct m66592 *m66592 = ep->m66592; |
413 | struct m66592_pipe_info info; | 412 | struct m66592_pipe_info info; |
@@ -419,15 +418,15 @@ static int alloc_pipe_config(struct m66592_ep *ep, | |||
419 | 418 | ||
420 | BUG_ON(ep->pipenum); | 419 | BUG_ON(ep->pipenum); |
421 | 420 | ||
422 | switch(desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { | 421 | switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { |
423 | case USB_ENDPOINT_XFER_BULK: | 422 | case USB_ENDPOINT_XFER_BULK: |
424 | if (m66592->bulk >= M66592_MAX_NUM_BULK) { | 423 | if (m66592->bulk >= M66592_MAX_NUM_BULK) { |
425 | if (m66592->isochronous >= M66592_MAX_NUM_ISOC) { | 424 | if (m66592->isochronous >= M66592_MAX_NUM_ISOC) { |
426 | printk(KERN_ERR "bulk pipe is insufficient\n"); | 425 | printk(KERN_ERR "bulk pipe is insufficient\n"); |
427 | return -ENODEV; | 426 | return -ENODEV; |
428 | } else { | 427 | } else { |
429 | info.pipe = M66592_BASE_PIPENUM_ISOC + | 428 | info.pipe = M66592_BASE_PIPENUM_ISOC |
430 | m66592->isochronous; | 429 | + m66592->isochronous; |
431 | counter = &m66592->isochronous; | 430 | counter = &m66592->isochronous; |
432 | } | 431 | } |
433 | } else { | 432 | } else { |
@@ -462,7 +461,7 @@ static int alloc_pipe_config(struct m66592_ep *ep, | |||
462 | ep->type = info.type; | 461 | ep->type = info.type; |
463 | 462 | ||
464 | info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; | 463 | info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; |
465 | info.maxpacket = desc->wMaxPacketSize; | 464 | info.maxpacket = le16_to_cpu(desc->wMaxPacketSize); |
466 | info.interval = desc->bInterval; | 465 | info.interval = desc->bInterval; |
467 | if (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) | 466 | if (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) |
468 | info.dir_in = 1; | 467 | info.dir_in = 1; |
@@ -525,8 +524,8 @@ static void start_ep0_write(struct m66592_ep *ep, struct m66592_request *req) | |||
525 | 524 | ||
526 | pipe_change(m66592, ep->pipenum); | 525 | pipe_change(m66592, ep->pipenum); |
527 | m66592_mdfy(m66592, M66592_ISEL | M66592_PIPE0, | 526 | m66592_mdfy(m66592, M66592_ISEL | M66592_PIPE0, |
528 | (M66592_ISEL | M66592_CURPIPE), | 527 | (M66592_ISEL | M66592_CURPIPE), |
529 | M66592_CFIFOSEL); | 528 | M66592_CFIFOSEL); |
530 | m66592_write(m66592, M66592_BCLR, ep->fifoctr); | 529 | m66592_write(m66592, M66592_BCLR, ep->fifoctr); |
531 | if (req->req.length == 0) { | 530 | if (req->req.length == 0) { |
532 | m66592_bset(m66592, M66592_BVAL, ep->fifoctr); | 531 | m66592_bset(m66592, M66592_BVAL, ep->fifoctr); |
@@ -561,8 +560,8 @@ static void start_packet_read(struct m66592_ep *ep, struct m66592_request *req) | |||
561 | 560 | ||
562 | if (ep->pipenum == 0) { | 561 | if (ep->pipenum == 0) { |
563 | m66592_mdfy(m66592, M66592_PIPE0, | 562 | m66592_mdfy(m66592, M66592_PIPE0, |
564 | (M66592_ISEL | M66592_CURPIPE), | 563 | (M66592_ISEL | M66592_CURPIPE), |
565 | M66592_CFIFOSEL); | 564 | M66592_CFIFOSEL); |
566 | m66592_write(m66592, M66592_BCLR, ep->fifoctr); | 565 | m66592_write(m66592, M66592_BCLR, ep->fifoctr); |
567 | pipe_start(m66592, pipenum); | 566 | pipe_start(m66592, pipenum); |
568 | pipe_irq_enable(m66592, pipenum); | 567 | pipe_irq_enable(m66592, pipenum); |
@@ -572,8 +571,9 @@ static void start_packet_read(struct m66592_ep *ep, struct m66592_request *req) | |||
572 | pipe_change(m66592, pipenum); | 571 | pipe_change(m66592, pipenum); |
573 | m66592_bset(m66592, M66592_TRENB, ep->fifosel); | 572 | m66592_bset(m66592, M66592_TRENB, ep->fifosel); |
574 | m66592_write(m66592, | 573 | m66592_write(m66592, |
575 | (req->req.length + ep->ep.maxpacket - 1) / | 574 | (req->req.length + ep->ep.maxpacket - 1) |
576 | ep->ep.maxpacket, ep->fifotrn); | 575 | / ep->ep.maxpacket, |
576 | ep->fifotrn); | ||
577 | } | 577 | } |
578 | pipe_start(m66592, pipenum); /* trigger once */ | 578 | pipe_start(m66592, pipenum); /* trigger once */ |
579 | pipe_irq_enable(m66592, pipenum); | 579 | pipe_irq_enable(m66592, pipenum); |
@@ -614,7 +614,7 @@ static void start_ep0(struct m66592_ep *ep, struct m66592_request *req) | |||
614 | static void init_controller(struct m66592 *m66592) | 614 | static void init_controller(struct m66592 *m66592) |
615 | { | 615 | { |
616 | m66592_bset(m66592, (vif & M66592_LDRV) | (endian & M66592_BIGEND), | 616 | m66592_bset(m66592, (vif & M66592_LDRV) | (endian & M66592_BIGEND), |
617 | M66592_PINCFG); | 617 | M66592_PINCFG); |
618 | m66592_bset(m66592, M66592_HSE, M66592_SYSCFG); /* High spd */ | 618 | m66592_bset(m66592, M66592_HSE, M66592_SYSCFG); /* High spd */ |
619 | m66592_mdfy(m66592, clock & M66592_XTAL, M66592_XTAL, M66592_SYSCFG); | 619 | m66592_mdfy(m66592, clock & M66592_XTAL, M66592_XTAL, M66592_SYSCFG); |
620 | 620 | ||
@@ -634,7 +634,7 @@ static void init_controller(struct m66592 *m66592) | |||
634 | 634 | ||
635 | m66592_bset(m66592, irq_sense & M66592_INTL, M66592_INTENB1); | 635 | m66592_bset(m66592, irq_sense & M66592_INTL, M66592_INTENB1); |
636 | m66592_write(m66592, M66592_BURST | M66592_CPU_ADR_RD_WR, | 636 | m66592_write(m66592, M66592_BURST | M66592_CPU_ADR_RD_WR, |
637 | M66592_DMA0CFG); | 637 | M66592_DMA0CFG); |
638 | } | 638 | } |
639 | 639 | ||
640 | static void disable_controller(struct m66592 *m66592) | 640 | static void disable_controller(struct m66592 *m66592) |
@@ -659,8 +659,9 @@ static void m66592_start_xclock(struct m66592 *m66592) | |||
659 | 659 | ||
660 | /*-------------------------------------------------------------------------*/ | 660 | /*-------------------------------------------------------------------------*/ |
661 | static void transfer_complete(struct m66592_ep *ep, | 661 | static void transfer_complete(struct m66592_ep *ep, |
662 | struct m66592_request *req, | 662 | struct m66592_request *req, int status) |
663 | int status) | 663 | __releases(m66592->lock) |
664 | __acquires(m66592->lock) | ||
664 | { | 665 | { |
665 | int restart = 0; | 666 | int restart = 0; |
666 | 667 | ||
@@ -680,8 +681,9 @@ static void transfer_complete(struct m66592_ep *ep, | |||
680 | if (!list_empty(&ep->queue)) | 681 | if (!list_empty(&ep->queue)) |
681 | restart = 1; | 682 | restart = 1; |
682 | 683 | ||
683 | if (likely(req->req.complete)) | 684 | spin_unlock(&ep->m66592->lock); |
684 | req->req.complete(&ep->ep, &req->req); | 685 | req->req.complete(&ep->ep, &req->req); |
686 | spin_lock(&ep->m66592->lock); | ||
685 | 687 | ||
686 | if (restart) { | 688 | if (restart) { |
687 | req = list_entry(ep->queue.next, struct m66592_request, queue); | 689 | req = list_entry(ep->queue.next, struct m66592_request, queue); |
@@ -693,7 +695,7 @@ static void transfer_complete(struct m66592_ep *ep, | |||
693 | static void irq_ep0_write(struct m66592_ep *ep, struct m66592_request *req) | 695 | static void irq_ep0_write(struct m66592_ep *ep, struct m66592_request *req) |
694 | { | 696 | { |
695 | int i; | 697 | int i; |
696 | volatile u16 tmp; | 698 | u16 tmp; |
697 | unsigned bufsize; | 699 | unsigned bufsize; |
698 | size_t size; | 700 | size_t size; |
699 | void *buf; | 701 | void *buf; |
@@ -731,8 +733,9 @@ static void irq_ep0_write(struct m66592_ep *ep, struct m66592_request *req) | |||
731 | req->req.actual += size; | 733 | req->req.actual += size; |
732 | 734 | ||
733 | /* check transfer finish */ | 735 | /* check transfer finish */ |
734 | if ((!req->req.zero && (req->req.actual == req->req.length)) || | 736 | if ((!req->req.zero && (req->req.actual == req->req.length)) |
735 | (size % ep->ep.maxpacket) || (size == 0)) { | 737 | || (size % ep->ep.maxpacket) |
738 | || (size == 0)) { | ||
736 | disable_irq_ready(m66592, pipenum); | 739 | disable_irq_ready(m66592, pipenum); |
737 | disable_irq_empty(m66592, pipenum); | 740 | disable_irq_empty(m66592, pipenum); |
738 | } else { | 741 | } else { |
@@ -768,16 +771,19 @@ static void irq_packet_write(struct m66592_ep *ep, struct m66592_request *req) | |||
768 | /* write fifo */ | 771 | /* write fifo */ |
769 | if (req->req.buf) { | 772 | if (req->req.buf) { |
770 | m66592_write_fifo(m66592, ep->fifoaddr, buf, size); | 773 | m66592_write_fifo(m66592, ep->fifoaddr, buf, size); |
771 | if ((size == 0) || ((size % ep->ep.maxpacket) != 0) || | 774 | if ((size == 0) |
772 | ((bufsize != ep->ep.maxpacket) && (bufsize > size))) | 775 | || ((size % ep->ep.maxpacket) != 0) |
776 | || ((bufsize != ep->ep.maxpacket) | ||
777 | && (bufsize > size))) | ||
773 | m66592_bset(m66592, M66592_BVAL, ep->fifoctr); | 778 | m66592_bset(m66592, M66592_BVAL, ep->fifoctr); |
774 | } | 779 | } |
775 | 780 | ||
776 | /* update parameters */ | 781 | /* update parameters */ |
777 | req->req.actual += size; | 782 | req->req.actual += size; |
778 | /* check transfer finish */ | 783 | /* check transfer finish */ |
779 | if ((!req->req.zero && (req->req.actual == req->req.length)) || | 784 | if ((!req->req.zero && (req->req.actual == req->req.length)) |
780 | (size % ep->ep.maxpacket) || (size == 0)) { | 785 | || (size % ep->ep.maxpacket) |
786 | || (size == 0)) { | ||
781 | disable_irq_ready(m66592, pipenum); | 787 | disable_irq_ready(m66592, pipenum); |
782 | enable_irq_empty(m66592, pipenum); | 788 | enable_irq_empty(m66592, pipenum); |
783 | } else { | 789 | } else { |
@@ -821,8 +827,9 @@ static void irq_packet_read(struct m66592_ep *ep, struct m66592_request *req) | |||
821 | req->req.actual += size; | 827 | req->req.actual += size; |
822 | 828 | ||
823 | /* check transfer finish */ | 829 | /* check transfer finish */ |
824 | if ((!req->req.zero && (req->req.actual == req->req.length)) || | 830 | if ((!req->req.zero && (req->req.actual == req->req.length)) |
825 | (size % ep->ep.maxpacket) || (size == 0)) { | 831 | || (size % ep->ep.maxpacket) |
832 | || (size == 0)) { | ||
826 | pipe_stop(m66592, pipenum); | 833 | pipe_stop(m66592, pipenum); |
827 | pipe_irq_disable(m66592, pipenum); | 834 | pipe_irq_disable(m66592, pipenum); |
828 | finish = 1; | 835 | finish = 1; |
@@ -850,7 +857,7 @@ static void irq_pipe_ready(struct m66592 *m66592, u16 status, u16 enb) | |||
850 | if ((status & M66592_BRDY0) && (enb & M66592_BRDY0)) { | 857 | if ((status & M66592_BRDY0) && (enb & M66592_BRDY0)) { |
851 | m66592_write(m66592, ~M66592_BRDY0, M66592_BRDYSTS); | 858 | m66592_write(m66592, ~M66592_BRDY0, M66592_BRDYSTS); |
852 | m66592_mdfy(m66592, M66592_PIPE0, M66592_CURPIPE, | 859 | m66592_mdfy(m66592, M66592_PIPE0, M66592_CURPIPE, |
853 | M66592_CFIFOSEL); | 860 | M66592_CFIFOSEL); |
854 | 861 | ||
855 | ep = &m66592->ep[0]; | 862 | ep = &m66592->ep[0]; |
856 | req = list_entry(ep->queue.next, struct m66592_request, queue); | 863 | req = list_entry(ep->queue.next, struct m66592_request, queue); |
@@ -909,23 +916,26 @@ static void irq_pipe_empty(struct m66592 *m66592, u16 status, u16 enb) | |||
909 | } | 916 | } |
910 | 917 | ||
911 | static void get_status(struct m66592 *m66592, struct usb_ctrlrequest *ctrl) | 918 | static void get_status(struct m66592 *m66592, struct usb_ctrlrequest *ctrl) |
919 | __releases(m66592->lock) | ||
920 | __acquires(m66592->lock) | ||
912 | { | 921 | { |
913 | struct m66592_ep *ep; | 922 | struct m66592_ep *ep; |
914 | u16 pid; | 923 | u16 pid; |
915 | u16 status = 0; | 924 | u16 status = 0; |
925 | u16 w_index = le16_to_cpu(ctrl->wIndex); | ||
916 | 926 | ||
917 | switch (ctrl->bRequestType & USB_RECIP_MASK) { | 927 | switch (ctrl->bRequestType & USB_RECIP_MASK) { |
918 | case USB_RECIP_DEVICE: | 928 | case USB_RECIP_DEVICE: |
919 | status = 1; /* selfpower */ | 929 | status = 1 << USB_DEVICE_SELF_POWERED; |
920 | break; | 930 | break; |
921 | case USB_RECIP_INTERFACE: | 931 | case USB_RECIP_INTERFACE: |
922 | status = 0; | 932 | status = 0; |
923 | break; | 933 | break; |
924 | case USB_RECIP_ENDPOINT: | 934 | case USB_RECIP_ENDPOINT: |
925 | ep = m66592->epaddr2ep[ctrl->wIndex&USB_ENDPOINT_NUMBER_MASK]; | 935 | ep = m66592->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK]; |
926 | pid = control_reg_get_pid(m66592, ep->pipenum); | 936 | pid = control_reg_get_pid(m66592, ep->pipenum); |
927 | if (pid == M66592_PID_STALL) | 937 | if (pid == M66592_PID_STALL) |
928 | status = 1; | 938 | status = 1 << USB_ENDPOINT_HALT; |
929 | else | 939 | else |
930 | status = 0; | 940 | status = 0; |
931 | break; | 941 | break; |
@@ -934,11 +944,13 @@ static void get_status(struct m66592 *m66592, struct usb_ctrlrequest *ctrl) | |||
934 | return; /* exit */ | 944 | return; /* exit */ |
935 | } | 945 | } |
936 | 946 | ||
937 | *m66592->ep0_buf = status; | 947 | m66592->ep0_data = cpu_to_le16(status); |
938 | m66592->ep0_req->buf = m66592->ep0_buf; | 948 | m66592->ep0_req->buf = &m66592->ep0_data; |
939 | m66592->ep0_req->length = 2; | 949 | m66592->ep0_req->length = 2; |
940 | /* AV: what happens if we get called again before that gets through? */ | 950 | /* AV: what happens if we get called again before that gets through? */ |
951 | spin_unlock(&m66592->lock); | ||
941 | m66592_queue(m66592->gadget.ep0, m66592->ep0_req, GFP_KERNEL); | 952 | m66592_queue(m66592->gadget.ep0, m66592->ep0_req, GFP_KERNEL); |
953 | spin_lock(&m66592->lock); | ||
942 | } | 954 | } |
943 | 955 | ||
944 | static void clear_feature(struct m66592 *m66592, struct usb_ctrlrequest *ctrl) | 956 | static void clear_feature(struct m66592 *m66592, struct usb_ctrlrequest *ctrl) |
@@ -953,8 +965,9 @@ static void clear_feature(struct m66592 *m66592, struct usb_ctrlrequest *ctrl) | |||
953 | case USB_RECIP_ENDPOINT: { | 965 | case USB_RECIP_ENDPOINT: { |
954 | struct m66592_ep *ep; | 966 | struct m66592_ep *ep; |
955 | struct m66592_request *req; | 967 | struct m66592_request *req; |
968 | u16 w_index = le16_to_cpu(ctrl->wIndex); | ||
956 | 969 | ||
957 | ep = m66592->epaddr2ep[ctrl->wIndex&USB_ENDPOINT_NUMBER_MASK]; | 970 | ep = m66592->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK]; |
958 | pipe_stop(m66592, ep->pipenum); | 971 | pipe_stop(m66592, ep->pipenum); |
959 | control_reg_sqclr(m66592, ep->pipenum); | 972 | control_reg_sqclr(m66592, ep->pipenum); |
960 | 973 | ||
@@ -989,8 +1002,9 @@ static void set_feature(struct m66592 *m66592, struct usb_ctrlrequest *ctrl) | |||
989 | break; | 1002 | break; |
990 | case USB_RECIP_ENDPOINT: { | 1003 | case USB_RECIP_ENDPOINT: { |
991 | struct m66592_ep *ep; | 1004 | struct m66592_ep *ep; |
1005 | u16 w_index = le16_to_cpu(ctrl->wIndex); | ||
992 | 1006 | ||
993 | ep = m66592->epaddr2ep[ctrl->wIndex&USB_ENDPOINT_NUMBER_MASK]; | 1007 | ep = m66592->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK]; |
994 | pipe_stall(m66592, ep->pipenum); | 1008 | pipe_stall(m66592, ep->pipenum); |
995 | 1009 | ||
996 | control_end(m66592, 1); | 1010 | control_end(m66592, 1); |
@@ -1066,14 +1080,16 @@ static void irq_device_state(struct m66592 *m66592) | |||
1066 | } | 1080 | } |
1067 | if (m66592->old_dvsq == M66592_DS_CNFG && dvsq != M66592_DS_CNFG) | 1081 | if (m66592->old_dvsq == M66592_DS_CNFG && dvsq != M66592_DS_CNFG) |
1068 | m66592_update_usb_speed(m66592); | 1082 | m66592_update_usb_speed(m66592); |
1069 | if ((dvsq == M66592_DS_CNFG || dvsq == M66592_DS_ADDS) && | 1083 | if ((dvsq == M66592_DS_CNFG || dvsq == M66592_DS_ADDS) |
1070 | m66592->gadget.speed == USB_SPEED_UNKNOWN) | 1084 | && m66592->gadget.speed == USB_SPEED_UNKNOWN) |
1071 | m66592_update_usb_speed(m66592); | 1085 | m66592_update_usb_speed(m66592); |
1072 | 1086 | ||
1073 | m66592->old_dvsq = dvsq; | 1087 | m66592->old_dvsq = dvsq; |
1074 | } | 1088 | } |
1075 | 1089 | ||
1076 | static void irq_control_stage(struct m66592 *m66592) | 1090 | static void irq_control_stage(struct m66592 *m66592) |
1091 | __releases(m66592->lock) | ||
1092 | __acquires(m66592->lock) | ||
1077 | { | 1093 | { |
1078 | struct usb_ctrlrequest ctrl; | 1094 | struct usb_ctrlrequest ctrl; |
1079 | u16 ctsq; | 1095 | u16 ctsq; |
@@ -1095,8 +1111,10 @@ static void irq_control_stage(struct m66592 *m66592) | |||
1095 | case M66592_CS_WRDS: | 1111 | case M66592_CS_WRDS: |
1096 | case M66592_CS_WRND: | 1112 | case M66592_CS_WRND: |
1097 | if (setup_packet(m66592, &ctrl)) { | 1113 | if (setup_packet(m66592, &ctrl)) { |
1114 | spin_unlock(&m66592->lock); | ||
1098 | if (m66592->driver->setup(&m66592->gadget, &ctrl) < 0) | 1115 | if (m66592->driver->setup(&m66592->gadget, &ctrl) < 0) |
1099 | pipe_stall(m66592, 0); | 1116 | pipe_stall(m66592, 0); |
1117 | spin_lock(&m66592->lock); | ||
1100 | } | 1118 | } |
1101 | break; | 1119 | break; |
1102 | case M66592_CS_RDSS: | 1120 | case M66592_CS_RDSS: |
@@ -1119,6 +1137,8 @@ static irqreturn_t m66592_irq(int irq, void *_m66592) | |||
1119 | u16 savepipe; | 1137 | u16 savepipe; |
1120 | u16 mask0; | 1138 | u16 mask0; |
1121 | 1139 | ||
1140 | spin_lock(&m66592->lock); | ||
1141 | |||
1122 | intsts0 = m66592_read(m66592, M66592_INTSTS0); | 1142 | intsts0 = m66592_read(m66592, M66592_INTSTS0); |
1123 | intenb0 = m66592_read(m66592, M66592_INTENB0); | 1143 | intenb0 = m66592_read(m66592, M66592_INTENB0); |
1124 | 1144 | ||
@@ -1134,27 +1154,27 @@ static irqreturn_t m66592_irq(int irq, void *_m66592) | |||
1134 | bempenb = m66592_read(m66592, M66592_BEMPENB); | 1154 | bempenb = m66592_read(m66592, M66592_BEMPENB); |
1135 | 1155 | ||
1136 | if (mask0 & M66592_VBINT) { | 1156 | if (mask0 & M66592_VBINT) { |
1137 | m66592_write(m66592, (u16)~M66592_VBINT, | 1157 | m66592_write(m66592, 0xffff & ~M66592_VBINT, |
1138 | M66592_INTSTS0); | 1158 | M66592_INTSTS0); |
1139 | m66592_start_xclock(m66592); | 1159 | m66592_start_xclock(m66592); |
1140 | 1160 | ||
1141 | /* start vbus sampling */ | 1161 | /* start vbus sampling */ |
1142 | m66592->old_vbus = m66592_read(m66592, M66592_INTSTS0) | 1162 | m66592->old_vbus = m66592_read(m66592, M66592_INTSTS0) |
1143 | & M66592_VBSTS; | 1163 | & M66592_VBSTS; |
1144 | m66592->scount = M66592_MAX_SAMPLING; | 1164 | m66592->scount = M66592_MAX_SAMPLING; |
1145 | 1165 | ||
1146 | mod_timer(&m66592->timer, | 1166 | mod_timer(&m66592->timer, |
1147 | jiffies + msecs_to_jiffies(50)); | 1167 | jiffies + msecs_to_jiffies(50)); |
1148 | } | 1168 | } |
1149 | if (intsts0 & M66592_DVSQ) | 1169 | if (intsts0 & M66592_DVSQ) |
1150 | irq_device_state(m66592); | 1170 | irq_device_state(m66592); |
1151 | 1171 | ||
1152 | if ((intsts0 & M66592_BRDY) && (intenb0 & M66592_BRDYE) && | 1172 | if ((intsts0 & M66592_BRDY) && (intenb0 & M66592_BRDYE) |
1153 | (brdysts & brdyenb)) { | 1173 | && (brdysts & brdyenb)) { |
1154 | irq_pipe_ready(m66592, brdysts, brdyenb); | 1174 | irq_pipe_ready(m66592, brdysts, brdyenb); |
1155 | } | 1175 | } |
1156 | if ((intsts0 & M66592_BEMP) && (intenb0 & M66592_BEMPE) && | 1176 | if ((intsts0 & M66592_BEMP) && (intenb0 & M66592_BEMPE) |
1157 | (bempsts & bempenb)) { | 1177 | && (bempsts & bempenb)) { |
1158 | irq_pipe_empty(m66592, bempsts, bempenb); | 1178 | irq_pipe_empty(m66592, bempsts, bempenb); |
1159 | } | 1179 | } |
1160 | 1180 | ||
@@ -1164,6 +1184,7 @@ static irqreturn_t m66592_irq(int irq, void *_m66592) | |||
1164 | 1184 | ||
1165 | m66592_write(m66592, savepipe, M66592_CFIFOSEL); | 1185 | m66592_write(m66592, savepipe, M66592_CFIFOSEL); |
1166 | 1186 | ||
1187 | spin_unlock(&m66592->lock); | ||
1167 | return IRQ_HANDLED; | 1188 | return IRQ_HANDLED; |
1168 | } | 1189 | } |
1169 | 1190 | ||
@@ -1191,13 +1212,13 @@ static void m66592_timer(unsigned long _m66592) | |||
1191 | m66592_usb_disconnect(m66592); | 1212 | m66592_usb_disconnect(m66592); |
1192 | } else { | 1213 | } else { |
1193 | mod_timer(&m66592->timer, | 1214 | mod_timer(&m66592->timer, |
1194 | jiffies + msecs_to_jiffies(50)); | 1215 | jiffies + msecs_to_jiffies(50)); |
1195 | } | 1216 | } |
1196 | } else { | 1217 | } else { |
1197 | m66592->scount = M66592_MAX_SAMPLING; | 1218 | m66592->scount = M66592_MAX_SAMPLING; |
1198 | m66592->old_vbus = tmp; | 1219 | m66592->old_vbus = tmp; |
1199 | mod_timer(&m66592->timer, | 1220 | mod_timer(&m66592->timer, |
1200 | jiffies + msecs_to_jiffies(50)); | 1221 | jiffies + msecs_to_jiffies(50)); |
1201 | } | 1222 | } |
1202 | } | 1223 | } |
1203 | spin_unlock_irqrestore(&m66592->lock, flags); | 1224 | spin_unlock_irqrestore(&m66592->lock, flags); |
@@ -1335,11 +1356,6 @@ out: | |||
1335 | return ret; | 1356 | return ret; |
1336 | } | 1357 | } |
1337 | 1358 | ||
1338 | static int m66592_fifo_status(struct usb_ep *_ep) | ||
1339 | { | ||
1340 | return -EOPNOTSUPP; | ||
1341 | } | ||
1342 | |||
1343 | static void m66592_fifo_flush(struct usb_ep *_ep) | 1359 | static void m66592_fifo_flush(struct usb_ep *_ep) |
1344 | { | 1360 | { |
1345 | struct m66592_ep *ep; | 1361 | struct m66592_ep *ep; |
@@ -1365,7 +1381,6 @@ static struct usb_ep_ops m66592_ep_ops = { | |||
1365 | .dequeue = m66592_dequeue, | 1381 | .dequeue = m66592_dequeue, |
1366 | 1382 | ||
1367 | .set_halt = m66592_set_halt, | 1383 | .set_halt = m66592_set_halt, |
1368 | .fifo_status = m66592_fifo_status, | ||
1369 | .fifo_flush = m66592_fifo_flush, | 1384 | .fifo_flush = m66592_fifo_flush, |
1370 | }; | 1385 | }; |
1371 | 1386 | ||
@@ -1377,11 +1392,10 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) | |||
1377 | struct m66592 *m66592 = the_controller; | 1392 | struct m66592 *m66592 = the_controller; |
1378 | int retval; | 1393 | int retval; |
1379 | 1394 | ||
1380 | if (!driver || | 1395 | if (!driver |
1381 | driver->speed != USB_SPEED_HIGH || | 1396 | || driver->speed != USB_SPEED_HIGH |
1382 | !driver->bind || | 1397 | || !driver->bind |
1383 | !driver->unbind || | 1398 | || !driver->setup) |
1384 | !driver->setup) | ||
1385 | return -EINVAL; | 1399 | return -EINVAL; |
1386 | if (!m66592) | 1400 | if (!m66592) |
1387 | return -ENODEV; | 1401 | return -ENODEV; |
@@ -1413,8 +1427,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver) | |||
1413 | m66592->old_vbus = m66592_read(m66592, | 1427 | m66592->old_vbus = m66592_read(m66592, |
1414 | M66592_INTSTS0) & M66592_VBSTS; | 1428 | M66592_INTSTS0) & M66592_VBSTS; |
1415 | m66592->scount = M66592_MAX_SAMPLING; | 1429 | m66592->scount = M66592_MAX_SAMPLING; |
1416 | mod_timer(&m66592->timer, | 1430 | mod_timer(&m66592->timer, jiffies + msecs_to_jiffies(50)); |
1417 | jiffies + msecs_to_jiffies(50)); | ||
1418 | } | 1431 | } |
1419 | 1432 | ||
1420 | return 0; | 1433 | return 0; |
@@ -1432,6 +1445,9 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) | |||
1432 | struct m66592 *m66592 = the_controller; | 1445 | struct m66592 *m66592 = the_controller; |
1433 | unsigned long flags; | 1446 | unsigned long flags; |
1434 | 1447 | ||
1448 | if (driver != m66592->driver || !driver->unbind) | ||
1449 | return -EINVAL; | ||
1450 | |||
1435 | spin_lock_irqsave(&m66592->lock, flags); | 1451 | spin_lock_irqsave(&m66592->lock, flags); |
1436 | if (m66592->gadget.speed != USB_SPEED_UNKNOWN) | 1452 | if (m66592->gadget.speed != USB_SPEED_UNKNOWN) |
1437 | m66592_usb_disconnect(m66592); | 1453 | m66592_usb_disconnect(m66592); |
@@ -1461,46 +1477,35 @@ static struct usb_gadget_ops m66592_gadget_ops = { | |||
1461 | .get_frame = m66592_get_frame, | 1477 | .get_frame = m66592_get_frame, |
1462 | }; | 1478 | }; |
1463 | 1479 | ||
1464 | #if defined(CONFIG_PM) | 1480 | static int __exit m66592_remove(struct platform_device *pdev) |
1465 | static int m66592_suspend(struct platform_device *pdev, pm_message_t state) | ||
1466 | { | ||
1467 | pdev->dev.power.power_state = state; | ||
1468 | return 0; | ||
1469 | } | ||
1470 | |||
1471 | static int m66592_resume(struct platform_device *pdev) | ||
1472 | { | ||
1473 | pdev->dev.power.power_state = PMSG_ON; | ||
1474 | return 0; | ||
1475 | } | ||
1476 | #else /* if defined(CONFIG_PM) */ | ||
1477 | #define m66592_suspend NULL | ||
1478 | #define m66592_resume NULL | ||
1479 | #endif | ||
1480 | |||
1481 | static int __init_or_module m66592_remove(struct platform_device *pdev) | ||
1482 | { | 1481 | { |
1483 | struct m66592 *m66592 = dev_get_drvdata(&pdev->dev); | 1482 | struct m66592 *m66592 = dev_get_drvdata(&pdev->dev); |
1484 | 1483 | ||
1485 | del_timer_sync(&m66592->timer); | 1484 | del_timer_sync(&m66592->timer); |
1486 | iounmap(m66592->reg); | 1485 | iounmap(m66592->reg); |
1487 | free_irq(platform_get_irq(pdev, 0), m66592); | 1486 | free_irq(platform_get_irq(pdev, 0), m66592); |
1487 | m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req); | ||
1488 | kfree(m66592); | 1488 | kfree(m66592); |
1489 | return 0; | 1489 | return 0; |
1490 | } | 1490 | } |
1491 | 1491 | ||
1492 | static void nop_completion(struct usb_ep *ep, struct usb_request *r) | ||
1493 | { | ||
1494 | } | ||
1495 | |||
1492 | #define resource_len(r) (((r)->end - (r)->start) + 1) | 1496 | #define resource_len(r) (((r)->end - (r)->start) + 1) |
1497 | |||
1493 | static int __init m66592_probe(struct platform_device *pdev) | 1498 | static int __init m66592_probe(struct platform_device *pdev) |
1494 | { | 1499 | { |
1495 | struct resource *res = NULL; | 1500 | struct resource *res; |
1496 | int irq = -1; | 1501 | int irq; |
1497 | void __iomem *reg = NULL; | 1502 | void __iomem *reg = NULL; |
1498 | struct m66592 *m66592 = NULL; | 1503 | struct m66592 *m66592 = NULL; |
1499 | int ret = 0; | 1504 | int ret = 0; |
1500 | int i; | 1505 | int i; |
1501 | 1506 | ||
1502 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, | 1507 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
1503 | (char *)udc_name); | 1508 | (char *)udc_name); |
1504 | if (!res) { | 1509 | if (!res) { |
1505 | ret = -ENODEV; | 1510 | ret = -ENODEV; |
1506 | printk(KERN_ERR "platform_get_resource_byname error.\n"); | 1511 | printk(KERN_ERR "platform_get_resource_byname error.\n"); |
@@ -1548,7 +1553,7 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1548 | m66592->bi_bufnum = M66592_BASE_BUFNUM; | 1553 | m66592->bi_bufnum = M66592_BASE_BUFNUM; |
1549 | 1554 | ||
1550 | ret = request_irq(irq, m66592_irq, IRQF_DISABLED | IRQF_SHARED, | 1555 | ret = request_irq(irq, m66592_irq, IRQF_DISABLED | IRQF_SHARED, |
1551 | udc_name, m66592); | 1556 | udc_name, m66592); |
1552 | if (ret < 0) { | 1557 | if (ret < 0) { |
1553 | printk(KERN_ERR "request_irq error (%d)\n", ret); | 1558 | printk(KERN_ERR "request_irq error (%d)\n", ret); |
1554 | goto clean_up; | 1559 | goto clean_up; |
@@ -1563,7 +1568,7 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1563 | if (i != 0) { | 1568 | if (i != 0) { |
1564 | INIT_LIST_HEAD(&m66592->ep[i].ep.ep_list); | 1569 | INIT_LIST_HEAD(&m66592->ep[i].ep.ep_list); |
1565 | list_add_tail(&m66592->ep[i].ep.ep_list, | 1570 | list_add_tail(&m66592->ep[i].ep.ep_list, |
1566 | &m66592->gadget.ep_list); | 1571 | &m66592->gadget.ep_list); |
1567 | } | 1572 | } |
1568 | ep->m66592 = m66592; | 1573 | ep->m66592 = m66592; |
1569 | INIT_LIST_HEAD(&ep->queue); | 1574 | INIT_LIST_HEAD(&ep->queue); |
@@ -1583,20 +1588,18 @@ static int __init m66592_probe(struct platform_device *pdev) | |||
1583 | 1588 | ||
1584 | the_controller = m66592; | 1589 | the_controller = m66592; |
1585 | 1590 | ||
1586 | /* AV: leaks */ | ||
1587 | m66592->ep0_req = m66592_alloc_request(&m66592->ep[0].ep, GFP_KERNEL); | 1591 | m66592->ep0_req = m66592_alloc_request(&m66592->ep[0].ep, GFP_KERNEL); |
1588 | if (m66592->ep0_req == NULL) | 1592 | if (m66592->ep0_req == NULL) |
1589 | goto clean_up; | 1593 | goto clean_up2; |
1590 | /* AV: leaks, and do we really need it separately allocated? */ | 1594 | m66592->ep0_req->complete = nop_completion; |
1591 | m66592->ep0_buf = kzalloc(2, GFP_KERNEL); | ||
1592 | if (m66592->ep0_buf == NULL) | ||
1593 | goto clean_up; | ||
1594 | 1595 | ||
1595 | init_controller(m66592); | 1596 | init_controller(m66592); |
1596 | 1597 | ||
1597 | printk("driver %s, %s\n", udc_name, DRIVER_VERSION); | 1598 | dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); |
1598 | return 0; | 1599 | return 0; |
1599 | 1600 | ||
1601 | clean_up2: | ||
1602 | free_irq(irq, m66592); | ||
1600 | clean_up: | 1603 | clean_up: |
1601 | if (m66592) { | 1604 | if (m66592) { |
1602 | if (m66592->ep0_req) | 1605 | if (m66592->ep0_req) |
@@ -1611,10 +1614,7 @@ clean_up: | |||
1611 | 1614 | ||
1612 | /*-------------------------------------------------------------------------*/ | 1615 | /*-------------------------------------------------------------------------*/ |
1613 | static struct platform_driver m66592_driver = { | 1616 | static struct platform_driver m66592_driver = { |
1614 | .probe = m66592_probe, | 1617 | .remove = __exit_p(m66592_remove), |
1615 | .remove = m66592_remove, | ||
1616 | .suspend = m66592_suspend, | ||
1617 | .resume = m66592_resume, | ||
1618 | .driver = { | 1618 | .driver = { |
1619 | .name = (char *) udc_name, | 1619 | .name = (char *) udc_name, |
1620 | }, | 1620 | }, |
@@ -1622,7 +1622,7 @@ static struct platform_driver m66592_driver = { | |||
1622 | 1622 | ||
1623 | static int __init m66592_udc_init(void) | 1623 | static int __init m66592_udc_init(void) |
1624 | { | 1624 | { |
1625 | return platform_driver_register(&m66592_driver); | 1625 | return platform_driver_probe(&m66592_driver, m66592_probe); |
1626 | } | 1626 | } |
1627 | module_init(m66592_udc_init); | 1627 | module_init(m66592_udc_init); |
1628 | 1628 | ||
@@ -1631,4 +1631,3 @@ static void __exit m66592_udc_cleanup(void) | |||
1631 | platform_driver_unregister(&m66592_driver); | 1631 | platform_driver_unregister(&m66592_driver); |
1632 | } | 1632 | } |
1633 | module_exit(m66592_udc_cleanup); | 1633 | module_exit(m66592_udc_cleanup); |
1634 | |||
diff --git a/drivers/usb/gadget/m66592-udc.h b/drivers/usb/gadget/m66592-udc.h index 26b54f8b8945..bfa0c645f229 100644 --- a/drivers/usb/gadget/m66592-udc.h +++ b/drivers/usb/gadget/m66592-udc.h | |||
@@ -24,73 +24,73 @@ | |||
24 | #define __M66592_UDC_H__ | 24 | #define __M66592_UDC_H__ |
25 | 25 | ||
26 | #define M66592_SYSCFG 0x00 | 26 | #define M66592_SYSCFG 0x00 |
27 | #define M66592_XTAL 0xC000 /* b15-14: Crystal selection */ | 27 | #define M66592_XTAL 0xC000 /* b15-14: Crystal selection */ |
28 | #define M66592_XTAL48 0x8000 /* 48MHz */ | 28 | #define M66592_XTAL48 0x8000 /* 48MHz */ |
29 | #define M66592_XTAL24 0x4000 /* 24MHz */ | 29 | #define M66592_XTAL24 0x4000 /* 24MHz */ |
30 | #define M66592_XTAL12 0x0000 /* 12MHz */ | 30 | #define M66592_XTAL12 0x0000 /* 12MHz */ |
31 | #define M66592_XCKE 0x2000 /* b13: External clock enable */ | 31 | #define M66592_XCKE 0x2000 /* b13: External clock enable */ |
32 | #define M66592_RCKE 0x1000 /* b12: Register clock enable */ | 32 | #define M66592_RCKE 0x1000 /* b12: Register clock enable */ |
33 | #define M66592_PLLC 0x0800 /* b11: PLL control */ | 33 | #define M66592_PLLC 0x0800 /* b11: PLL control */ |
34 | #define M66592_SCKE 0x0400 /* b10: USB clock enable */ | 34 | #define M66592_SCKE 0x0400 /* b10: USB clock enable */ |
35 | #define M66592_ATCKM 0x0100 /* b8: Automatic supply functional enable */ | 35 | #define M66592_ATCKM 0x0100 /* b8: Automatic clock supply */ |
36 | #define M66592_HSE 0x0080 /* b7: Hi-speed enable */ | 36 | #define M66592_HSE 0x0080 /* b7: Hi-speed enable */ |
37 | #define M66592_DCFM 0x0040 /* b6: Controller function select */ | 37 | #define M66592_DCFM 0x0040 /* b6: Controller function select */ |
38 | #define M66592_DMRPD 0x0020 /* b5: D- pull down control */ | 38 | #define M66592_DMRPD 0x0020 /* b5: D- pull down control */ |
39 | #define M66592_DPRPU 0x0010 /* b4: D+ pull up control */ | 39 | #define M66592_DPRPU 0x0010 /* b4: D+ pull up control */ |
40 | #define M66592_FSRPC 0x0004 /* b2: Full-speed receiver enable */ | 40 | #define M66592_FSRPC 0x0004 /* b2: Full-speed receiver enable */ |
41 | #define M66592_PCUT 0x0002 /* b1: Low power sleep enable */ | 41 | #define M66592_PCUT 0x0002 /* b1: Low power sleep enable */ |
42 | #define M66592_USBE 0x0001 /* b0: USB module operation enable */ | 42 | #define M66592_USBE 0x0001 /* b0: USB module operation enable */ |
43 | 43 | ||
44 | #define M66592_SYSSTS 0x02 | 44 | #define M66592_SYSSTS 0x02 |
45 | #define M66592_LNST 0x0003 /* b1-0: D+, D- line status */ | 45 | #define M66592_LNST 0x0003 /* b1-0: D+, D- line status */ |
46 | #define M66592_SE1 0x0003 /* SE1 */ | 46 | #define M66592_SE1 0x0003 /* SE1 */ |
47 | #define M66592_KSTS 0x0002 /* K State */ | 47 | #define M66592_KSTS 0x0002 /* K State */ |
48 | #define M66592_JSTS 0x0001 /* J State */ | 48 | #define M66592_JSTS 0x0001 /* J State */ |
49 | #define M66592_SE0 0x0000 /* SE0 */ | 49 | #define M66592_SE0 0x0000 /* SE0 */ |
50 | 50 | ||
51 | #define M66592_DVSTCTR 0x04 | 51 | #define M66592_DVSTCTR 0x04 |
52 | #define M66592_WKUP 0x0100 /* b8: Remote wakeup */ | 52 | #define M66592_WKUP 0x0100 /* b8: Remote wakeup */ |
53 | #define M66592_RWUPE 0x0080 /* b7: Remote wakeup sense */ | 53 | #define M66592_RWUPE 0x0080 /* b7: Remote wakeup sense */ |
54 | #define M66592_USBRST 0x0040 /* b6: USB reset enable */ | 54 | #define M66592_USBRST 0x0040 /* b6: USB reset enable */ |
55 | #define M66592_RESUME 0x0020 /* b5: Resume enable */ | 55 | #define M66592_RESUME 0x0020 /* b5: Resume enable */ |
56 | #define M66592_UACT 0x0010 /* b4: USB bus enable */ | 56 | #define M66592_UACT 0x0010 /* b4: USB bus enable */ |
57 | #define M66592_RHST 0x0003 /* b1-0: Reset handshake status */ | 57 | #define M66592_RHST 0x0003 /* b1-0: Reset handshake status */ |
58 | #define M66592_HSMODE 0x0003 /* Hi-Speed mode */ | 58 | #define M66592_HSMODE 0x0003 /* Hi-Speed mode */ |
59 | #define M66592_FSMODE 0x0002 /* Full-Speed mode */ | 59 | #define M66592_FSMODE 0x0002 /* Full-Speed mode */ |
60 | #define M66592_HSPROC 0x0001 /* HS handshake is processing */ | 60 | #define M66592_HSPROC 0x0001 /* HS handshake is processing */ |
61 | 61 | ||
62 | #define M66592_TESTMODE 0x06 | 62 | #define M66592_TESTMODE 0x06 |
63 | #define M66592_UTST 0x000F /* b4-0: Test select */ | 63 | #define M66592_UTST 0x000F /* b4-0: Test select */ |
64 | #define M66592_H_TST_PACKET 0x000C /* HOST TEST Packet */ | 64 | #define M66592_H_TST_PACKET 0x000C /* HOST TEST Packet */ |
65 | #define M66592_H_TST_SE0_NAK 0x000B /* HOST TEST SE0 NAK */ | 65 | #define M66592_H_TST_SE0_NAK 0x000B /* HOST TEST SE0 NAK */ |
66 | #define M66592_H_TST_K 0x000A /* HOST TEST K */ | 66 | #define M66592_H_TST_K 0x000A /* HOST TEST K */ |
67 | #define M66592_H_TST_J 0x0009 /* HOST TEST J */ | 67 | #define M66592_H_TST_J 0x0009 /* HOST TEST J */ |
68 | #define M66592_H_TST_NORMAL 0x0000 /* HOST Normal Mode */ | 68 | #define M66592_H_TST_NORMAL 0x0000 /* HOST Normal Mode */ |
69 | #define M66592_P_TST_PACKET 0x0004 /* PERI TEST Packet */ | 69 | #define M66592_P_TST_PACKET 0x0004 /* PERI TEST Packet */ |
70 | #define M66592_P_TST_SE0_NAK 0x0003 /* PERI TEST SE0 NAK */ | 70 | #define M66592_P_TST_SE0_NAK 0x0003 /* PERI TEST SE0 NAK */ |
71 | #define M66592_P_TST_K 0x0002 /* PERI TEST K */ | 71 | #define M66592_P_TST_K 0x0002 /* PERI TEST K */ |
72 | #define M66592_P_TST_J 0x0001 /* PERI TEST J */ | 72 | #define M66592_P_TST_J 0x0001 /* PERI TEST J */ |
73 | #define M66592_P_TST_NORMAL 0x0000 /* PERI Normal Mode */ | 73 | #define M66592_P_TST_NORMAL 0x0000 /* PERI Normal Mode */ |
74 | 74 | ||
75 | #define M66592_PINCFG 0x0A | 75 | #define M66592_PINCFG 0x0A |
76 | #define M66592_LDRV 0x8000 /* b15: Drive Current Adjust */ | 76 | #define M66592_LDRV 0x8000 /* b15: Drive Current Adjust */ |
77 | #define M66592_BIGEND 0x0100 /* b8: Big endian mode */ | 77 | #define M66592_BIGEND 0x0100 /* b8: Big endian mode */ |
78 | 78 | ||
79 | #define M66592_DMA0CFG 0x0C | 79 | #define M66592_DMA0CFG 0x0C |
80 | #define M66592_DMA1CFG 0x0E | 80 | #define M66592_DMA1CFG 0x0E |
81 | #define M66592_DREQA 0x4000 /* b14: Dreq active select */ | 81 | #define M66592_DREQA 0x4000 /* b14: Dreq active select */ |
82 | #define M66592_BURST 0x2000 /* b13: Burst mode */ | 82 | #define M66592_BURST 0x2000 /* b13: Burst mode */ |
83 | #define M66592_DACKA 0x0400 /* b10: Dack active select */ | 83 | #define M66592_DACKA 0x0400 /* b10: Dack active select */ |
84 | #define M66592_DFORM 0x0380 /* b9-7: DMA mode select */ | 84 | #define M66592_DFORM 0x0380 /* b9-7: DMA mode select */ |
85 | #define M66592_CPU_ADR_RD_WR 0x0000 /* Address + RD/WR mode (CPU bus) */ | 85 | #define M66592_CPU_ADR_RD_WR 0x0000 /* Address + RD/WR mode (CPU bus) */ |
86 | #define M66592_CPU_DACK_RD_WR 0x0100 /* DACK + RD/WR mode (CPU bus) */ | 86 | #define M66592_CPU_DACK_RD_WR 0x0100 /* DACK + RD/WR mode (CPU bus) */ |
87 | #define M66592_CPU_DACK_ONLY 0x0180 /* DACK only mode (CPU bus) */ | 87 | #define M66592_CPU_DACK_ONLY 0x0180 /* DACK only mode (CPU bus) */ |
88 | #define M66592_SPLIT_DACK_ONLY 0x0200 /* DACK only mode (SPLIT bus) */ | 88 | #define M66592_SPLIT_DACK_ONLY 0x0200 /* DACK only mode (SPLIT bus) */ |
89 | #define M66592_SPLIT_DACK_DSTB 0x0300 /* DACK + DSTB0 mode (SPLIT bus) */ | 89 | #define M66592_SPLIT_DACK_DSTB 0x0300 /* DACK + DSTB0 mode (SPLIT bus) */ |
90 | #define M66592_DENDA 0x0040 /* b6: Dend active select */ | 90 | #define M66592_DENDA 0x0040 /* b6: Dend active select */ |
91 | #define M66592_PKTM 0x0020 /* b5: Packet mode */ | 91 | #define M66592_PKTM 0x0020 /* b5: Packet mode */ |
92 | #define M66592_DENDE 0x0010 /* b4: Dend enable */ | 92 | #define M66592_DENDE 0x0010 /* b4: Dend enable */ |
93 | #define M66592_OBUS 0x0004 /* b2: OUTbus mode */ | 93 | #define M66592_OBUS 0x0004 /* b2: OUTbus mode */ |
94 | 94 | ||
95 | #define M66592_CFIFO 0x10 | 95 | #define M66592_CFIFO 0x10 |
96 | #define M66592_D0FIFO 0x14 | 96 | #define M66592_D0FIFO 0x14 |
@@ -99,300 +99,300 @@ | |||
99 | #define M66592_CFIFOSEL 0x1E | 99 | #define M66592_CFIFOSEL 0x1E |
100 | #define M66592_D0FIFOSEL 0x24 | 100 | #define M66592_D0FIFOSEL 0x24 |
101 | #define M66592_D1FIFOSEL 0x2A | 101 | #define M66592_D1FIFOSEL 0x2A |
102 | #define M66592_RCNT 0x8000 /* b15: Read count mode */ | 102 | #define M66592_RCNT 0x8000 /* b15: Read count mode */ |
103 | #define M66592_REW 0x4000 /* b14: Buffer rewind */ | 103 | #define M66592_REW 0x4000 /* b14: Buffer rewind */ |
104 | #define M66592_DCLRM 0x2000 /* b13: DMA buffer clear mode */ | 104 | #define M66592_DCLRM 0x2000 /* b13: DMA buffer clear mode */ |
105 | #define M66592_DREQE 0x1000 /* b12: DREQ output enable */ | 105 | #define M66592_DREQE 0x1000 /* b12: DREQ output enable */ |
106 | #define M66592_MBW 0x0400 /* b10: Maximum bit width for FIFO access */ | 106 | #define M66592_MBW 0x0400 /* b10: Maximum bit width for FIFO */ |
107 | #define M66592_MBW_8 0x0000 /* 8bit */ | 107 | #define M66592_MBW_8 0x0000 /* 8bit */ |
108 | #define M66592_MBW_16 0x0400 /* 16bit */ | 108 | #define M66592_MBW_16 0x0400 /* 16bit */ |
109 | #define M66592_TRENB 0x0200 /* b9: Transaction counter enable */ | 109 | #define M66592_TRENB 0x0200 /* b9: Transaction counter enable */ |
110 | #define M66592_TRCLR 0x0100 /* b8: Transaction counter clear */ | 110 | #define M66592_TRCLR 0x0100 /* b8: Transaction counter clear */ |
111 | #define M66592_DEZPM 0x0080 /* b7: Zero-length packet additional mode */ | 111 | #define M66592_DEZPM 0x0080 /* b7: Zero-length packet mode */ |
112 | #define M66592_ISEL 0x0020 /* b5: DCP FIFO port direction select */ | 112 | #define M66592_ISEL 0x0020 /* b5: DCP FIFO port direction select */ |
113 | #define M66592_CURPIPE 0x0007 /* b2-0: PIPE select */ | 113 | #define M66592_CURPIPE 0x0007 /* b2-0: PIPE select */ |
114 | 114 | ||
115 | #define M66592_CFIFOCTR 0x20 | 115 | #define M66592_CFIFOCTR 0x20 |
116 | #define M66592_D0FIFOCTR 0x26 | 116 | #define M66592_D0FIFOCTR 0x26 |
117 | #define M66592_D1FIFOCTR 0x2c | 117 | #define M66592_D1FIFOCTR 0x2c |
118 | #define M66592_BVAL 0x8000 /* b15: Buffer valid flag */ | 118 | #define M66592_BVAL 0x8000 /* b15: Buffer valid flag */ |
119 | #define M66592_BCLR 0x4000 /* b14: Buffer clear */ | 119 | #define M66592_BCLR 0x4000 /* b14: Buffer clear */ |
120 | #define M66592_FRDY 0x2000 /* b13: FIFO ready */ | 120 | #define M66592_FRDY 0x2000 /* b13: FIFO ready */ |
121 | #define M66592_DTLN 0x0FFF /* b11-0: FIFO received data length */ | 121 | #define M66592_DTLN 0x0FFF /* b11-0: FIFO received data length */ |
122 | 122 | ||
123 | #define M66592_CFIFOSIE 0x22 | 123 | #define M66592_CFIFOSIE 0x22 |
124 | #define M66592_TGL 0x8000 /* b15: Buffer toggle */ | 124 | #define M66592_TGL 0x8000 /* b15: Buffer toggle */ |
125 | #define M66592_SCLR 0x4000 /* b14: Buffer clear */ | 125 | #define M66592_SCLR 0x4000 /* b14: Buffer clear */ |
126 | #define M66592_SBUSY 0x2000 /* b13: SIE_FIFO busy */ | 126 | #define M66592_SBUSY 0x2000 /* b13: SIE_FIFO busy */ |
127 | 127 | ||
128 | #define M66592_D0FIFOTRN 0x28 | 128 | #define M66592_D0FIFOTRN 0x28 |
129 | #define M66592_D1FIFOTRN 0x2E | 129 | #define M66592_D1FIFOTRN 0x2E |
130 | #define M66592_TRNCNT 0xFFFF /* b15-0: Transaction counter */ | 130 | #define M66592_TRNCNT 0xFFFF /* b15-0: Transaction counter */ |
131 | 131 | ||
132 | #define M66592_INTENB0 0x30 | 132 | #define M66592_INTENB0 0x30 |
133 | #define M66592_VBSE 0x8000 /* b15: VBUS interrupt */ | 133 | #define M66592_VBSE 0x8000 /* b15: VBUS interrupt */ |
134 | #define M66592_RSME 0x4000 /* b14: Resume interrupt */ | 134 | #define M66592_RSME 0x4000 /* b14: Resume interrupt */ |
135 | #define M66592_SOFE 0x2000 /* b13: Frame update interrupt */ | 135 | #define M66592_SOFE 0x2000 /* b13: Frame update interrupt */ |
136 | #define M66592_DVSE 0x1000 /* b12: Device state transition interrupt */ | 136 | #define M66592_DVSE 0x1000 /* b12: Device state transition interrupt */ |
137 | #define M66592_CTRE 0x0800 /* b11: Control transfer stage transition interrupt */ | 137 | #define M66592_CTRE 0x0800 /* b11: Control transfer stage transition irq */ |
138 | #define M66592_BEMPE 0x0400 /* b10: Buffer empty interrupt */ | 138 | #define M66592_BEMPE 0x0400 /* b10: Buffer empty interrupt */ |
139 | #define M66592_NRDYE 0x0200 /* b9: Buffer not ready interrupt */ | 139 | #define M66592_NRDYE 0x0200 /* b9: Buffer not ready interrupt */ |
140 | #define M66592_BRDYE 0x0100 /* b8: Buffer ready interrupt */ | 140 | #define M66592_BRDYE 0x0100 /* b8: Buffer ready interrupt */ |
141 | #define M66592_URST 0x0080 /* b7: USB reset detected interrupt */ | 141 | #define M66592_URST 0x0080 /* b7: USB reset detected interrupt */ |
142 | #define M66592_SADR 0x0040 /* b6: Set address executed interrupt */ | 142 | #define M66592_SADR 0x0040 /* b6: Set address executed interrupt */ |
143 | #define M66592_SCFG 0x0020 /* b5: Set configuration executed interrupt */ | 143 | #define M66592_SCFG 0x0020 /* b5: Set configuration executed interrupt */ |
144 | #define M66592_SUSP 0x0010 /* b4: Suspend detected interrupt */ | 144 | #define M66592_SUSP 0x0010 /* b4: Suspend detected interrupt */ |
145 | #define M66592_WDST 0x0008 /* b3: Control write data stage completed interrupt */ | 145 | #define M66592_WDST 0x0008 /* b3: Control write data stage completed irq */ |
146 | #define M66592_RDST 0x0004 /* b2: Control read data stage completed interrupt */ | 146 | #define M66592_RDST 0x0004 /* b2: Control read data stage completed irq */ |
147 | #define M66592_CMPL 0x0002 /* b1: Control transfer complete interrupt */ | 147 | #define M66592_CMPL 0x0002 /* b1: Control transfer complete interrupt */ |
148 | #define M66592_SERR 0x0001 /* b0: Sequence error interrupt */ | 148 | #define M66592_SERR 0x0001 /* b0: Sequence error interrupt */ |
149 | 149 | ||
150 | #define M66592_INTENB1 0x32 | 150 | #define M66592_INTENB1 0x32 |
151 | #define M66592_BCHGE 0x4000 /* b14: USB us chenge interrupt */ | 151 | #define M66592_BCHGE 0x4000 /* b14: USB us chenge interrupt */ |
152 | #define M66592_DTCHE 0x1000 /* b12: Detach sense interrupt */ | 152 | #define M66592_DTCHE 0x1000 /* b12: Detach sense interrupt */ |
153 | #define M66592_SIGNE 0x0020 /* b5: SETUP IGNORE interrupt */ | 153 | #define M66592_SIGNE 0x0020 /* b5: SETUP IGNORE interrupt */ |
154 | #define M66592_SACKE 0x0010 /* b4: SETUP ACK interrupt */ | 154 | #define M66592_SACKE 0x0010 /* b4: SETUP ACK interrupt */ |
155 | #define M66592_BRDYM 0x0004 /* b2: BRDY clear timing */ | 155 | #define M66592_BRDYM 0x0004 /* b2: BRDY clear timing */ |
156 | #define M66592_INTL 0x0002 /* b1: Interrupt sense select */ | 156 | #define M66592_INTL 0x0002 /* b1: Interrupt sense select */ |
157 | #define M66592_PCSE 0x0001 /* b0: PCUT enable by CS assert */ | 157 | #define M66592_PCSE 0x0001 /* b0: PCUT enable by CS assert */ |
158 | 158 | ||
159 | #define M66592_BRDYENB 0x36 | 159 | #define M66592_BRDYENB 0x36 |
160 | #define M66592_BRDYSTS 0x46 | 160 | #define M66592_BRDYSTS 0x46 |
161 | #define M66592_BRDY7 0x0080 /* b7: PIPE7 */ | 161 | #define M66592_BRDY7 0x0080 /* b7: PIPE7 */ |
162 | #define M66592_BRDY6 0x0040 /* b6: PIPE6 */ | 162 | #define M66592_BRDY6 0x0040 /* b6: PIPE6 */ |
163 | #define M66592_BRDY5 0x0020 /* b5: PIPE5 */ | 163 | #define M66592_BRDY5 0x0020 /* b5: PIPE5 */ |
164 | #define M66592_BRDY4 0x0010 /* b4: PIPE4 */ | 164 | #define M66592_BRDY4 0x0010 /* b4: PIPE4 */ |
165 | #define M66592_BRDY3 0x0008 /* b3: PIPE3 */ | 165 | #define M66592_BRDY3 0x0008 /* b3: PIPE3 */ |
166 | #define M66592_BRDY2 0x0004 /* b2: PIPE2 */ | 166 | #define M66592_BRDY2 0x0004 /* b2: PIPE2 */ |
167 | #define M66592_BRDY1 0x0002 /* b1: PIPE1 */ | 167 | #define M66592_BRDY1 0x0002 /* b1: PIPE1 */ |
168 | #define M66592_BRDY0 0x0001 /* b1: PIPE0 */ | 168 | #define M66592_BRDY0 0x0001 /* b1: PIPE0 */ |
169 | 169 | ||
170 | #define M66592_NRDYENB 0x38 | 170 | #define M66592_NRDYENB 0x38 |
171 | #define M66592_NRDYSTS 0x48 | 171 | #define M66592_NRDYSTS 0x48 |
172 | #define M66592_NRDY7 0x0080 /* b7: PIPE7 */ | 172 | #define M66592_NRDY7 0x0080 /* b7: PIPE7 */ |
173 | #define M66592_NRDY6 0x0040 /* b6: PIPE6 */ | 173 | #define M66592_NRDY6 0x0040 /* b6: PIPE6 */ |
174 | #define M66592_NRDY5 0x0020 /* b5: PIPE5 */ | 174 | #define M66592_NRDY5 0x0020 /* b5: PIPE5 */ |
175 | #define M66592_NRDY4 0x0010 /* b4: PIPE4 */ | 175 | #define M66592_NRDY4 0x0010 /* b4: PIPE4 */ |
176 | #define M66592_NRDY3 0x0008 /* b3: PIPE3 */ | 176 | #define M66592_NRDY3 0x0008 /* b3: PIPE3 */ |
177 | #define M66592_NRDY2 0x0004 /* b2: PIPE2 */ | 177 | #define M66592_NRDY2 0x0004 /* b2: PIPE2 */ |
178 | #define M66592_NRDY1 0x0002 /* b1: PIPE1 */ | 178 | #define M66592_NRDY1 0x0002 /* b1: PIPE1 */ |
179 | #define M66592_NRDY0 0x0001 /* b1: PIPE0 */ | 179 | #define M66592_NRDY0 0x0001 /* b1: PIPE0 */ |
180 | 180 | ||
181 | #define M66592_BEMPENB 0x3A | 181 | #define M66592_BEMPENB 0x3A |
182 | #define M66592_BEMPSTS 0x4A | 182 | #define M66592_BEMPSTS 0x4A |
183 | #define M66592_BEMP7 0x0080 /* b7: PIPE7 */ | 183 | #define M66592_BEMP7 0x0080 /* b7: PIPE7 */ |
184 | #define M66592_BEMP6 0x0040 /* b6: PIPE6 */ | 184 | #define M66592_BEMP6 0x0040 /* b6: PIPE6 */ |
185 | #define M66592_BEMP5 0x0020 /* b5: PIPE5 */ | 185 | #define M66592_BEMP5 0x0020 /* b5: PIPE5 */ |
186 | #define M66592_BEMP4 0x0010 /* b4: PIPE4 */ | 186 | #define M66592_BEMP4 0x0010 /* b4: PIPE4 */ |
187 | #define M66592_BEMP3 0x0008 /* b3: PIPE3 */ | 187 | #define M66592_BEMP3 0x0008 /* b3: PIPE3 */ |
188 | #define M66592_BEMP2 0x0004 /* b2: PIPE2 */ | 188 | #define M66592_BEMP2 0x0004 /* b2: PIPE2 */ |
189 | #define M66592_BEMP1 0x0002 /* b1: PIPE1 */ | 189 | #define M66592_BEMP1 0x0002 /* b1: PIPE1 */ |
190 | #define M66592_BEMP0 0x0001 /* b0: PIPE0 */ | 190 | #define M66592_BEMP0 0x0001 /* b0: PIPE0 */ |
191 | 191 | ||
192 | #define M66592_SOFCFG 0x3C | 192 | #define M66592_SOFCFG 0x3C |
193 | #define M66592_SOFM 0x000C /* b3-2: SOF palse mode */ | 193 | #define M66592_SOFM 0x000C /* b3-2: SOF palse mode */ |
194 | #define M66592_SOF_125US 0x0008 /* SOF OUT 125us uFrame Signal */ | 194 | #define M66592_SOF_125US 0x0008 /* SOF OUT 125us uFrame Signal */ |
195 | #define M66592_SOF_1MS 0x0004 /* SOF OUT 1ms Frame Signal */ | 195 | #define M66592_SOF_1MS 0x0004 /* SOF OUT 1ms Frame Signal */ |
196 | #define M66592_SOF_DISABLE 0x0000 /* SOF OUT Disable */ | 196 | #define M66592_SOF_DISABLE 0x0000 /* SOF OUT Disable */ |
197 | 197 | ||
198 | #define M66592_INTSTS0 0x40 | 198 | #define M66592_INTSTS0 0x40 |
199 | #define M66592_VBINT 0x8000 /* b15: VBUS interrupt */ | 199 | #define M66592_VBINT 0x8000 /* b15: VBUS interrupt */ |
200 | #define M66592_RESM 0x4000 /* b14: Resume interrupt */ | 200 | #define M66592_RESM 0x4000 /* b14: Resume interrupt */ |
201 | #define M66592_SOFR 0x2000 /* b13: SOF frame update interrupt */ | 201 | #define M66592_SOFR 0x2000 /* b13: SOF frame update interrupt */ |
202 | #define M66592_DVST 0x1000 /* b12: Device state transition interrupt */ | 202 | #define M66592_DVST 0x1000 /* b12: Device state transition */ |
203 | #define M66592_CTRT 0x0800 /* b11: Control transfer stage transition interrupt */ | 203 | #define M66592_CTRT 0x0800 /* b11: Control stage transition */ |
204 | #define M66592_BEMP 0x0400 /* b10: Buffer empty interrupt */ | 204 | #define M66592_BEMP 0x0400 /* b10: Buffer empty interrupt */ |
205 | #define M66592_NRDY 0x0200 /* b9: Buffer not ready interrupt */ | 205 | #define M66592_NRDY 0x0200 /* b9: Buffer not ready interrupt */ |
206 | #define M66592_BRDY 0x0100 /* b8: Buffer ready interrupt */ | 206 | #define M66592_BRDY 0x0100 /* b8: Buffer ready interrupt */ |
207 | #define M66592_VBSTS 0x0080 /* b7: VBUS input port */ | 207 | #define M66592_VBSTS 0x0080 /* b7: VBUS input port */ |
208 | #define M66592_DVSQ 0x0070 /* b6-4: Device state */ | 208 | #define M66592_DVSQ 0x0070 /* b6-4: Device state */ |
209 | #define M66592_DS_SPD_CNFG 0x0070 /* Suspend Configured */ | 209 | #define M66592_DS_SPD_CNFG 0x0070 /* Suspend Configured */ |
210 | #define M66592_DS_SPD_ADDR 0x0060 /* Suspend Address */ | 210 | #define M66592_DS_SPD_ADDR 0x0060 /* Suspend Address */ |
211 | #define M66592_DS_SPD_DFLT 0x0050 /* Suspend Default */ | 211 | #define M66592_DS_SPD_DFLT 0x0050 /* Suspend Default */ |
212 | #define M66592_DS_SPD_POWR 0x0040 /* Suspend Powered */ | 212 | #define M66592_DS_SPD_POWR 0x0040 /* Suspend Powered */ |
213 | #define M66592_DS_SUSP 0x0040 /* Suspend */ | 213 | #define M66592_DS_SUSP 0x0040 /* Suspend */ |
214 | #define M66592_DS_CNFG 0x0030 /* Configured */ | 214 | #define M66592_DS_CNFG 0x0030 /* Configured */ |
215 | #define M66592_DS_ADDS 0x0020 /* Address */ | 215 | #define M66592_DS_ADDS 0x0020 /* Address */ |
216 | #define M66592_DS_DFLT 0x0010 /* Default */ | 216 | #define M66592_DS_DFLT 0x0010 /* Default */ |
217 | #define M66592_DS_POWR 0x0000 /* Powered */ | 217 | #define M66592_DS_POWR 0x0000 /* Powered */ |
218 | #define M66592_DVSQS 0x0030 /* b5-4: Device state */ | 218 | #define M66592_DVSQS 0x0030 /* b5-4: Device state */ |
219 | #define M66592_VALID 0x0008 /* b3: Setup packet detected flag */ | 219 | #define M66592_VALID 0x0008 /* b3: Setup packet detected flag */ |
220 | #define M66592_CTSQ 0x0007 /* b2-0: Control transfer stage */ | 220 | #define M66592_CTSQ 0x0007 /* b2-0: Control transfer stage */ |
221 | #define M66592_CS_SQER 0x0006 /* Sequence error */ | 221 | #define M66592_CS_SQER 0x0006 /* Sequence error */ |
222 | #define M66592_CS_WRND 0x0005 /* Control write nodata status stage */ | 222 | #define M66592_CS_WRND 0x0005 /* Control write nodata status */ |
223 | #define M66592_CS_WRSS 0x0004 /* Control write status stage */ | 223 | #define M66592_CS_WRSS 0x0004 /* Control write status stage */ |
224 | #define M66592_CS_WRDS 0x0003 /* Control write data stage */ | 224 | #define M66592_CS_WRDS 0x0003 /* Control write data stage */ |
225 | #define M66592_CS_RDSS 0x0002 /* Control read status stage */ | 225 | #define M66592_CS_RDSS 0x0002 /* Control read status stage */ |
226 | #define M66592_CS_RDDS 0x0001 /* Control read data stage */ | 226 | #define M66592_CS_RDDS 0x0001 /* Control read data stage */ |
227 | #define M66592_CS_IDST 0x0000 /* Idle or setup stage */ | 227 | #define M66592_CS_IDST 0x0000 /* Idle or setup stage */ |
228 | 228 | ||
229 | #define M66592_INTSTS1 0x42 | 229 | #define M66592_INTSTS1 0x42 |
230 | #define M66592_BCHG 0x4000 /* b14: USB bus chenge interrupt */ | 230 | #define M66592_BCHG 0x4000 /* b14: USB bus chenge interrupt */ |
231 | #define M66592_DTCH 0x1000 /* b12: Detach sense interrupt */ | 231 | #define M66592_DTCH 0x1000 /* b12: Detach sense interrupt */ |
232 | #define M66592_SIGN 0x0020 /* b5: SETUP IGNORE interrupt */ | 232 | #define M66592_SIGN 0x0020 /* b5: SETUP IGNORE interrupt */ |
233 | #define M66592_SACK 0x0010 /* b4: SETUP ACK interrupt */ | 233 | #define M66592_SACK 0x0010 /* b4: SETUP ACK interrupt */ |
234 | 234 | ||
235 | #define M66592_FRMNUM 0x4C | 235 | #define M66592_FRMNUM 0x4C |
236 | #define M66592_OVRN 0x8000 /* b15: Overrun error */ | 236 | #define M66592_OVRN 0x8000 /* b15: Overrun error */ |
237 | #define M66592_CRCE 0x4000 /* b14: Received data error */ | 237 | #define M66592_CRCE 0x4000 /* b14: Received data error */ |
238 | #define M66592_SOFRM 0x0800 /* b11: SOF output mode */ | 238 | #define M66592_SOFRM 0x0800 /* b11: SOF output mode */ |
239 | #define M66592_FRNM 0x07FF /* b10-0: Frame number */ | 239 | #define M66592_FRNM 0x07FF /* b10-0: Frame number */ |
240 | 240 | ||
241 | #define M66592_UFRMNUM 0x4E | 241 | #define M66592_UFRMNUM 0x4E |
242 | #define M66592_UFRNM 0x0007 /* b2-0: Micro frame number */ | 242 | #define M66592_UFRNM 0x0007 /* b2-0: Micro frame number */ |
243 | 243 | ||
244 | #define M66592_RECOVER 0x50 | 244 | #define M66592_RECOVER 0x50 |
245 | #define M66592_STSRECOV 0x0700 /* Status recovery */ | 245 | #define M66592_STSRECOV 0x0700 /* Status recovery */ |
246 | #define M66592_STSR_HI 0x0400 /* FULL(0) or HI(1) Speed */ | 246 | #define M66592_STSR_HI 0x0400 /* FULL(0) or HI(1) Speed */ |
247 | #define M66592_STSR_DEFAULT 0x0100 /* Default state */ | 247 | #define M66592_STSR_DEFAULT 0x0100 /* Default state */ |
248 | #define M66592_STSR_ADDRESS 0x0200 /* Address state */ | 248 | #define M66592_STSR_ADDRESS 0x0200 /* Address state */ |
249 | #define M66592_STSR_CONFIG 0x0300 /* Configured state */ | 249 | #define M66592_STSR_CONFIG 0x0300 /* Configured state */ |
250 | #define M66592_USBADDR 0x007F /* b6-0: USB address */ | 250 | #define M66592_USBADDR 0x007F /* b6-0: USB address */ |
251 | 251 | ||
252 | #define M66592_USBREQ 0x54 | 252 | #define M66592_USBREQ 0x54 |
253 | #define M66592_bRequest 0xFF00 /* b15-8: bRequest */ | 253 | #define M66592_bRequest 0xFF00 /* b15-8: bRequest */ |
254 | #define M66592_GET_STATUS 0x0000 | 254 | #define M66592_GET_STATUS 0x0000 |
255 | #define M66592_CLEAR_FEATURE 0x0100 | 255 | #define M66592_CLEAR_FEATURE 0x0100 |
256 | #define M66592_ReqRESERVED 0x0200 | 256 | #define M66592_ReqRESERVED 0x0200 |
257 | #define M66592_SET_FEATURE 0x0300 | 257 | #define M66592_SET_FEATURE 0x0300 |
258 | #define M66592_ReqRESERVED1 0x0400 | 258 | #define M66592_ReqRESERVED1 0x0400 |
259 | #define M66592_SET_ADDRESS 0x0500 | 259 | #define M66592_SET_ADDRESS 0x0500 |
260 | #define M66592_GET_DESCRIPTOR 0x0600 | 260 | #define M66592_GET_DESCRIPTOR 0x0600 |
261 | #define M66592_SET_DESCRIPTOR 0x0700 | 261 | #define M66592_SET_DESCRIPTOR 0x0700 |
262 | #define M66592_GET_CONFIGURATION 0x0800 | 262 | #define M66592_GET_CONFIGURATION 0x0800 |
263 | #define M66592_SET_CONFIGURATION 0x0900 | 263 | #define M66592_SET_CONFIGURATION 0x0900 |
264 | #define M66592_GET_INTERFACE 0x0A00 | 264 | #define M66592_GET_INTERFACE 0x0A00 |
265 | #define M66592_SET_INTERFACE 0x0B00 | 265 | #define M66592_SET_INTERFACE 0x0B00 |
266 | #define M66592_SYNCH_FRAME 0x0C00 | 266 | #define M66592_SYNCH_FRAME 0x0C00 |
267 | #define M66592_bmRequestType 0x00FF /* b7-0: bmRequestType */ | 267 | #define M66592_bmRequestType 0x00FF /* b7-0: bmRequestType */ |
268 | #define M66592_bmRequestTypeDir 0x0080 /* b7 : Data transfer direction */ | 268 | #define M66592_bmRequestTypeDir 0x0080 /* b7 : Data direction */ |
269 | #define M66592_HOST_TO_DEVICE 0x0000 | 269 | #define M66592_HOST_TO_DEVICE 0x0000 |
270 | #define M66592_DEVICE_TO_HOST 0x0080 | 270 | #define M66592_DEVICE_TO_HOST 0x0080 |
271 | #define M66592_bmRequestTypeType 0x0060 /* b6-5: Type */ | 271 | #define M66592_bmRequestTypeType 0x0060 /* b6-5: Type */ |
272 | #define M66592_STANDARD 0x0000 | 272 | #define M66592_STANDARD 0x0000 |
273 | #define M66592_CLASS 0x0020 | 273 | #define M66592_CLASS 0x0020 |
274 | #define M66592_VENDOR 0x0040 | 274 | #define M66592_VENDOR 0x0040 |
275 | #define M66592_bmRequestTypeRecip 0x001F /* b4-0: Recipient */ | 275 | #define M66592_bmRequestTypeRecip 0x001F /* b4-0: Recipient */ |
276 | #define M66592_DEVICE 0x0000 | 276 | #define M66592_DEVICE 0x0000 |
277 | #define M66592_INTERFACE 0x0001 | 277 | #define M66592_INTERFACE 0x0001 |
278 | #define M66592_ENDPOINT 0x0002 | 278 | #define M66592_ENDPOINT 0x0002 |
279 | 279 | ||
280 | #define M66592_USBVAL 0x56 | 280 | #define M66592_USBVAL 0x56 |
281 | #define M66592_wValue 0xFFFF /* b15-0: wValue */ | 281 | #define M66592_wValue 0xFFFF /* b15-0: wValue */ |
282 | /* Standard Feature Selector */ | 282 | /* Standard Feature Selector */ |
283 | #define M66592_ENDPOINT_HALT 0x0000 | 283 | #define M66592_ENDPOINT_HALT 0x0000 |
284 | #define M66592_DEVICE_REMOTE_WAKEUP 0x0001 | 284 | #define M66592_DEVICE_REMOTE_WAKEUP 0x0001 |
285 | #define M66592_TEST_MODE 0x0002 | 285 | #define M66592_TEST_MODE 0x0002 |
286 | /* Descriptor Types */ | 286 | /* Descriptor Types */ |
287 | #define M66592_DT_TYPE 0xFF00 | 287 | #define M66592_DT_TYPE 0xFF00 |
288 | #define M66592_GET_DT_TYPE(v) (((v) & DT_TYPE) >> 8) | 288 | #define M66592_GET_DT_TYPE(v) (((v) & DT_TYPE) >> 8) |
289 | #define M66592_DT_DEVICE 0x01 | 289 | #define M66592_DT_DEVICE 0x01 |
290 | #define M66592_DT_CONFIGURATION 0x02 | 290 | #define M66592_DT_CONFIGURATION 0x02 |
291 | #define M66592_DT_STRING 0x03 | 291 | #define M66592_DT_STRING 0x03 |
292 | #define M66592_DT_INTERFACE 0x04 | 292 | #define M66592_DT_INTERFACE 0x04 |
293 | #define M66592_DT_ENDPOINT 0x05 | 293 | #define M66592_DT_ENDPOINT 0x05 |
294 | #define M66592_DT_DEVICE_QUALIFIER 0x06 | 294 | #define M66592_DT_DEVICE_QUALIFIER 0x06 |
295 | #define M66592_DT_OTHER_SPEED_CONFIGURATION 0x07 | 295 | #define M66592_DT_OTHER_SPEED_CONFIGURATION 0x07 |
296 | #define M66592_DT_INTERFACE_POWER 0x08 | 296 | #define M66592_DT_INTERFACE_POWER 0x08 |
297 | #define M66592_DT_INDEX 0x00FF | 297 | #define M66592_DT_INDEX 0x00FF |
298 | #define M66592_CONF_NUM 0x00FF | 298 | #define M66592_CONF_NUM 0x00FF |
299 | #define M66592_ALT_SET 0x00FF | 299 | #define M66592_ALT_SET 0x00FF |
300 | 300 | ||
301 | #define M66592_USBINDEX 0x58 | 301 | #define M66592_USBINDEX 0x58 |
302 | #define M66592_wIndex 0xFFFF /* b15-0: wIndex */ | 302 | #define M66592_wIndex 0xFFFF /* b15-0: wIndex */ |
303 | #define M66592_TEST_SELECT 0xFF00 /* b15-b8: Test Mode Selectors */ | 303 | #define M66592_TEST_SELECT 0xFF00 /* b15-b8: Test Mode */ |
304 | #define M66592_TEST_J 0x0100 /* Test_J */ | 304 | #define M66592_TEST_J 0x0100 /* Test_J */ |
305 | #define M66592_TEST_K 0x0200 /* Test_K */ | 305 | #define M66592_TEST_K 0x0200 /* Test_K */ |
306 | #define M66592_TEST_SE0_NAK 0x0300 /* Test_SE0_NAK */ | 306 | #define M66592_TEST_SE0_NAK 0x0300 /* Test_SE0_NAK */ |
307 | #define M66592_TEST_PACKET 0x0400 /* Test_Packet */ | 307 | #define M66592_TEST_PACKET 0x0400 /* Test_Packet */ |
308 | #define M66592_TEST_FORCE_ENABLE 0x0500 /* Test_Force_Enable */ | 308 | #define M66592_TEST_FORCE_ENABLE 0x0500 /* Test_Force_Enable */ |
309 | #define M66592_TEST_STSelectors 0x0600 /* Standard test selectors */ | 309 | #define M66592_TEST_STSelectors 0x0600 /* Standard test selectors */ |
310 | #define M66592_TEST_Reserved 0x4000 /* Reserved */ | 310 | #define M66592_TEST_Reserved 0x4000 /* Reserved */ |
311 | #define M66592_TEST_VSTModes 0xC000 /* Vendor-specific test modes */ | 311 | #define M66592_TEST_VSTModes 0xC000 /* Vendor-specific tests */ |
312 | #define M66592_EP_DIR 0x0080 /* b7: Endpoint Direction */ | 312 | #define M66592_EP_DIR 0x0080 /* b7: Endpoint Direction */ |
313 | #define M66592_EP_DIR_IN 0x0080 | 313 | #define M66592_EP_DIR_IN 0x0080 |
314 | #define M66592_EP_DIR_OUT 0x0000 | 314 | #define M66592_EP_DIR_OUT 0x0000 |
315 | 315 | ||
316 | #define M66592_USBLENG 0x5A | 316 | #define M66592_USBLENG 0x5A |
317 | #define M66592_wLength 0xFFFF /* b15-0: wLength */ | 317 | #define M66592_wLength 0xFFFF /* b15-0: wLength */ |
318 | 318 | ||
319 | #define M66592_DCPCFG 0x5C | 319 | #define M66592_DCPCFG 0x5C |
320 | #define M66592_CNTMD 0x0100 /* b8: Continuous transfer mode select */ | 320 | #define M66592_CNTMD 0x0100 /* b8: Continuous transfer mode */ |
321 | #define M66592_DIR 0x0010 /* b4: Control transfer DIR select */ | 321 | #define M66592_DIR 0x0010 /* b4: Control transfer DIR select */ |
322 | 322 | ||
323 | #define M66592_DCPMAXP 0x5E | 323 | #define M66592_DCPMAXP 0x5E |
324 | #define M66592_DEVSEL 0xC000 /* b15-14: Device address select */ | 324 | #define M66592_DEVSEL 0xC000 /* b15-14: Device address select */ |
325 | #define M66592_DEVICE_0 0x0000 /* Device address 0 */ | 325 | #define M66592_DEVICE_0 0x0000 /* Device address 0 */ |
326 | #define M66592_DEVICE_1 0x4000 /* Device address 1 */ | 326 | #define M66592_DEVICE_1 0x4000 /* Device address 1 */ |
327 | #define M66592_DEVICE_2 0x8000 /* Device address 2 */ | 327 | #define M66592_DEVICE_2 0x8000 /* Device address 2 */ |
328 | #define M66592_DEVICE_3 0xC000 /* Device address 3 */ | 328 | #define M66592_DEVICE_3 0xC000 /* Device address 3 */ |
329 | #define M66592_MAXP 0x007F /* b6-0: Maxpacket size of default control pipe */ | 329 | #define M66592_MAXP 0x007F /* b6-0: Maxpacket size of ep0 */ |
330 | 330 | ||
331 | #define M66592_DCPCTR 0x60 | 331 | #define M66592_DCPCTR 0x60 |
332 | #define M66592_BSTS 0x8000 /* b15: Buffer status */ | 332 | #define M66592_BSTS 0x8000 /* b15: Buffer status */ |
333 | #define M66592_SUREQ 0x4000 /* b14: Send USB request */ | 333 | #define M66592_SUREQ 0x4000 /* b14: Send USB request */ |
334 | #define M66592_SQCLR 0x0100 /* b8: Sequence toggle bit clear */ | 334 | #define M66592_SQCLR 0x0100 /* b8: Sequence toggle bit clear */ |
335 | #define M66592_SQSET 0x0080 /* b7: Sequence toggle bit set */ | 335 | #define M66592_SQSET 0x0080 /* b7: Sequence toggle bit set */ |
336 | #define M66592_SQMON 0x0040 /* b6: Sequence toggle bit monitor */ | 336 | #define M66592_SQMON 0x0040 /* b6: Sequence toggle bit monitor */ |
337 | #define M66592_CCPL 0x0004 /* b2: Enable control transfer complete */ | 337 | #define M66592_CCPL 0x0004 /* b2: control transfer complete */ |
338 | #define M66592_PID 0x0003 /* b1-0: Response PID */ | 338 | #define M66592_PID 0x0003 /* b1-0: Response PID */ |
339 | #define M66592_PID_STALL 0x0002 /* STALL */ | 339 | #define M66592_PID_STALL 0x0002 /* STALL */ |
340 | #define M66592_PID_BUF 0x0001 /* BUF */ | 340 | #define M66592_PID_BUF 0x0001 /* BUF */ |
341 | #define M66592_PID_NAK 0x0000 /* NAK */ | 341 | #define M66592_PID_NAK 0x0000 /* NAK */ |
342 | 342 | ||
343 | #define M66592_PIPESEL 0x64 | 343 | #define M66592_PIPESEL 0x64 |
344 | #define M66592_PIPENM 0x0007 /* b2-0: Pipe select */ | 344 | #define M66592_PIPENM 0x0007 /* b2-0: Pipe select */ |
345 | #define M66592_PIPE0 0x0000 /* PIPE 0 */ | 345 | #define M66592_PIPE0 0x0000 /* PIPE 0 */ |
346 | #define M66592_PIPE1 0x0001 /* PIPE 1 */ | 346 | #define M66592_PIPE1 0x0001 /* PIPE 1 */ |
347 | #define M66592_PIPE2 0x0002 /* PIPE 2 */ | 347 | #define M66592_PIPE2 0x0002 /* PIPE 2 */ |
348 | #define M66592_PIPE3 0x0003 /* PIPE 3 */ | 348 | #define M66592_PIPE3 0x0003 /* PIPE 3 */ |
349 | #define M66592_PIPE4 0x0004 /* PIPE 4 */ | 349 | #define M66592_PIPE4 0x0004 /* PIPE 4 */ |
350 | #define M66592_PIPE5 0x0005 /* PIPE 5 */ | 350 | #define M66592_PIPE5 0x0005 /* PIPE 5 */ |
351 | #define M66592_PIPE6 0x0006 /* PIPE 6 */ | 351 | #define M66592_PIPE6 0x0006 /* PIPE 6 */ |
352 | #define M66592_PIPE7 0x0007 /* PIPE 7 */ | 352 | #define M66592_PIPE7 0x0007 /* PIPE 7 */ |
353 | 353 | ||
354 | #define M66592_PIPECFG 0x66 | 354 | #define M66592_PIPECFG 0x66 |
355 | #define M66592_TYP 0xC000 /* b15-14: Transfer type */ | 355 | #define M66592_TYP 0xC000 /* b15-14: Transfer type */ |
356 | #define M66592_ISO 0xC000 /* Isochronous */ | 356 | #define M66592_ISO 0xC000 /* Isochronous */ |
357 | #define M66592_INT 0x8000 /* Interrupt */ | 357 | #define M66592_INT 0x8000 /* Interrupt */ |
358 | #define M66592_BULK 0x4000 /* Bulk */ | 358 | #define M66592_BULK 0x4000 /* Bulk */ |
359 | #define M66592_BFRE 0x0400 /* b10: Buffer ready interrupt mode select */ | 359 | #define M66592_BFRE 0x0400 /* b10: Buffer ready interrupt mode */ |
360 | #define M66592_DBLB 0x0200 /* b9: Double buffer mode select */ | 360 | #define M66592_DBLB 0x0200 /* b9: Double buffer mode select */ |
361 | #define M66592_CNTMD 0x0100 /* b8: Continuous transfer mode select */ | 361 | #define M66592_CNTMD 0x0100 /* b8: Continuous transfer mode */ |
362 | #define M66592_SHTNAK 0x0080 /* b7: Transfer end NAK */ | 362 | #define M66592_SHTNAK 0x0080 /* b7: Transfer end NAK */ |
363 | #define M66592_DIR 0x0010 /* b4: Transfer direction select */ | 363 | #define M66592_DIR 0x0010 /* b4: Transfer direction select */ |
364 | #define M66592_DIR_H_OUT 0x0010 /* HOST OUT */ | 364 | #define M66592_DIR_H_OUT 0x0010 /* HOST OUT */ |
365 | #define M66592_DIR_P_IN 0x0010 /* PERI IN */ | 365 | #define M66592_DIR_P_IN 0x0010 /* PERI IN */ |
366 | #define M66592_DIR_H_IN 0x0000 /* HOST IN */ | 366 | #define M66592_DIR_H_IN 0x0000 /* HOST IN */ |
367 | #define M66592_DIR_P_OUT 0x0000 /* PERI OUT */ | 367 | #define M66592_DIR_P_OUT 0x0000 /* PERI OUT */ |
368 | #define M66592_EPNUM 0x000F /* b3-0: Eendpoint number select */ | 368 | #define M66592_EPNUM 0x000F /* b3-0: Eendpoint number select */ |
369 | #define M66592_EP1 0x0001 | 369 | #define M66592_EP1 0x0001 |
370 | #define M66592_EP2 0x0002 | 370 | #define M66592_EP2 0x0002 |
371 | #define M66592_EP3 0x0003 | 371 | #define M66592_EP3 0x0003 |
372 | #define M66592_EP4 0x0004 | 372 | #define M66592_EP4 0x0004 |
373 | #define M66592_EP5 0x0005 | 373 | #define M66592_EP5 0x0005 |
374 | #define M66592_EP6 0x0006 | 374 | #define M66592_EP6 0x0006 |
375 | #define M66592_EP7 0x0007 | 375 | #define M66592_EP7 0x0007 |
376 | #define M66592_EP8 0x0008 | 376 | #define M66592_EP8 0x0008 |
377 | #define M66592_EP9 0x0009 | 377 | #define M66592_EP9 0x0009 |
378 | #define M66592_EP10 0x000A | 378 | #define M66592_EP10 0x000A |
379 | #define M66592_EP11 0x000B | 379 | #define M66592_EP11 0x000B |
380 | #define M66592_EP12 0x000C | 380 | #define M66592_EP12 0x000C |
381 | #define M66592_EP13 0x000D | 381 | #define M66592_EP13 0x000D |
382 | #define M66592_EP14 0x000E | 382 | #define M66592_EP14 0x000E |
383 | #define M66592_EP15 0x000F | 383 | #define M66592_EP15 0x000F |
384 | 384 | ||
385 | #define M66592_PIPEBUF 0x68 | 385 | #define M66592_PIPEBUF 0x68 |
386 | #define M66592_BUFSIZE 0x7C00 /* b14-10: Pipe buffer size */ | 386 | #define M66592_BUFSIZE 0x7C00 /* b14-10: Pipe buffer size */ |
387 | #define M66592_BUF_SIZE(x) ((((x) / 64) - 1) << 10) | 387 | #define M66592_BUF_SIZE(x) ((((x) / 64) - 1) << 10) |
388 | #define M66592_BUFNMB 0x00FF /* b7-0: Pipe buffer number */ | 388 | #define M66592_BUFNMB 0x00FF /* b7-0: Pipe buffer number */ |
389 | 389 | ||
390 | #define M66592_PIPEMAXP 0x6A | 390 | #define M66592_PIPEMAXP 0x6A |
391 | #define M66592_MXPS 0x07FF /* b10-0: Maxpacket size */ | 391 | #define M66592_MXPS 0x07FF /* b10-0: Maxpacket size */ |
392 | 392 | ||
393 | #define M66592_PIPEPERI 0x6C | 393 | #define M66592_PIPEPERI 0x6C |
394 | #define M66592_IFIS 0x1000 /* b12: Isochronous in-buffer flush mode select */ | 394 | #define M66592_IFIS 0x1000 /* b12: ISO in-buffer flush mode */ |
395 | #define M66592_IITV 0x0007 /* b2-0: Isochronous interval */ | 395 | #define M66592_IITV 0x0007 /* b2-0: ISO interval */ |
396 | 396 | ||
397 | #define M66592_PIPE1CTR 0x70 | 397 | #define M66592_PIPE1CTR 0x70 |
398 | #define M66592_PIPE2CTR 0x72 | 398 | #define M66592_PIPE2CTR 0x72 |
@@ -401,19 +401,17 @@ | |||
401 | #define M66592_PIPE5CTR 0x78 | 401 | #define M66592_PIPE5CTR 0x78 |
402 | #define M66592_PIPE6CTR 0x7A | 402 | #define M66592_PIPE6CTR 0x7A |
403 | #define M66592_PIPE7CTR 0x7C | 403 | #define M66592_PIPE7CTR 0x7C |
404 | #define M66592_BSTS 0x8000 /* b15: Buffer status */ | 404 | #define M66592_BSTS 0x8000 /* b15: Buffer status */ |
405 | #define M66592_INBUFM 0x4000 /* b14: IN buffer monitor (Only for PIPE1 to 5) */ | 405 | #define M66592_INBUFM 0x4000 /* b14: IN buffer monitor (PIPE 1-5) */ |
406 | #define M66592_ACLRM 0x0200 /* b9: Out buffer auto clear mode */ | 406 | #define M66592_ACLRM 0x0200 /* b9: Out buffer auto clear mode */ |
407 | #define M66592_SQCLR 0x0100 /* b8: Sequence toggle bit clear */ | 407 | #define M66592_SQCLR 0x0100 /* b8: Sequence toggle bit clear */ |
408 | #define M66592_SQSET 0x0080 /* b7: Sequence toggle bit set */ | 408 | #define M66592_SQSET 0x0080 /* b7: Sequence toggle bit set */ |
409 | #define M66592_SQMON 0x0040 /* b6: Sequence toggle bit monitor */ | 409 | #define M66592_SQMON 0x0040 /* b6: Sequence toggle bit monitor */ |
410 | #define M66592_PID 0x0003 /* b1-0: Response PID */ | 410 | #define M66592_PID 0x0003 /* b1-0: Response PID */ |
411 | 411 | ||
412 | #define M66592_INVALID_REG 0x7E | 412 | #define M66592_INVALID_REG 0x7E |
413 | 413 | ||
414 | 414 | ||
415 | #define __iomem | ||
416 | |||
417 | #define get_pipectr_addr(pipenum) (M66592_PIPE1CTR + (pipenum - 1) * 2) | 415 | #define get_pipectr_addr(pipenum) (M66592_PIPE1CTR + (pipenum - 1) * 2) |
418 | 416 | ||
419 | #define M66592_MAX_SAMPLING 10 | 417 | #define M66592_MAX_SAMPLING 10 |
@@ -449,7 +447,7 @@ struct m66592_ep { | |||
449 | struct m66592 *m66592; | 447 | struct m66592 *m66592; |
450 | 448 | ||
451 | struct list_head queue; | 449 | struct list_head queue; |
452 | unsigned busy:1; | 450 | unsigned busy:1; |
453 | unsigned internal_ccpl:1; /* use only control */ | 451 | unsigned internal_ccpl:1; /* use only control */ |
454 | 452 | ||
455 | /* this member can able to after m66592_enable */ | 453 | /* this member can able to after m66592_enable */ |
@@ -477,7 +475,7 @@ struct m66592 { | |||
477 | struct m66592_ep *epaddr2ep[16]; | 475 | struct m66592_ep *epaddr2ep[16]; |
478 | 476 | ||
479 | struct usb_request *ep0_req; /* for internal request */ | 477 | struct usb_request *ep0_req; /* for internal request */ |
480 | u16 *ep0_buf; /* for internal request */ | 478 | u16 ep0_data; /* for internal request */ |
481 | 479 | ||
482 | struct timer_list timer; | 480 | struct timer_list timer; |
483 | 481 | ||
@@ -527,8 +525,8 @@ static inline u16 m66592_read(struct m66592 *m66592, unsigned long offset) | |||
527 | } | 525 | } |
528 | 526 | ||
529 | static inline void m66592_read_fifo(struct m66592 *m66592, | 527 | static inline void m66592_read_fifo(struct m66592 *m66592, |
530 | unsigned long offset, | 528 | unsigned long offset, |
531 | void *buf, unsigned long len) | 529 | void *buf, unsigned long len) |
532 | { | 530 | { |
533 | unsigned long fifoaddr = (unsigned long)m66592->reg + offset; | 531 | unsigned long fifoaddr = (unsigned long)m66592->reg + offset; |
534 | 532 | ||
@@ -543,8 +541,8 @@ static inline void m66592_write(struct m66592 *m66592, u16 val, | |||
543 | } | 541 | } |
544 | 542 | ||
545 | static inline void m66592_write_fifo(struct m66592 *m66592, | 543 | static inline void m66592_write_fifo(struct m66592 *m66592, |
546 | unsigned long offset, | 544 | unsigned long offset, |
547 | void *buf, unsigned long len) | 545 | void *buf, unsigned long len) |
548 | { | 546 | { |
549 | unsigned long fifoaddr = (unsigned long)m66592->reg + offset; | 547 | unsigned long fifoaddr = (unsigned long)m66592->reg + offset; |
550 | unsigned long odd = len & 0x0001; | 548 | unsigned long odd = len & 0x0001; |
@@ -558,7 +556,7 @@ static inline void m66592_write_fifo(struct m66592 *m66592, | |||
558 | } | 556 | } |
559 | 557 | ||
560 | static inline void m66592_mdfy(struct m66592 *m66592, u16 val, u16 pat, | 558 | static inline void m66592_mdfy(struct m66592 *m66592, u16 val, u16 pat, |
561 | unsigned long offset) | 559 | unsigned long offset) |
562 | { | 560 | { |
563 | u16 tmp; | 561 | u16 tmp; |
564 | tmp = m66592_read(m66592, offset); | 562 | tmp = m66592_read(m66592, offset); |
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c index 38138bb9ddb0..9cd98e73dc1d 100644 --- a/drivers/usb/gadget/serial.c +++ b/drivers/usb/gadget/serial.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/device.h> | 33 | #include <linux/device.h> |
34 | #include <linux/tty.h> | 34 | #include <linux/tty.h> |
35 | #include <linux/tty_flip.h> | 35 | #include <linux/tty_flip.h> |
36 | #include <linux/mutex.h> | ||
36 | 37 | ||
37 | #include <asm/byteorder.h> | 38 | #include <asm/byteorder.h> |
38 | #include <asm/io.h> | 39 | #include <asm/io.h> |
@@ -258,7 +259,7 @@ static const char *EP_IN_NAME; | |||
258 | static const char *EP_OUT_NAME; | 259 | static const char *EP_OUT_NAME; |
259 | static const char *EP_NOTIFY_NAME; | 260 | static const char *EP_NOTIFY_NAME; |
260 | 261 | ||
261 | static struct semaphore gs_open_close_sem[GS_NUM_PORTS]; | 262 | static struct mutex gs_open_close_lock[GS_NUM_PORTS]; |
262 | 263 | ||
263 | static unsigned int read_q_size = GS_DEFAULT_READ_Q_SIZE; | 264 | static unsigned int read_q_size = GS_DEFAULT_READ_Q_SIZE; |
264 | static unsigned int write_q_size = GS_DEFAULT_WRITE_Q_SIZE; | 265 | static unsigned int write_q_size = GS_DEFAULT_WRITE_Q_SIZE; |
@@ -595,7 +596,7 @@ static int __init gs_module_init(void) | |||
595 | tty_set_operations(gs_tty_driver, &gs_tty_ops); | 596 | tty_set_operations(gs_tty_driver, &gs_tty_ops); |
596 | 597 | ||
597 | for (i=0; i < GS_NUM_PORTS; i++) | 598 | for (i=0; i < GS_NUM_PORTS; i++) |
598 | sema_init(&gs_open_close_sem[i], 1); | 599 | mutex_init(&gs_open_close_lock[i]); |
599 | 600 | ||
600 | retval = tty_register_driver(gs_tty_driver); | 601 | retval = tty_register_driver(gs_tty_driver); |
601 | if (retval) { | 602 | if (retval) { |
@@ -635,7 +636,7 @@ static int gs_open(struct tty_struct *tty, struct file *file) | |||
635 | struct gs_port *port; | 636 | struct gs_port *port; |
636 | struct gs_dev *dev; | 637 | struct gs_dev *dev; |
637 | struct gs_buf *buf; | 638 | struct gs_buf *buf; |
638 | struct semaphore *sem; | 639 | struct mutex *mtx; |
639 | int ret; | 640 | int ret; |
640 | 641 | ||
641 | port_num = tty->index; | 642 | port_num = tty->index; |
@@ -656,10 +657,10 @@ static int gs_open(struct tty_struct *tty, struct file *file) | |||
656 | return -ENODEV; | 657 | return -ENODEV; |
657 | } | 658 | } |
658 | 659 | ||
659 | sem = &gs_open_close_sem[port_num]; | 660 | mtx = &gs_open_close_lock[port_num]; |
660 | if (down_interruptible(sem)) { | 661 | if (mutex_lock_interruptible(mtx)) { |
661 | printk(KERN_ERR | 662 | printk(KERN_ERR |
662 | "gs_open: (%d,%p,%p) interrupted waiting for semaphore\n", | 663 | "gs_open: (%d,%p,%p) interrupted waiting for mutex\n", |
663 | port_num, tty, file); | 664 | port_num, tty, file); |
664 | return -ERESTARTSYS; | 665 | return -ERESTARTSYS; |
665 | } | 666 | } |
@@ -754,12 +755,12 @@ static int gs_open(struct tty_struct *tty, struct file *file) | |||
754 | 755 | ||
755 | exit_unlock_port: | 756 | exit_unlock_port: |
756 | spin_unlock_irqrestore(&port->port_lock, flags); | 757 | spin_unlock_irqrestore(&port->port_lock, flags); |
757 | up(sem); | 758 | mutex_unlock(mtx); |
758 | return ret; | 759 | return ret; |
759 | 760 | ||
760 | exit_unlock_dev: | 761 | exit_unlock_dev: |
761 | spin_unlock_irqrestore(&dev->dev_lock, flags); | 762 | spin_unlock_irqrestore(&dev->dev_lock, flags); |
762 | up(sem); | 763 | mutex_unlock(mtx); |
763 | return ret; | 764 | return ret; |
764 | 765 | ||
765 | } | 766 | } |
@@ -781,7 +782,7 @@ exit_unlock_dev: | |||
781 | static void gs_close(struct tty_struct *tty, struct file *file) | 782 | static void gs_close(struct tty_struct *tty, struct file *file) |
782 | { | 783 | { |
783 | struct gs_port *port = tty->driver_data; | 784 | struct gs_port *port = tty->driver_data; |
784 | struct semaphore *sem; | 785 | struct mutex *mtx; |
785 | 786 | ||
786 | if (port == NULL) { | 787 | if (port == NULL) { |
787 | printk(KERN_ERR "gs_close: NULL port pointer\n"); | 788 | printk(KERN_ERR "gs_close: NULL port pointer\n"); |
@@ -790,8 +791,8 @@ static void gs_close(struct tty_struct *tty, struct file *file) | |||
790 | 791 | ||
791 | gs_debug("gs_close: (%d,%p,%p)\n", port->port_num, tty, file); | 792 | gs_debug("gs_close: (%d,%p,%p)\n", port->port_num, tty, file); |
792 | 793 | ||
793 | sem = &gs_open_close_sem[port->port_num]; | 794 | mtx = &gs_open_close_lock[port->port_num]; |
794 | down(sem); | 795 | mutex_lock(mtx); |
795 | 796 | ||
796 | spin_lock_irq(&port->port_lock); | 797 | spin_lock_irq(&port->port_lock); |
797 | 798 | ||
@@ -846,7 +847,7 @@ static void gs_close(struct tty_struct *tty, struct file *file) | |||
846 | 847 | ||
847 | exit: | 848 | exit: |
848 | spin_unlock_irq(&port->port_lock); | 849 | spin_unlock_irq(&port->port_lock); |
849 | up(sem); | 850 | mutex_unlock(mtx); |
850 | } | 851 | } |
851 | 852 | ||
852 | /* | 853 | /* |
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c index 46873f2534b5..5c851a36de72 100644 --- a/drivers/usb/host/isp116x-hcd.c +++ b/drivers/usb/host/isp116x-hcd.c | |||
@@ -228,7 +228,6 @@ static void preproc_atl_queue(struct isp116x *isp116x) | |||
228 | struct urb, urb_list); | 228 | struct urb, urb_list); |
229 | ptd = &ep->ptd; | 229 | ptd = &ep->ptd; |
230 | len = ep->length; | 230 | len = ep->length; |
231 | spin_lock(&urb->lock); | ||
232 | ep->data = (unsigned char *)urb->transfer_buffer | 231 | ep->data = (unsigned char *)urb->transfer_buffer |
233 | + urb->actual_length; | 232 | + urb->actual_length; |
234 | 233 | ||
@@ -264,7 +263,6 @@ static void preproc_atl_queue(struct isp116x *isp116x) | |||
264 | | PTD_EP(ep->epnum); | 263 | | PTD_EP(ep->epnum); |
265 | ptd->len = PTD_LEN(len) | PTD_DIR(dir); | 264 | ptd->len = PTD_LEN(len) | PTD_DIR(dir); |
266 | ptd->faddr = PTD_FA(usb_pipedevice(urb->pipe)); | 265 | ptd->faddr = PTD_FA(usb_pipedevice(urb->pipe)); |
267 | spin_unlock(&urb->lock); | ||
268 | if (!ep->active) { | 266 | if (!ep->active) { |
269 | ptd->mps |= PTD_LAST_MSK; | 267 | ptd->mps |= PTD_LAST_MSK; |
270 | isp116x->atl_last_dir = dir; | 268 | isp116x->atl_last_dir = dir; |
@@ -275,6 +273,61 @@ static void preproc_atl_queue(struct isp116x *isp116x) | |||
275 | } | 273 | } |
276 | 274 | ||
277 | /* | 275 | /* |
276 | Take done or failed requests out of schedule. Give back | ||
277 | processed urbs. | ||
278 | */ | ||
279 | static void finish_request(struct isp116x *isp116x, struct isp116x_ep *ep, | ||
280 | struct urb *urb) | ||
281 | __releases(isp116x->lock) __acquires(isp116x->lock) | ||
282 | { | ||
283 | unsigned i; | ||
284 | |||
285 | urb->hcpriv = NULL; | ||
286 | ep->error_count = 0; | ||
287 | |||
288 | if (usb_pipecontrol(urb->pipe)) | ||
289 | ep->nextpid = USB_PID_SETUP; | ||
290 | |||
291 | urb_dbg(urb, "Finish"); | ||
292 | |||
293 | spin_unlock(&isp116x->lock); | ||
294 | usb_hcd_giveback_urb(isp116x_to_hcd(isp116x), urb); | ||
295 | spin_lock(&isp116x->lock); | ||
296 | |||
297 | /* take idle endpoints out of the schedule */ | ||
298 | if (!list_empty(&ep->hep->urb_list)) | ||
299 | return; | ||
300 | |||
301 | /* async deschedule */ | ||
302 | if (!list_empty(&ep->schedule)) { | ||
303 | list_del_init(&ep->schedule); | ||
304 | return; | ||
305 | } | ||
306 | |||
307 | /* periodic deschedule */ | ||
308 | DBG("deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch); | ||
309 | for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) { | ||
310 | struct isp116x_ep *temp; | ||
311 | struct isp116x_ep **prev = &isp116x->periodic[i]; | ||
312 | |||
313 | while (*prev && ((temp = *prev) != ep)) | ||
314 | prev = &temp->next; | ||
315 | if (*prev) | ||
316 | *prev = ep->next; | ||
317 | isp116x->load[i] -= ep->load; | ||
318 | } | ||
319 | ep->branch = PERIODIC_SIZE; | ||
320 | isp116x_to_hcd(isp116x)->self.bandwidth_allocated -= | ||
321 | ep->load / ep->period; | ||
322 | |||
323 | /* switch irq type? */ | ||
324 | if (!--isp116x->periodic_count) { | ||
325 | isp116x->irqenb &= ~HCuPINT_SOF; | ||
326 | isp116x->irqenb |= HCuPINT_ATL; | ||
327 | } | ||
328 | } | ||
329 | |||
330 | /* | ||
278 | Analyze transfer results, handle partial transfers and errors | 331 | Analyze transfer results, handle partial transfers and errors |
279 | */ | 332 | */ |
280 | static void postproc_atl_queue(struct isp116x *isp116x) | 333 | static void postproc_atl_queue(struct isp116x *isp116x) |
@@ -284,6 +337,7 @@ static void postproc_atl_queue(struct isp116x *isp116x) | |||
284 | struct usb_device *udev; | 337 | struct usb_device *udev; |
285 | struct ptd *ptd; | 338 | struct ptd *ptd; |
286 | int short_not_ok; | 339 | int short_not_ok; |
340 | int status; | ||
287 | u8 cc; | 341 | u8 cc; |
288 | 342 | ||
289 | for (ep = isp116x->atl_active; ep; ep = ep->active) { | 343 | for (ep = isp116x->atl_active; ep; ep = ep->active) { |
@@ -294,7 +348,7 @@ static void postproc_atl_queue(struct isp116x *isp116x) | |||
294 | ptd = &ep->ptd; | 348 | ptd = &ep->ptd; |
295 | cc = PTD_GET_CC(ptd); | 349 | cc = PTD_GET_CC(ptd); |
296 | short_not_ok = 1; | 350 | short_not_ok = 1; |
297 | spin_lock(&urb->lock); | 351 | status = -EINPROGRESS; |
298 | 352 | ||
299 | /* Data underrun is special. For allowed underrun | 353 | /* Data underrun is special. For allowed underrun |
300 | we clear the error and continue as normal. For | 354 | we clear the error and continue as normal. For |
@@ -302,47 +356,36 @@ static void postproc_atl_queue(struct isp116x *isp116x) | |||
302 | immediately while for control transfer, | 356 | immediately while for control transfer, |
303 | we do a STATUS stage. */ | 357 | we do a STATUS stage. */ |
304 | if (cc == TD_DATAUNDERRUN) { | 358 | if (cc == TD_DATAUNDERRUN) { |
305 | if (!(urb->transfer_flags & URB_SHORT_NOT_OK)) { | 359 | if (!(urb->transfer_flags & URB_SHORT_NOT_OK) || |
306 | DBG("Allowed data underrun\n"); | 360 | usb_pipecontrol(urb->pipe)) { |
361 | DBG("Allowed or control data underrun\n"); | ||
307 | cc = TD_CC_NOERROR; | 362 | cc = TD_CC_NOERROR; |
308 | short_not_ok = 0; | 363 | short_not_ok = 0; |
309 | } else { | 364 | } else { |
310 | ep->error_count = 1; | 365 | ep->error_count = 1; |
311 | if (usb_pipecontrol(urb->pipe)) | 366 | usb_settoggle(udev, ep->epnum, |
312 | ep->nextpid = USB_PID_ACK; | 367 | ep->nextpid == USB_PID_OUT, |
313 | else | 368 | PTD_GET_TOGGLE(ptd)); |
314 | usb_settoggle(udev, ep->epnum, | ||
315 | ep->nextpid == | ||
316 | USB_PID_OUT, | ||
317 | PTD_GET_TOGGLE(ptd)); | ||
318 | urb->actual_length += PTD_GET_COUNT(ptd); | 369 | urb->actual_length += PTD_GET_COUNT(ptd); |
319 | urb->status = cc_to_error[TD_DATAUNDERRUN]; | 370 | status = cc_to_error[TD_DATAUNDERRUN]; |
320 | spin_unlock(&urb->lock); | 371 | goto done; |
321 | continue; | ||
322 | } | 372 | } |
323 | } | 373 | } |
324 | /* Keep underrun error through the STATUS stage */ | ||
325 | if (urb->status == cc_to_error[TD_DATAUNDERRUN]) | ||
326 | cc = TD_DATAUNDERRUN; | ||
327 | 374 | ||
328 | if (cc != TD_CC_NOERROR && cc != TD_NOTACCESSED | 375 | if (cc != TD_CC_NOERROR && cc != TD_NOTACCESSED |
329 | && (++ep->error_count >= 3 || cc == TD_CC_STALL | 376 | && (++ep->error_count >= 3 || cc == TD_CC_STALL |
330 | || cc == TD_DATAOVERRUN)) { | 377 | || cc == TD_DATAOVERRUN)) { |
331 | if (urb->status == -EINPROGRESS) | 378 | status = cc_to_error[cc]; |
332 | urb->status = cc_to_error[cc]; | ||
333 | if (ep->nextpid == USB_PID_ACK) | 379 | if (ep->nextpid == USB_PID_ACK) |
334 | ep->nextpid = 0; | 380 | ep->nextpid = 0; |
335 | spin_unlock(&urb->lock); | 381 | goto done; |
336 | continue; | ||
337 | } | 382 | } |
338 | /* According to usb spec, zero-length Int transfer signals | 383 | /* According to usb spec, zero-length Int transfer signals |
339 | finishing of the urb. Hey, does this apply only | 384 | finishing of the urb. Hey, does this apply only |
340 | for IN endpoints? */ | 385 | for IN endpoints? */ |
341 | if (usb_pipeint(urb->pipe) && !PTD_GET_LEN(ptd)) { | 386 | if (usb_pipeint(urb->pipe) && !PTD_GET_LEN(ptd)) { |
342 | if (urb->status == -EINPROGRESS) | 387 | status = 0; |
343 | urb->status = 0; | 388 | goto done; |
344 | spin_unlock(&urb->lock); | ||
345 | continue; | ||
346 | } | 389 | } |
347 | 390 | ||
348 | /* Relax after previously failed, but later succeeded | 391 | /* Relax after previously failed, but later succeeded |
@@ -381,8 +424,8 @@ static void postproc_atl_queue(struct isp116x *isp116x) | |||
381 | /* All data for this URB is transferred, let's finish */ | 424 | /* All data for this URB is transferred, let's finish */ |
382 | if (usb_pipecontrol(urb->pipe)) | 425 | if (usb_pipecontrol(urb->pipe)) |
383 | ep->nextpid = USB_PID_ACK; | 426 | ep->nextpid = USB_PID_ACK; |
384 | else if (urb->status == -EINPROGRESS) | 427 | else |
385 | urb->status = 0; | 428 | status = 0; |
386 | break; | 429 | break; |
387 | case USB_PID_SETUP: | 430 | case USB_PID_SETUP: |
388 | if (PTD_GET_ACTIVE(ptd) | 431 | if (PTD_GET_ACTIVE(ptd) |
@@ -402,69 +445,27 @@ static void postproc_atl_queue(struct isp116x *isp116x) | |||
402 | if (PTD_GET_ACTIVE(ptd) | 445 | if (PTD_GET_ACTIVE(ptd) |
403 | || (cc != TD_CC_NOERROR && cc < 0x0E)) | 446 | || (cc != TD_CC_NOERROR && cc < 0x0E)) |
404 | break; | 447 | break; |
405 | if (urb->status == -EINPROGRESS) | 448 | if ((urb->transfer_flags & URB_SHORT_NOT_OK) && |
406 | urb->status = 0; | 449 | urb->actual_length < |
450 | urb->transfer_buffer_length) | ||
451 | status = -EREMOTEIO; | ||
452 | else | ||
453 | status = 0; | ||
407 | ep->nextpid = 0; | 454 | ep->nextpid = 0; |
408 | break; | 455 | break; |
409 | default: | 456 | default: |
410 | BUG(); | 457 | BUG(); |
411 | } | 458 | } |
412 | spin_unlock(&urb->lock); | ||
413 | } | ||
414 | } | ||
415 | |||
416 | /* | ||
417 | Take done or failed requests out of schedule. Give back | ||
418 | processed urbs. | ||
419 | */ | ||
420 | static void finish_request(struct isp116x *isp116x, struct isp116x_ep *ep, | ||
421 | struct urb *urb) | ||
422 | __releases(isp116x->lock) __acquires(isp116x->lock) | ||
423 | { | ||
424 | unsigned i; | ||
425 | |||
426 | urb->hcpriv = NULL; | ||
427 | ep->error_count = 0; | ||
428 | |||
429 | if (usb_pipecontrol(urb->pipe)) | ||
430 | ep->nextpid = USB_PID_SETUP; | ||
431 | |||
432 | urb_dbg(urb, "Finish"); | ||
433 | |||
434 | spin_unlock(&isp116x->lock); | ||
435 | usb_hcd_giveback_urb(isp116x_to_hcd(isp116x), urb); | ||
436 | spin_lock(&isp116x->lock); | ||
437 | |||
438 | /* take idle endpoints out of the schedule */ | ||
439 | if (!list_empty(&ep->hep->urb_list)) | ||
440 | return; | ||
441 | |||
442 | /* async deschedule */ | ||
443 | if (!list_empty(&ep->schedule)) { | ||
444 | list_del_init(&ep->schedule); | ||
445 | return; | ||
446 | } | ||
447 | 459 | ||
448 | /* periodic deschedule */ | 460 | done: |
449 | DBG("deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch); | 461 | if (status != -EINPROGRESS) { |
450 | for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) { | 462 | spin_lock(&urb->lock); |
451 | struct isp116x_ep *temp; | 463 | if (urb->status == -EINPROGRESS) |
452 | struct isp116x_ep **prev = &isp116x->periodic[i]; | 464 | urb->status = status; |
453 | 465 | spin_unlock(&urb->lock); | |
454 | while (*prev && ((temp = *prev) != ep)) | 466 | } |
455 | prev = &temp->next; | 467 | if (urb->status != -EINPROGRESS) |
456 | if (*prev) | 468 | finish_request(isp116x, ep, urb); |
457 | *prev = ep->next; | ||
458 | isp116x->load[i] -= ep->load; | ||
459 | } | ||
460 | ep->branch = PERIODIC_SIZE; | ||
461 | isp116x_to_hcd(isp116x)->self.bandwidth_allocated -= | ||
462 | ep->load / ep->period; | ||
463 | |||
464 | /* switch irq type? */ | ||
465 | if (!--isp116x->periodic_count) { | ||
466 | isp116x->irqenb &= ~HCuPINT_SOF; | ||
467 | isp116x->irqenb |= HCuPINT_ATL; | ||
468 | } | 469 | } |
469 | } | 470 | } |
470 | 471 | ||
@@ -570,9 +571,6 @@ static void start_atl_transfers(struct isp116x *isp116x) | |||
570 | */ | 571 | */ |
571 | static void finish_atl_transfers(struct isp116x *isp116x) | 572 | static void finish_atl_transfers(struct isp116x *isp116x) |
572 | { | 573 | { |
573 | struct isp116x_ep *ep; | ||
574 | struct urb *urb; | ||
575 | |||
576 | if (!isp116x->atl_active) | 574 | if (!isp116x->atl_active) |
577 | return; | 575 | return; |
578 | /* Fifo not ready? */ | 576 | /* Fifo not ready? */ |
@@ -582,16 +580,6 @@ static void finish_atl_transfers(struct isp116x *isp116x) | |||
582 | atomic_inc(&isp116x->atl_finishing); | 580 | atomic_inc(&isp116x->atl_finishing); |
583 | unpack_fifo(isp116x); | 581 | unpack_fifo(isp116x); |
584 | postproc_atl_queue(isp116x); | 582 | postproc_atl_queue(isp116x); |
585 | for (ep = isp116x->atl_active; ep; ep = ep->active) { | ||
586 | urb = | ||
587 | container_of(ep->hep->urb_list.next, struct urb, urb_list); | ||
588 | /* USB_PID_ACK check here avoids finishing of | ||
589 | control transfers, for which TD_DATAUNDERRUN | ||
590 | occured, while URB_SHORT_NOT_OK was set */ | ||
591 | if (urb && urb->status != -EINPROGRESS | ||
592 | && ep->nextpid != USB_PID_ACK) | ||
593 | finish_request(isp116x, ep, urb); | ||
594 | } | ||
595 | atomic_dec(&isp116x->atl_finishing); | 583 | atomic_dec(&isp116x->atl_finishing); |
596 | } | 584 | } |
597 | 585 | ||
@@ -821,15 +809,12 @@ static int isp116x_urb_enqueue(struct usb_hcd *hcd, | |||
821 | } | 809 | } |
822 | 810 | ||
823 | /* in case of unlink-during-submit */ | 811 | /* in case of unlink-during-submit */ |
824 | spin_lock(&urb->lock); | ||
825 | if (urb->status != -EINPROGRESS) { | 812 | if (urb->status != -EINPROGRESS) { |
826 | spin_unlock(&urb->lock); | ||
827 | finish_request(isp116x, ep, urb); | 813 | finish_request(isp116x, ep, urb); |
828 | ret = 0; | 814 | ret = 0; |
829 | goto fail; | 815 | goto fail; |
830 | } | 816 | } |
831 | urb->hcpriv = hep; | 817 | urb->hcpriv = hep; |
832 | spin_unlock(&urb->lock); | ||
833 | start_atl_transfers(isp116x); | 818 | start_atl_transfers(isp116x); |
834 | 819 | ||
835 | fail: | 820 | fail: |
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c index a7a7070c6e2a..d60f1985320c 100644 --- a/drivers/usb/host/r8a66597-hcd.c +++ b/drivers/usb/host/r8a66597-hcd.c | |||
@@ -35,10 +35,8 @@ | |||
35 | #include <linux/interrupt.h> | 35 | #include <linux/interrupt.h> |
36 | #include <linux/usb.h> | 36 | #include <linux/usb.h> |
37 | #include <linux/platform_device.h> | 37 | #include <linux/platform_device.h> |
38 | 38 | #include <linux/io.h> | |
39 | #include <asm/io.h> | 39 | #include <linux/irq.h> |
40 | #include <asm/irq.h> | ||
41 | #include <asm/system.h> | ||
42 | 40 | ||
43 | #include "../core/hcd.h" | 41 | #include "../core/hcd.h" |
44 | #include "r8a66597.h" | 42 | #include "r8a66597.h" |
@@ -54,16 +52,21 @@ static const char hcd_name[] = "r8a66597_hcd"; | |||
54 | /* module parameters */ | 52 | /* module parameters */ |
55 | static unsigned short clock = XTAL12; | 53 | static unsigned short clock = XTAL12; |
56 | module_param(clock, ushort, 0644); | 54 | module_param(clock, ushort, 0644); |
57 | MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0(default=0)"); | 55 | MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0 " |
56 | "(default=0)"); | ||
57 | |||
58 | static unsigned short vif = LDRV; | 58 | static unsigned short vif = LDRV; |
59 | module_param(vif, ushort, 0644); | 59 | module_param(vif, ushort, 0644); |
60 | MODULE_PARM_DESC(vif, "input VIF: 3.3V=32768, 1.5V=0(default=32768)"); | 60 | MODULE_PARM_DESC(vif, "input VIF: 3.3V=32768, 1.5V=0(default=32768)"); |
61 | static unsigned short endian = 0; | 61 | |
62 | static unsigned short endian; | ||
62 | module_param(endian, ushort, 0644); | 63 | module_param(endian, ushort, 0644); |
63 | MODULE_PARM_DESC(endian, "data endian: big=256, little=0(default=0)"); | 64 | MODULE_PARM_DESC(endian, "data endian: big=256, little=0 (default=0)"); |
65 | |||
64 | static unsigned short irq_sense = INTL; | 66 | static unsigned short irq_sense = INTL; |
65 | module_param(irq_sense, ushort, 0644); | 67 | module_param(irq_sense, ushort, 0644); |
66 | MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=32, falling edge=0(default=32)"); | 68 | MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=32, falling edge=0 " |
69 | "(default=32)"); | ||
67 | 70 | ||
68 | static void packet_write(struct r8a66597 *r8a66597, u16 pipenum); | 71 | static void packet_write(struct r8a66597 *r8a66597, u16 pipenum); |
69 | static int r8a66597_get_frame(struct usb_hcd *hcd); | 72 | static int r8a66597_get_frame(struct usb_hcd *hcd); |
@@ -308,7 +311,7 @@ static int make_r8a66597_device(struct r8a66597 *r8a66597, | |||
308 | struct r8a66597_device *dev; | 311 | struct r8a66597_device *dev; |
309 | int usb_address = urb->setup_packet[2]; /* urb->pipe is address 0 */ | 312 | int usb_address = urb->setup_packet[2]; /* urb->pipe is address 0 */ |
310 | 313 | ||
311 | dev = kzalloc(sizeof(struct r8a66597_device), GFP_KERNEL); | 314 | dev = kzalloc(sizeof(struct r8a66597_device), GFP_ATOMIC); |
312 | if (dev == NULL) | 315 | if (dev == NULL) |
313 | return -ENOMEM; | 316 | return -ENOMEM; |
314 | 317 | ||
@@ -611,33 +614,33 @@ static u16 get_empty_pipenum(struct r8a66597 *r8a66597, | |||
611 | u16 array[R8A66597_MAX_NUM_PIPE], i = 0, min; | 614 | u16 array[R8A66597_MAX_NUM_PIPE], i = 0, min; |
612 | 615 | ||
613 | memset(array, 0, sizeof(array)); | 616 | memset(array, 0, sizeof(array)); |
614 | switch(ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { | 617 | switch (ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { |
615 | case USB_ENDPOINT_XFER_BULK: | 618 | case USB_ENDPOINT_XFER_BULK: |
616 | if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) | 619 | if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) |
617 | array[i++] = 4; | 620 | array[i++] = 4; |
618 | else { | 621 | else { |
619 | array[i++] = 3; | 622 | array[i++] = 3; |
620 | array[i++] = 5; | 623 | array[i++] = 5; |
621 | } | 624 | } |
622 | break; | 625 | break; |
623 | case USB_ENDPOINT_XFER_INT: | 626 | case USB_ENDPOINT_XFER_INT: |
624 | if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) { | 627 | if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) { |
625 | array[i++] = 6; | 628 | array[i++] = 6; |
626 | array[i++] = 7; | 629 | array[i++] = 7; |
627 | array[i++] = 8; | 630 | array[i++] = 8; |
628 | } else | 631 | } else |
629 | array[i++] = 9; | 632 | array[i++] = 9; |
630 | break; | 633 | break; |
631 | case USB_ENDPOINT_XFER_ISOC: | 634 | case USB_ENDPOINT_XFER_ISOC: |
632 | if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) | 635 | if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) |
633 | array[i++] = 2; | 636 | array[i++] = 2; |
634 | else | 637 | else |
635 | array[i++] = 1; | 638 | array[i++] = 1; |
636 | break; | 639 | break; |
637 | default: | 640 | default: |
638 | err("Illegal type"); | 641 | err("Illegal type"); |
639 | return 0; | 642 | return 0; |
640 | } | 643 | } |
641 | 644 | ||
642 | i = 1; | 645 | i = 1; |
643 | min = array[0]; | 646 | min = array[0]; |
@@ -654,7 +657,7 @@ static u16 get_r8a66597_type(__u8 type) | |||
654 | { | 657 | { |
655 | u16 r8a66597_type; | 658 | u16 r8a66597_type; |
656 | 659 | ||
657 | switch(type) { | 660 | switch (type) { |
658 | case USB_ENDPOINT_XFER_BULK: | 661 | case USB_ENDPOINT_XFER_BULK: |
659 | r8a66597_type = R8A66597_BULK; | 662 | r8a66597_type = R8A66597_BULK; |
660 | break; | 663 | break; |
@@ -874,7 +877,7 @@ static void r8a66597_usb_preconnect(struct r8a66597 *r8a66597, int port) | |||
874 | { | 877 | { |
875 | r8a66597->root_hub[port].port |= (1 << USB_PORT_FEAT_CONNECTION) | 878 | r8a66597->root_hub[port].port |= (1 << USB_PORT_FEAT_CONNECTION) |
876 | | (1 << USB_PORT_FEAT_C_CONNECTION); | 879 | | (1 << USB_PORT_FEAT_C_CONNECTION); |
877 | r8a66597_write(r8a66597, (u16)~DTCH, get_intsts_reg(port)); | 880 | r8a66597_write(r8a66597, ~DTCH, get_intsts_reg(port)); |
878 | r8a66597_bset(r8a66597, DTCHE, get_intenb_reg(port)); | 881 | r8a66597_bset(r8a66597, DTCHE, get_intenb_reg(port)); |
879 | } | 882 | } |
880 | 883 | ||
@@ -917,7 +920,7 @@ static void prepare_setup_packet(struct r8a66597 *r8a66597, | |||
917 | 920 | ||
918 | r8a66597_write(r8a66597, make_devsel(td->address) | td->maxpacket, | 921 | r8a66597_write(r8a66597, make_devsel(td->address) | td->maxpacket, |
919 | DCPMAXP); | 922 | DCPMAXP); |
920 | r8a66597_write(r8a66597, (u16)~(SIGN | SACK), INTSTS1); | 923 | r8a66597_write(r8a66597, ~(SIGN | SACK), INTSTS1); |
921 | 924 | ||
922 | for (i = 0; i < 4; i++) { | 925 | for (i = 0; i < 4; i++) { |
923 | r8a66597_write(r8a66597, p[i], setup_addr); | 926 | r8a66597_write(r8a66597, p[i], setup_addr); |
@@ -948,19 +951,18 @@ static void prepare_packet_read(struct r8a66597 *r8a66597, | |||
948 | pipe_irq_disable(r8a66597, td->pipenum); | 951 | pipe_irq_disable(r8a66597, td->pipenum); |
949 | pipe_setting(r8a66597, td); | 952 | pipe_setting(r8a66597, td); |
950 | pipe_stop(r8a66597, td->pipe); | 953 | pipe_stop(r8a66597, td->pipe); |
951 | r8a66597_write(r8a66597, (u16)~(1 << td->pipenum), | 954 | r8a66597_write(r8a66597, ~(1 << td->pipenum), BRDYSTS); |
952 | BRDYSTS); | ||
953 | 955 | ||
954 | if (td->pipe->pipetre) { | 956 | if (td->pipe->pipetre) { |
955 | r8a66597_write(r8a66597, TRCLR, | 957 | r8a66597_write(r8a66597, TRCLR, |
956 | td->pipe->pipetre); | 958 | td->pipe->pipetre); |
957 | r8a66597_write(r8a66597, | 959 | r8a66597_write(r8a66597, |
958 | (urb->transfer_buffer_length | 960 | (urb->transfer_buffer_length |
959 | + td->maxpacket - 1) | 961 | + td->maxpacket - 1) |
960 | / td->maxpacket, | 962 | / td->maxpacket, |
961 | td->pipe->pipetrn); | 963 | td->pipe->pipetrn); |
962 | r8a66597_bset(r8a66597, TRENB, | 964 | r8a66597_bset(r8a66597, TRENB, |
963 | td->pipe->pipetre); | 965 | td->pipe->pipetre); |
964 | } | 966 | } |
965 | 967 | ||
966 | pipe_start(r8a66597, td->pipe); | 968 | pipe_start(r8a66597, td->pipe); |
@@ -991,7 +993,7 @@ static void prepare_packet_write(struct r8a66597 *r8a66597, | |||
991 | if (td->pipe->pipetre) | 993 | if (td->pipe->pipetre) |
992 | r8a66597_bclr(r8a66597, TRENB, td->pipe->pipetre); | 994 | r8a66597_bclr(r8a66597, TRENB, td->pipe->pipetre); |
993 | } | 995 | } |
994 | r8a66597_write(r8a66597, (u16)~(1 << td->pipenum), BRDYSTS); | 996 | r8a66597_write(r8a66597, ~(1 << td->pipenum), BRDYSTS); |
995 | 997 | ||
996 | fifo_change_from_pipe(r8a66597, td->pipe); | 998 | fifo_change_from_pipe(r8a66597, td->pipe); |
997 | tmp = r8a66597_read(r8a66597, td->pipe->fifoctr); | 999 | tmp = r8a66597_read(r8a66597, td->pipe->fifoctr); |
@@ -1009,21 +1011,21 @@ static void prepare_status_packet(struct r8a66597 *r8a66597, | |||
1009 | struct urb *urb = td->urb; | 1011 | struct urb *urb = td->urb; |
1010 | 1012 | ||
1011 | r8a66597_pipe_toggle(r8a66597, td->pipe, 1); | 1013 | r8a66597_pipe_toggle(r8a66597, td->pipe, 1); |
1014 | pipe_stop(r8a66597, td->pipe); | ||
1012 | 1015 | ||
1013 | if (urb->setup_packet[0] & USB_ENDPOINT_DIR_MASK) { | 1016 | if (urb->setup_packet[0] & USB_ENDPOINT_DIR_MASK) { |
1014 | r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG); | 1017 | r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG); |
1015 | r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL); | 1018 | r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL); |
1016 | r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0); | 1019 | r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0); |
1017 | r8a66597_write(r8a66597, BVAL | BCLR, CFIFOCTR); | 1020 | r8a66597_write(r8a66597, ~BEMP0, BEMPSTS); |
1018 | r8a66597_write(r8a66597, (u16)~BEMP0, BEMPSTS); | 1021 | r8a66597_write(r8a66597, BCLR, CFIFOCTR); |
1022 | r8a66597_write(r8a66597, BVAL, CFIFOCTR); | ||
1019 | enable_irq_empty(r8a66597, 0); | 1023 | enable_irq_empty(r8a66597, 0); |
1020 | } else { | 1024 | } else { |
1021 | r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG); | 1025 | r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG); |
1022 | r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL); | 1026 | r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL); |
1023 | r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0); | 1027 | r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0); |
1024 | r8a66597_write(r8a66597, BCLR, CFIFOCTR); | 1028 | r8a66597_write(r8a66597, BCLR, CFIFOCTR); |
1025 | r8a66597_write(r8a66597, (u16)~BRDY0, BRDYSTS); | ||
1026 | r8a66597_write(r8a66597, (u16)~BEMP0, BEMPSTS); | ||
1027 | enable_irq_ready(r8a66597, 0); | 1029 | enable_irq_ready(r8a66597, 0); |
1028 | } | 1030 | } |
1029 | enable_irq_nrdy(r8a66597, 0); | 1031 | enable_irq_nrdy(r8a66597, 0); |
@@ -1269,7 +1271,7 @@ static void packet_write(struct r8a66597 *r8a66597, u16 pipenum) | |||
1269 | 1271 | ||
1270 | /* write fifo */ | 1272 | /* write fifo */ |
1271 | if (pipenum > 0) | 1273 | if (pipenum > 0) |
1272 | r8a66597_write(r8a66597, (u16)~(1 << pipenum), BEMPSTS); | 1274 | r8a66597_write(r8a66597, ~(1 << pipenum), BEMPSTS); |
1273 | if (urb->transfer_buffer) { | 1275 | if (urb->transfer_buffer) { |
1274 | r8a66597_write_fifo(r8a66597, td->pipe->fifoaddr, buf, size); | 1276 | r8a66597_write_fifo(r8a66597, td->pipe->fifoaddr, buf, size); |
1275 | if (!usb_pipebulk(urb->pipe) || td->maxpacket != size) | 1277 | if (!usb_pipebulk(urb->pipe) || td->maxpacket != size) |
@@ -1362,7 +1364,7 @@ static void irq_pipe_ready(struct r8a66597 *r8a66597) | |||
1362 | 1364 | ||
1363 | mask = r8a66597_read(r8a66597, BRDYSTS) | 1365 | mask = r8a66597_read(r8a66597, BRDYSTS) |
1364 | & r8a66597_read(r8a66597, BRDYENB); | 1366 | & r8a66597_read(r8a66597, BRDYENB); |
1365 | r8a66597_write(r8a66597, (u16)~mask, BRDYSTS); | 1367 | r8a66597_write(r8a66597, ~mask, BRDYSTS); |
1366 | if (mask & BRDY0) { | 1368 | if (mask & BRDY0) { |
1367 | td = r8a66597_get_td(r8a66597, 0); | 1369 | td = r8a66597_get_td(r8a66597, 0); |
1368 | if (td && td->type == USB_PID_IN) | 1370 | if (td && td->type == USB_PID_IN) |
@@ -1397,7 +1399,7 @@ static void irq_pipe_empty(struct r8a66597 *r8a66597) | |||
1397 | 1399 | ||
1398 | mask = r8a66597_read(r8a66597, BEMPSTS) | 1400 | mask = r8a66597_read(r8a66597, BEMPSTS) |
1399 | & r8a66597_read(r8a66597, BEMPENB); | 1401 | & r8a66597_read(r8a66597, BEMPENB); |
1400 | r8a66597_write(r8a66597, (u16)~mask, BEMPSTS); | 1402 | r8a66597_write(r8a66597, ~mask, BEMPSTS); |
1401 | if (mask & BEMP0) { | 1403 | if (mask & BEMP0) { |
1402 | cfifo_change(r8a66597, 0); | 1404 | cfifo_change(r8a66597, 0); |
1403 | td = r8a66597_get_td(r8a66597, 0); | 1405 | td = r8a66597_get_td(r8a66597, 0); |
@@ -1434,7 +1436,7 @@ static void irq_pipe_nrdy(struct r8a66597 *r8a66597) | |||
1434 | 1436 | ||
1435 | mask = r8a66597_read(r8a66597, NRDYSTS) | 1437 | mask = r8a66597_read(r8a66597, NRDYSTS) |
1436 | & r8a66597_read(r8a66597, NRDYENB); | 1438 | & r8a66597_read(r8a66597, NRDYENB); |
1437 | r8a66597_write(r8a66597, (u16)~mask, NRDYSTS); | 1439 | r8a66597_write(r8a66597, ~mask, NRDYSTS); |
1438 | if (mask & NRDY0) { | 1440 | if (mask & NRDY0) { |
1439 | cfifo_change(r8a66597, 0); | 1441 | cfifo_change(r8a66597, 0); |
1440 | set_urb_error(r8a66597, 0); | 1442 | set_urb_error(r8a66597, 0); |
@@ -1488,14 +1490,14 @@ static irqreturn_t r8a66597_irq(struct usb_hcd *hcd) | |||
1488 | mask0 = intsts0 & intenb0 & (BEMP | NRDY | BRDY); | 1490 | mask0 = intsts0 & intenb0 & (BEMP | NRDY | BRDY); |
1489 | if (mask2) { | 1491 | if (mask2) { |
1490 | if (mask2 & ATTCH) { | 1492 | if (mask2 & ATTCH) { |
1491 | r8a66597_write(r8a66597, (u16)~ATTCH, INTSTS2); | 1493 | r8a66597_write(r8a66597, ~ATTCH, INTSTS2); |
1492 | r8a66597_bclr(r8a66597, ATTCHE, INTENB2); | 1494 | r8a66597_bclr(r8a66597, ATTCHE, INTENB2); |
1493 | 1495 | ||
1494 | /* start usb bus sampling */ | 1496 | /* start usb bus sampling */ |
1495 | start_root_hub_sampling(r8a66597, 1); | 1497 | start_root_hub_sampling(r8a66597, 1); |
1496 | } | 1498 | } |
1497 | if (mask2 & DTCH) { | 1499 | if (mask2 & DTCH) { |
1498 | r8a66597_write(r8a66597, (u16)~DTCH, INTSTS2); | 1500 | r8a66597_write(r8a66597, ~DTCH, INTSTS2); |
1499 | r8a66597_bclr(r8a66597, DTCHE, INTENB2); | 1501 | r8a66597_bclr(r8a66597, DTCHE, INTENB2); |
1500 | r8a66597_usb_disconnect(r8a66597, 1); | 1502 | r8a66597_usb_disconnect(r8a66597, 1); |
1501 | } | 1503 | } |
@@ -1503,24 +1505,24 @@ static irqreturn_t r8a66597_irq(struct usb_hcd *hcd) | |||
1503 | 1505 | ||
1504 | if (mask1) { | 1506 | if (mask1) { |
1505 | if (mask1 & ATTCH) { | 1507 | if (mask1 & ATTCH) { |
1506 | r8a66597_write(r8a66597, (u16)~ATTCH, INTSTS1); | 1508 | r8a66597_write(r8a66597, ~ATTCH, INTSTS1); |
1507 | r8a66597_bclr(r8a66597, ATTCHE, INTENB1); | 1509 | r8a66597_bclr(r8a66597, ATTCHE, INTENB1); |
1508 | 1510 | ||
1509 | /* start usb bus sampling */ | 1511 | /* start usb bus sampling */ |
1510 | start_root_hub_sampling(r8a66597, 0); | 1512 | start_root_hub_sampling(r8a66597, 0); |
1511 | } | 1513 | } |
1512 | if (mask1 & DTCH) { | 1514 | if (mask1 & DTCH) { |
1513 | r8a66597_write(r8a66597, (u16)~DTCH, INTSTS1); | 1515 | r8a66597_write(r8a66597, ~DTCH, INTSTS1); |
1514 | r8a66597_bclr(r8a66597, DTCHE, INTENB1); | 1516 | r8a66597_bclr(r8a66597, DTCHE, INTENB1); |
1515 | r8a66597_usb_disconnect(r8a66597, 0); | 1517 | r8a66597_usb_disconnect(r8a66597, 0); |
1516 | } | 1518 | } |
1517 | if (mask1 & SIGN) { | 1519 | if (mask1 & SIGN) { |
1518 | r8a66597_write(r8a66597, (u16)~SIGN, INTSTS1); | 1520 | r8a66597_write(r8a66597, ~SIGN, INTSTS1); |
1519 | set_urb_error(r8a66597, 0); | 1521 | set_urb_error(r8a66597, 0); |
1520 | check_next_phase(r8a66597); | 1522 | check_next_phase(r8a66597); |
1521 | } | 1523 | } |
1522 | if (mask1 & SACK) { | 1524 | if (mask1 & SACK) { |
1523 | r8a66597_write(r8a66597, (u16)~SACK, INTSTS1); | 1525 | r8a66597_write(r8a66597, ~SACK, INTSTS1); |
1524 | check_next_phase(r8a66597); | 1526 | check_next_phase(r8a66597); |
1525 | } | 1527 | } |
1526 | } | 1528 | } |
@@ -1663,13 +1665,9 @@ static int check_pipe_config(struct r8a66597 *r8a66597, struct urb *urb) | |||
1663 | static int r8a66597_start(struct usb_hcd *hcd) | 1665 | static int r8a66597_start(struct usb_hcd *hcd) |
1664 | { | 1666 | { |
1665 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); | 1667 | struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); |
1666 | int ret; | ||
1667 | 1668 | ||
1668 | hcd->state = HC_STATE_RUNNING; | 1669 | hcd->state = HC_STATE_RUNNING; |
1669 | if ((ret = enable_controller(r8a66597)) < 0) | 1670 | return enable_controller(r8a66597); |
1670 | return ret; | ||
1671 | |||
1672 | return 0; | ||
1673 | } | 1671 | } |
1674 | 1672 | ||
1675 | static void r8a66597_stop(struct usb_hcd *hcd) | 1673 | static void r8a66597_stop(struct usb_hcd *hcd) |
@@ -1696,13 +1694,12 @@ static void set_address_zero(struct r8a66597 *r8a66597, struct urb *urb) | |||
1696 | 1694 | ||
1697 | static struct r8a66597_td *r8a66597_make_td(struct r8a66597 *r8a66597, | 1695 | static struct r8a66597_td *r8a66597_make_td(struct r8a66597 *r8a66597, |
1698 | struct urb *urb, | 1696 | struct urb *urb, |
1699 | struct usb_host_endpoint *hep, | 1697 | struct usb_host_endpoint *hep) |
1700 | gfp_t mem_flags) | ||
1701 | { | 1698 | { |
1702 | struct r8a66597_td *td; | 1699 | struct r8a66597_td *td; |
1703 | u16 pipenum; | 1700 | u16 pipenum; |
1704 | 1701 | ||
1705 | td = kzalloc(sizeof(struct r8a66597_td), mem_flags); | 1702 | td = kzalloc(sizeof(struct r8a66597_td), GFP_ATOMIC); |
1706 | if (td == NULL) | 1703 | if (td == NULL) |
1707 | return NULL; | 1704 | return NULL; |
1708 | 1705 | ||
@@ -1741,7 +1738,8 @@ static int r8a66597_urb_enqueue(struct usb_hcd *hcd, | |||
1741 | } | 1738 | } |
1742 | 1739 | ||
1743 | if (!hep->hcpriv) { | 1740 | if (!hep->hcpriv) { |
1744 | hep->hcpriv = kzalloc(sizeof(struct r8a66597_pipe), mem_flags); | 1741 | hep->hcpriv = kzalloc(sizeof(struct r8a66597_pipe), |
1742 | GFP_ATOMIC); | ||
1745 | if (!hep->hcpriv) { | 1743 | if (!hep->hcpriv) { |
1746 | ret = -ENOMEM; | 1744 | ret = -ENOMEM; |
1747 | goto error; | 1745 | goto error; |
@@ -1755,7 +1753,7 @@ static int r8a66597_urb_enqueue(struct usb_hcd *hcd, | |||
1755 | init_pipe_config(r8a66597, urb); | 1753 | init_pipe_config(r8a66597, urb); |
1756 | 1754 | ||
1757 | set_address_zero(r8a66597, urb); | 1755 | set_address_zero(r8a66597, urb); |
1758 | td = r8a66597_make_td(r8a66597, urb, hep, mem_flags); | 1756 | td = r8a66597_make_td(r8a66597, urb, hep); |
1759 | if (td == NULL) { | 1757 | if (td == NULL) { |
1760 | ret = -ENOMEM; | 1758 | ret = -ENOMEM; |
1761 | goto error; | 1759 | goto error; |
diff --git a/drivers/usb/host/r8a66597.h b/drivers/usb/host/r8a66597.h index 97c2a71ac7a1..fe9ceb077d9b 100644 --- a/drivers/usb/host/r8a66597.h +++ b/drivers/usb/host/r8a66597.h | |||
@@ -203,14 +203,14 @@ | |||
203 | #define DTLN 0x0FFF /* b11-0: FIFO received data length */ | 203 | #define DTLN 0x0FFF /* b11-0: FIFO received data length */ |
204 | 204 | ||
205 | /* Interrupt Enable Register 0 */ | 205 | /* Interrupt Enable Register 0 */ |
206 | #define VBSE 0x8000 /* b15: VBUS interrupt */ | 206 | #define VBSE 0x8000 /* b15: VBUS interrupt */ |
207 | #define RSME 0x4000 /* b14: Resume interrupt */ | 207 | #define RSME 0x4000 /* b14: Resume interrupt */ |
208 | #define SOFE 0x2000 /* b13: Frame update interrupt */ | 208 | #define SOFE 0x2000 /* b13: Frame update interrupt */ |
209 | #define DVSE 0x1000 /* b12: Device state transition interrupt */ | 209 | #define DVSE 0x1000 /* b12: Device state transition interrupt */ |
210 | #define CTRE 0x0800 /* b11: Control transfer stage transition interrupt */ | 210 | #define CTRE 0x0800 /* b11: Control transfer stage transition interrupt */ |
211 | #define BEMPE 0x0400 /* b10: Buffer empty interrupt */ | 211 | #define BEMPE 0x0400 /* b10: Buffer empty interrupt */ |
212 | #define NRDYE 0x0200 /* b9: Buffer not ready interrupt */ | 212 | #define NRDYE 0x0200 /* b9: Buffer not ready interrupt */ |
213 | #define BRDYE 0x0100 /* b8: Buffer ready interrupt */ | 213 | #define BRDYE 0x0100 /* b8: Buffer ready interrupt */ |
214 | 214 | ||
215 | /* Interrupt Enable Register 1 */ | 215 | /* Interrupt Enable Register 1 */ |
216 | #define OVRCRE 0x8000 /* b15: Over-current interrupt */ | 216 | #define OVRCRE 0x8000 /* b15: Over-current interrupt */ |
@@ -268,16 +268,16 @@ | |||
268 | #define SOF_DISABLE 0x0000 /* SOF OUT Disable */ | 268 | #define SOF_DISABLE 0x0000 /* SOF OUT Disable */ |
269 | 269 | ||
270 | /* Interrupt Status Register 0 */ | 270 | /* Interrupt Status Register 0 */ |
271 | #define VBINT 0x8000 /* b15: VBUS interrupt */ | 271 | #define VBINT 0x8000 /* b15: VBUS interrupt */ |
272 | #define RESM 0x4000 /* b14: Resume interrupt */ | 272 | #define RESM 0x4000 /* b14: Resume interrupt */ |
273 | #define SOFR 0x2000 /* b13: SOF frame update interrupt */ | 273 | #define SOFR 0x2000 /* b13: SOF frame update interrupt */ |
274 | #define DVST 0x1000 /* b12: Device state transition interrupt */ | 274 | #define DVST 0x1000 /* b12: Device state transition interrupt */ |
275 | #define CTRT 0x0800 /* b11: Control transfer stage transition interrupt */ | 275 | #define CTRT 0x0800 /* b11: Control transfer stage transition interrupt */ |
276 | #define BEMP 0x0400 /* b10: Buffer empty interrupt */ | 276 | #define BEMP 0x0400 /* b10: Buffer empty interrupt */ |
277 | #define NRDY 0x0200 /* b9: Buffer not ready interrupt */ | 277 | #define NRDY 0x0200 /* b9: Buffer not ready interrupt */ |
278 | #define BRDY 0x0100 /* b8: Buffer ready interrupt */ | 278 | #define BRDY 0x0100 /* b8: Buffer ready interrupt */ |
279 | #define VBSTS 0x0080 /* b7: VBUS input port */ | 279 | #define VBSTS 0x0080 /* b7: VBUS input port */ |
280 | #define DVSQ 0x0070 /* b6-4: Device state */ | 280 | #define DVSQ 0x0070 /* b6-4: Device state */ |
281 | #define DS_SPD_CNFG 0x0070 /* Suspend Configured */ | 281 | #define DS_SPD_CNFG 0x0070 /* Suspend Configured */ |
282 | #define DS_SPD_ADDR 0x0060 /* Suspend Address */ | 282 | #define DS_SPD_ADDR 0x0060 /* Suspend Address */ |
283 | #define DS_SPD_DFLT 0x0050 /* Suspend Default */ | 283 | #define DS_SPD_DFLT 0x0050 /* Suspend Default */ |
@@ -315,13 +315,10 @@ | |||
315 | /* Micro Frame Number Register */ | 315 | /* Micro Frame Number Register */ |
316 | #define UFRNM 0x0007 /* b2-0: Micro frame number */ | 316 | #define UFRNM 0x0007 /* b2-0: Micro frame number */ |
317 | 317 | ||
318 | /* USB Address / Low Power Status Recovery Register */ | ||
319 | //#define USBADDR 0x007F /* b6-0: USB address */ | ||
320 | |||
321 | /* Default Control Pipe Maxpacket Size Register */ | 318 | /* Default Control Pipe Maxpacket Size Register */ |
322 | /* Pipe Maxpacket Size Register */ | 319 | /* Pipe Maxpacket Size Register */ |
323 | #define DEVSEL 0xF000 /* b15-14: Device address select */ | 320 | #define DEVSEL 0xF000 /* b15-14: Device address select */ |
324 | #define MAXP 0x007F /* b6-0: Maxpacket size of default control pipe */ | 321 | #define MAXP 0x007F /* b6-0: Maxpacket size of default control pipe */ |
325 | 322 | ||
326 | /* Default Control Pipe Control Register */ | 323 | /* Default Control Pipe Control Register */ |
327 | #define BSTS 0x8000 /* b15: Buffer status */ | 324 | #define BSTS 0x8000 /* b15: Buffer status */ |
@@ -366,21 +363,21 @@ | |||
366 | #define MXPS 0x07FF /* b10-0: Maxpacket size */ | 363 | #define MXPS 0x07FF /* b10-0: Maxpacket size */ |
367 | 364 | ||
368 | /* Pipe Cycle Configuration Register */ | 365 | /* Pipe Cycle Configuration Register */ |
369 | #define IFIS 0x1000 /* b12: Isochronous in-buffer flush mode select */ | 366 | #define IFIS 0x1000 /* b12: Isochronous in-buffer flush mode select */ |
370 | #define IITV 0x0007 /* b2-0: Isochronous interval */ | 367 | #define IITV 0x0007 /* b2-0: Isochronous interval */ |
371 | 368 | ||
372 | /* Pipex Control Register */ | 369 | /* Pipex Control Register */ |
373 | #define BSTS 0x8000 /* b15: Buffer status */ | 370 | #define BSTS 0x8000 /* b15: Buffer status */ |
374 | #define INBUFM 0x4000 /* b14: IN buffer monitor (Only for PIPE1 to 5) */ | 371 | #define INBUFM 0x4000 /* b14: IN buffer monitor (Only for PIPE1 to 5) */ |
375 | #define CSCLR 0x2000 /* b13: complete-split status clear */ | 372 | #define CSCLR 0x2000 /* b13: complete-split status clear */ |
376 | #define CSSTS 0x1000 /* b12: complete-split status */ | 373 | #define CSSTS 0x1000 /* b12: complete-split status */ |
377 | #define ATREPM 0x0400 /* b10: Auto repeat mode */ | 374 | #define ATREPM 0x0400 /* b10: Auto repeat mode */ |
378 | #define ACLRM 0x0200 /* b9: Out buffer auto clear mode */ | 375 | #define ACLRM 0x0200 /* b9: Out buffer auto clear mode */ |
379 | #define SQCLR 0x0100 /* b8: Sequence toggle bit clear */ | 376 | #define SQCLR 0x0100 /* b8: Sequence toggle bit clear */ |
380 | #define SQSET 0x0080 /* b7: Sequence toggle bit set */ | 377 | #define SQSET 0x0080 /* b7: Sequence toggle bit set */ |
381 | #define SQMON 0x0040 /* b6: Sequence toggle bit monitor */ | 378 | #define SQMON 0x0040 /* b6: Sequence toggle bit monitor */ |
382 | #define PBUSY 0x0020 /* b5: pipe busy */ | 379 | #define PBUSY 0x0020 /* b5: pipe busy */ |
383 | #define PID 0x0003 /* b1-0: Response PID */ | 380 | #define PID 0x0003 /* b1-0: Response PID */ |
384 | 381 | ||
385 | /* PIPExTRE */ | 382 | /* PIPExTRE */ |
386 | #define TRENB 0x0200 /* b9: Transaction counter enable */ | 383 | #define TRENB 0x0200 /* b9: Transaction counter enable */ |
@@ -407,15 +404,15 @@ | |||
407 | #define make_devsel(addr) (addr << 12) | 404 | #define make_devsel(addr) (addr << 12) |
408 | 405 | ||
409 | struct r8a66597_pipe_info { | 406 | struct r8a66597_pipe_info { |
410 | u16 pipenum; | 407 | u16 pipenum; |
411 | u16 address; /* R8A66597 HCD usb addres */ | 408 | u16 address; /* R8A66597 HCD usb addres */ |
412 | u16 epnum; | 409 | u16 epnum; |
413 | u16 maxpacket; | 410 | u16 maxpacket; |
414 | u16 type; | 411 | u16 type; |
415 | u16 bufnum; | 412 | u16 bufnum; |
416 | u16 buf_bsize; | 413 | u16 buf_bsize; |
417 | u16 interval; | 414 | u16 interval; |
418 | u16 dir_in; | 415 | u16 dir_in; |
419 | }; | 416 | }; |
420 | 417 | ||
421 | struct r8a66597_pipe { | 418 | struct r8a66597_pipe { |
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c index e98df2ee9901..7f765ec038cd 100644 --- a/drivers/usb/host/u132-hcd.c +++ b/drivers/usb/host/u132-hcd.c | |||
@@ -52,6 +52,7 @@ | |||
52 | #include <linux/workqueue.h> | 52 | #include <linux/workqueue.h> |
53 | #include <linux/platform_device.h> | 53 | #include <linux/platform_device.h> |
54 | #include <linux/pci_ids.h> | 54 | #include <linux/pci_ids.h> |
55 | #include <linux/mutex.h> | ||
55 | #include <asm/io.h> | 56 | #include <asm/io.h> |
56 | #include <asm/irq.h> | 57 | #include <asm/irq.h> |
57 | #include <asm/system.h> | 58 | #include <asm/system.h> |
@@ -83,7 +84,7 @@ static DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait); | |||
83 | * u132_module_lock exists to protect access to global variables | 84 | * u132_module_lock exists to protect access to global variables |
84 | * | 85 | * |
85 | */ | 86 | */ |
86 | static struct semaphore u132_module_lock; | 87 | static struct mutex u132_module_lock; |
87 | static int u132_exiting = 0; | 88 | static int u132_exiting = 0; |
88 | static int u132_instances = 0; | 89 | static int u132_instances = 0; |
89 | static struct list_head u132_static_list; | 90 | static struct list_head u132_static_list; |
@@ -258,10 +259,10 @@ static void u132_hcd_delete(struct kref *kref) | |||
258 | struct platform_device *pdev = u132->platform_dev; | 259 | struct platform_device *pdev = u132->platform_dev; |
259 | struct usb_hcd *hcd = u132_to_hcd(u132); | 260 | struct usb_hcd *hcd = u132_to_hcd(u132); |
260 | u132->going += 1; | 261 | u132->going += 1; |
261 | down(&u132_module_lock); | 262 | mutex_lock(&u132_module_lock); |
262 | list_del_init(&u132->u132_list); | 263 | list_del_init(&u132->u132_list); |
263 | u132_instances -= 1; | 264 | u132_instances -= 1; |
264 | up(&u132_module_lock); | 265 | mutex_unlock(&u132_module_lock); |
265 | dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13" | 266 | dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13" |
266 | "2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev); | 267 | "2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev); |
267 | usb_put_hcd(hcd); | 268 | usb_put_hcd(hcd); |
@@ -3111,10 +3112,10 @@ static int __devinit u132_probe(struct platform_device *pdev) | |||
3111 | int retval = 0; | 3112 | int retval = 0; |
3112 | struct u132 *u132 = hcd_to_u132(hcd); | 3113 | struct u132 *u132 = hcd_to_u132(hcd); |
3113 | hcd->rsrc_start = 0; | 3114 | hcd->rsrc_start = 0; |
3114 | down(&u132_module_lock); | 3115 | mutex_lock(&u132_module_lock); |
3115 | list_add_tail(&u132->u132_list, &u132_static_list); | 3116 | list_add_tail(&u132->u132_list, &u132_static_list); |
3116 | u132->sequence_num = ++u132_instances; | 3117 | u132->sequence_num = ++u132_instances; |
3117 | up(&u132_module_lock); | 3118 | mutex_unlock(&u132_module_lock); |
3118 | u132_u132_init_kref(u132); | 3119 | u132_u132_init_kref(u132); |
3119 | u132_initialise(u132, pdev); | 3120 | u132_initialise(u132, pdev); |
3120 | hcd->product_desc = "ELAN U132 Host Controller"; | 3121 | hcd->product_desc = "ELAN U132 Host Controller"; |
@@ -3216,7 +3217,7 @@ static int __init u132_hcd_init(void) | |||
3216 | INIT_LIST_HEAD(&u132_static_list); | 3217 | INIT_LIST_HEAD(&u132_static_list); |
3217 | u132_instances = 0; | 3218 | u132_instances = 0; |
3218 | u132_exiting = 0; | 3219 | u132_exiting = 0; |
3219 | init_MUTEX(&u132_module_lock); | 3220 | mutex_init(&u132_module_lock); |
3220 | if (usb_disabled()) | 3221 | if (usb_disabled()) |
3221 | return -ENODEV; | 3222 | return -ENODEV; |
3222 | printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__, | 3223 | printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__, |
@@ -3232,9 +3233,9 @@ static void __exit u132_hcd_exit(void) | |||
3232 | { | 3233 | { |
3233 | struct u132 *u132; | 3234 | struct u132 *u132; |
3234 | struct u132 *temp; | 3235 | struct u132 *temp; |
3235 | down(&u132_module_lock); | 3236 | mutex_lock(&u132_module_lock); |
3236 | u132_exiting += 1; | 3237 | u132_exiting += 1; |
3237 | up(&u132_module_lock); | 3238 | mutex_unlock(&u132_module_lock); |
3238 | list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) { | 3239 | list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) { |
3239 | platform_device_unregister(u132->platform_dev); | 3240 | platform_device_unregister(u132->platform_dev); |
3240 | } platform_driver_unregister(&u132_platform_driver); | 3241 | } platform_driver_unregister(&u132_platform_driver); |
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c index 76c555a67dac..805e5fc5f5db 100644 --- a/drivers/usb/host/uhci-hcd.c +++ b/drivers/usb/host/uhci-hcd.c | |||
@@ -933,7 +933,7 @@ static int __init uhci_hcd_init(void) | |||
933 | } | 933 | } |
934 | 934 | ||
935 | uhci_up_cachep = kmem_cache_create("uhci_urb_priv", | 935 | uhci_up_cachep = kmem_cache_create("uhci_urb_priv", |
936 | sizeof(struct urb_priv), 0, 0, NULL, NULL); | 936 | sizeof(struct urb_priv), 0, 0, NULL); |
937 | if (!uhci_up_cachep) | 937 | if (!uhci_up_cachep) |
938 | goto up_failed; | 938 | goto up_failed; |
939 | 939 | ||
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c index 4aed305982ec..3bb908ca38e9 100644 --- a/drivers/usb/host/uhci-q.c +++ b/drivers/usb/host/uhci-q.c | |||
@@ -827,8 +827,10 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
827 | * If direction is "send", change the packet ID from SETUP (0x2D) | 827 | * If direction is "send", change the packet ID from SETUP (0x2D) |
828 | * to OUT (0xE1). Else change it from SETUP to IN (0x69) and | 828 | * to OUT (0xE1). Else change it from SETUP to IN (0x69) and |
829 | * set Short Packet Detect (SPD) for all data packets. | 829 | * set Short Packet Detect (SPD) for all data packets. |
830 | * | ||
831 | * 0-length transfers always get treated as "send". | ||
830 | */ | 832 | */ |
831 | if (usb_pipeout(urb->pipe)) | 833 | if (usb_pipeout(urb->pipe) || len == 0) |
832 | destination ^= (USB_PID_SETUP ^ USB_PID_OUT); | 834 | destination ^= (USB_PID_SETUP ^ USB_PID_OUT); |
833 | else { | 835 | else { |
834 | destination ^= (USB_PID_SETUP ^ USB_PID_IN); | 836 | destination ^= (USB_PID_SETUP ^ USB_PID_IN); |
@@ -839,7 +841,12 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
839 | * Build the DATA TDs | 841 | * Build the DATA TDs |
840 | */ | 842 | */ |
841 | while (len > 0) { | 843 | while (len > 0) { |
842 | int pktsze = min(len, maxsze); | 844 | int pktsze = maxsze; |
845 | |||
846 | if (len <= pktsze) { /* The last data packet */ | ||
847 | pktsze = len; | ||
848 | status &= ~TD_CTRL_SPD; | ||
849 | } | ||
843 | 850 | ||
844 | td = uhci_alloc_td(uhci); | 851 | td = uhci_alloc_td(uhci); |
845 | if (!td) | 852 | if (!td) |
@@ -866,20 +873,10 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb, | |||
866 | goto nomem; | 873 | goto nomem; |
867 | *plink = LINK_TO_TD(td); | 874 | *plink = LINK_TO_TD(td); |
868 | 875 | ||
869 | /* | 876 | /* Change direction for the status transaction */ |
870 | * It's IN if the pipe is an output pipe or we're not expecting | 877 | destination ^= (USB_PID_IN ^ USB_PID_OUT); |
871 | * data back. | ||
872 | */ | ||
873 | destination &= ~TD_TOKEN_PID_MASK; | ||
874 | if (usb_pipeout(urb->pipe) || !urb->transfer_buffer_length) | ||
875 | destination |= USB_PID_IN; | ||
876 | else | ||
877 | destination |= USB_PID_OUT; | ||
878 | |||
879 | destination |= TD_TOKEN_TOGGLE; /* End in Data1 */ | 878 | destination |= TD_TOKEN_TOGGLE; /* End in Data1 */ |
880 | 879 | ||
881 | status &= ~TD_CTRL_SPD; | ||
882 | |||
883 | uhci_add_td_to_urbp(td, urbp); | 880 | uhci_add_td_to_urbp(td, urbp); |
884 | uhci_fill_td(td, status | TD_CTRL_IOC, | 881 | uhci_fill_td(td, status | TD_CTRL_IOC, |
885 | destination | uhci_explen(0), 0); | 882 | destination | uhci_explen(0), 0); |
@@ -1185,10 +1182,18 @@ static int uhci_result_common(struct uhci_hcd *uhci, struct urb *urb) | |||
1185 | } | 1182 | } |
1186 | } | 1183 | } |
1187 | 1184 | ||
1185 | /* Did we receive a short packet? */ | ||
1188 | } else if (len < uhci_expected_length(td_token(td))) { | 1186 | } else if (len < uhci_expected_length(td_token(td))) { |
1189 | 1187 | ||
1190 | /* We received a short packet */ | 1188 | /* For control transfers, go to the status TD if |
1191 | if (urb->transfer_flags & URB_SHORT_NOT_OK) | 1189 | * this isn't already the last data TD */ |
1190 | if (qh->type == USB_ENDPOINT_XFER_CONTROL) { | ||
1191 | if (td->list.next != urbp->td_list.prev) | ||
1192 | ret = 1; | ||
1193 | } | ||
1194 | |||
1195 | /* For bulk and interrupt, this may be an error */ | ||
1196 | else if (urb->transfer_flags & URB_SHORT_NOT_OK) | ||
1192 | ret = -EREMOTEIO; | 1197 | ret = -EREMOTEIO; |
1193 | 1198 | ||
1194 | /* Fixup needed only if this isn't the URB's last TD */ | 1199 | /* Fixup needed only if this isn't the URB's last TD */ |
@@ -1208,10 +1213,6 @@ static int uhci_result_common(struct uhci_hcd *uhci, struct urb *urb) | |||
1208 | 1213 | ||
1209 | err: | 1214 | err: |
1210 | if (ret < 0) { | 1215 | if (ret < 0) { |
1211 | /* In case a control transfer gets an error | ||
1212 | * during the setup stage */ | ||
1213 | urb->actual_length = max(urb->actual_length, 0); | ||
1214 | |||
1215 | /* Note that the queue has stopped and save | 1216 | /* Note that the queue has stopped and save |
1216 | * the next toggle value */ | 1217 | * the next toggle value */ |
1217 | qh->element = UHCI_PTR_TERM; | 1218 | qh->element = UHCI_PTR_TERM; |
@@ -1489,9 +1490,25 @@ __acquires(uhci->lock) | |||
1489 | { | 1490 | { |
1490 | struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv; | 1491 | struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv; |
1491 | 1492 | ||
1493 | if (qh->type == USB_ENDPOINT_XFER_CONTROL) { | ||
1494 | |||
1495 | /* urb->actual_length < 0 means the setup transaction didn't | ||
1496 | * complete successfully. Either it failed or the URB was | ||
1497 | * unlinked first. Regardless, don't confuse people with a | ||
1498 | * negative length. */ | ||
1499 | urb->actual_length = max(urb->actual_length, 0); | ||
1500 | |||
1501 | /* Report erroneous short transfers */ | ||
1502 | if (unlikely((urb->transfer_flags & URB_SHORT_NOT_OK) && | ||
1503 | urb->actual_length < | ||
1504 | urb->transfer_buffer_length && | ||
1505 | urb->status == 0)) | ||
1506 | urb->status = -EREMOTEIO; | ||
1507 | } | ||
1508 | |||
1492 | /* When giving back the first URB in an Isochronous queue, | 1509 | /* When giving back the first URB in an Isochronous queue, |
1493 | * reinitialize the QH's iso-related members for the next URB. */ | 1510 | * reinitialize the QH's iso-related members for the next URB. */ |
1494 | if (qh->type == USB_ENDPOINT_XFER_ISOC && | 1511 | else if (qh->type == USB_ENDPOINT_XFER_ISOC && |
1495 | urbp->node.prev == &qh->queue && | 1512 | urbp->node.prev == &qh->queue && |
1496 | urbp->node.next != &qh->queue) { | 1513 | urbp->node.next != &qh->queue) { |
1497 | struct urb *nurb = list_entry(urbp->node.next, | 1514 | struct urb *nurb = list_entry(urbp->node.next, |
diff --git a/drivers/usb/image/mdc800.c b/drivers/usb/image/mdc800.c index 36502a06f73a..d1131a87a5b1 100644 --- a/drivers/usb/image/mdc800.c +++ b/drivers/usb/image/mdc800.c | |||
@@ -284,9 +284,9 @@ static void mdc800_usb_irq (struct urb *urb) | |||
284 | int data_received=0, wake_up; | 284 | int data_received=0, wake_up; |
285 | unsigned char* b=urb->transfer_buffer; | 285 | unsigned char* b=urb->transfer_buffer; |
286 | struct mdc800_data* mdc800=urb->context; | 286 | struct mdc800_data* mdc800=urb->context; |
287 | int status = urb->status; | ||
287 | 288 | ||
288 | if (urb->status >= 0) | 289 | if (status >= 0) { |
289 | { | ||
290 | 290 | ||
291 | //dbg ("%i %i %i %i %i %i %i %i \n",b[0],b[1],b[2],b[3],b[4],b[5],b[6],b[7]); | 291 | //dbg ("%i %i %i %i %i %i %i %i \n",b[0],b[1],b[2],b[3],b[4],b[5],b[6],b[7]); |
292 | 292 | ||
@@ -324,7 +324,7 @@ static void mdc800_usb_irq (struct urb *urb) | |||
324 | || | 324 | || |
325 | ((mdc800->camera_request_ready == 3) && (mdc800->camera_busy)) | 325 | ((mdc800->camera_request_ready == 3) && (mdc800->camera_busy)) |
326 | || | 326 | || |
327 | (urb->status < 0) | 327 | (status < 0) |
328 | ); | 328 | ); |
329 | 329 | ||
330 | if (wake_up) | 330 | if (wake_up) |
@@ -376,15 +376,12 @@ static int mdc800_usb_waitForIRQ (int mode, int msec) | |||
376 | static void mdc800_usb_write_notify (struct urb *urb) | 376 | static void mdc800_usb_write_notify (struct urb *urb) |
377 | { | 377 | { |
378 | struct mdc800_data* mdc800=urb->context; | 378 | struct mdc800_data* mdc800=urb->context; |
379 | int status = urb->status; | ||
379 | 380 | ||
380 | if (urb->status != 0) | 381 | if (status != 0) |
381 | { | 382 | err ("writing command fails (status=%i)", status); |
382 | err ("writing command fails (status=%i)", urb->status); | ||
383 | } | ||
384 | else | 383 | else |
385 | { | ||
386 | mdc800->state=READY; | 384 | mdc800->state=READY; |
387 | } | ||
388 | mdc800->written = 1; | 385 | mdc800->written = 1; |
389 | wake_up (&mdc800->write_wait); | 386 | wake_up (&mdc800->write_wait); |
390 | } | 387 | } |
@@ -396,9 +393,9 @@ static void mdc800_usb_write_notify (struct urb *urb) | |||
396 | static void mdc800_usb_download_notify (struct urb *urb) | 393 | static void mdc800_usb_download_notify (struct urb *urb) |
397 | { | 394 | { |
398 | struct mdc800_data* mdc800=urb->context; | 395 | struct mdc800_data* mdc800=urb->context; |
396 | int status = urb->status; | ||
399 | 397 | ||
400 | if (urb->status == 0) | 398 | if (status == 0) { |
401 | { | ||
402 | /* Fill output buffer with these data */ | 399 | /* Fill output buffer with these data */ |
403 | memcpy (mdc800->out, urb->transfer_buffer, 64); | 400 | memcpy (mdc800->out, urb->transfer_buffer, 64); |
404 | mdc800->out_count=64; | 401 | mdc800->out_count=64; |
@@ -408,10 +405,8 @@ static void mdc800_usb_download_notify (struct urb *urb) | |||
408 | { | 405 | { |
409 | mdc800->state=READY; | 406 | mdc800->state=READY; |
410 | } | 407 | } |
411 | } | 408 | } else { |
412 | else | 409 | err ("request bytes fails (status:%i)", status); |
413 | { | ||
414 | err ("request bytes fails (status:%i)", urb->status); | ||
415 | } | 410 | } |
416 | mdc800->downloaded = 1; | 411 | mdc800->downloaded = 1; |
417 | wake_up (&mdc800->download_wait); | 412 | wake_up (&mdc800->download_wait); |
@@ -649,9 +644,9 @@ static int mdc800_device_open (struct inode* inode, struct file *file) | |||
649 | 644 | ||
650 | retval=0; | 645 | retval=0; |
651 | mdc800->irq_urb->dev = mdc800->dev; | 646 | mdc800->irq_urb->dev = mdc800->dev; |
652 | if (usb_submit_urb (mdc800->irq_urb, GFP_KERNEL)) | 647 | retval = usb_submit_urb (mdc800->irq_urb, GFP_KERNEL); |
653 | { | 648 | if (retval) { |
654 | err ("request USB irq fails (submit_retval=%i urb_status=%i).",retval, mdc800->irq_urb->status); | 649 | err ("request USB irq fails (submit_retval=%i).", retval); |
655 | errn = -EIO; | 650 | errn = -EIO; |
656 | goto error_out; | 651 | goto error_out; |
657 | } | 652 | } |
@@ -698,6 +693,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l | |||
698 | { | 693 | { |
699 | size_t left=len, sts=len; /* single transfer size */ | 694 | size_t left=len, sts=len; /* single transfer size */ |
700 | char __user *ptr = buf; | 695 | char __user *ptr = buf; |
696 | int retval; | ||
701 | 697 | ||
702 | mutex_lock(&mdc800->io_lock); | 698 | mutex_lock(&mdc800->io_lock); |
703 | if (mdc800->state == NOT_CONNECTED) | 699 | if (mdc800->state == NOT_CONNECTED) |
@@ -737,9 +733,9 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l | |||
737 | 733 | ||
738 | /* Download -> Request new bytes */ | 734 | /* Download -> Request new bytes */ |
739 | mdc800->download_urb->dev = mdc800->dev; | 735 | mdc800->download_urb->dev = mdc800->dev; |
740 | if (usb_submit_urb (mdc800->download_urb, GFP_KERNEL)) | 736 | retval = usb_submit_urb (mdc800->download_urb, GFP_KERNEL); |
741 | { | 737 | if (retval) { |
742 | err ("Can't submit download urb (status=%i)",mdc800->download_urb->status); | 738 | err ("Can't submit download urb (retval=%i)",retval); |
743 | mutex_unlock(&mdc800->io_lock); | 739 | mutex_unlock(&mdc800->io_lock); |
744 | return len-left; | 740 | return len-left; |
745 | } | 741 | } |
@@ -788,6 +784,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l | |||
788 | static ssize_t mdc800_device_write (struct file *file, const char __user *buf, size_t len, loff_t *pos) | 784 | static ssize_t mdc800_device_write (struct file *file, const char __user *buf, size_t len, loff_t *pos) |
789 | { | 785 | { |
790 | size_t i=0; | 786 | size_t i=0; |
787 | int retval; | ||
791 | 788 | ||
792 | mutex_lock(&mdc800->io_lock); | 789 | mutex_lock(&mdc800->io_lock); |
793 | if (mdc800->state != READY) | 790 | if (mdc800->state != READY) |
@@ -854,9 +851,9 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s | |||
854 | mdc800->state=WORKING; | 851 | mdc800->state=WORKING; |
855 | memcpy (mdc800->write_urb->transfer_buffer, mdc800->in,8); | 852 | memcpy (mdc800->write_urb->transfer_buffer, mdc800->in,8); |
856 | mdc800->write_urb->dev = mdc800->dev; | 853 | mdc800->write_urb->dev = mdc800->dev; |
857 | if (usb_submit_urb (mdc800->write_urb, GFP_KERNEL)) | 854 | retval = usb_submit_urb (mdc800->write_urb, GFP_KERNEL); |
858 | { | 855 | if (retval) { |
859 | err ("submitting write urb fails (status=%i)", mdc800->write_urb->status); | 856 | err ("submitting write urb fails (retval=%i)", retval); |
860 | mutex_unlock(&mdc800->io_lock); | 857 | mutex_unlock(&mdc800->io_lock); |
861 | return -EIO; | 858 | return -EIO; |
862 | } | 859 | } |
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c index 51bd80d2b8cc..768b2c11a231 100644 --- a/drivers/usb/image/microtek.c +++ b/drivers/usb/image/microtek.c | |||
@@ -189,7 +189,7 @@ static struct usb_driver mts_usb_driver = { | |||
189 | #define MTS_DEBUG_INT() \ | 189 | #define MTS_DEBUG_INT() \ |
190 | do { MTS_DEBUG_GOT_HERE(); \ | 190 | do { MTS_DEBUG_GOT_HERE(); \ |
191 | MTS_DEBUG("transfer = 0x%x context = 0x%x\n",(int)transfer,(int)context ); \ | 191 | MTS_DEBUG("transfer = 0x%x context = 0x%x\n",(int)transfer,(int)context ); \ |
192 | MTS_DEBUG("status = 0x%x data-length = 0x%x sent = 0x%x\n",(int)transfer->status,(int)context->data_length, (int)transfer->actual_length ); \ | 192 | MTS_DEBUG("status = 0x%x data-length = 0x%x sent = 0x%x\n",transfer->status,(int)context->data_length, (int)transfer->actual_length ); \ |
193 | mts_debug_dump(context->instance);\ | 193 | mts_debug_dump(context->instance);\ |
194 | } while(0) | 194 | } while(0) |
195 | #else | 195 | #else |
@@ -393,8 +393,6 @@ void mts_int_submit_urb (struct urb* transfer, | |||
393 | context | 393 | context |
394 | ); | 394 | ); |
395 | 395 | ||
396 | transfer->status = 0; | ||
397 | |||
398 | res = usb_submit_urb( transfer, GFP_ATOMIC ); | 396 | res = usb_submit_urb( transfer, GFP_ATOMIC ); |
399 | if ( unlikely(res) ) { | 397 | if ( unlikely(res) ) { |
400 | MTS_INT_ERROR( "could not submit URB! Error was %d\n",(int)res ); | 398 | MTS_INT_ERROR( "could not submit URB! Error was %d\n",(int)res ); |
@@ -444,12 +442,13 @@ static void mts_get_status( struct urb *transfer ) | |||
444 | static void mts_data_done( struct urb* transfer ) | 442 | static void mts_data_done( struct urb* transfer ) |
445 | /* Interrupt context! */ | 443 | /* Interrupt context! */ |
446 | { | 444 | { |
445 | int status = transfer->status; | ||
447 | MTS_INT_INIT(); | 446 | MTS_INT_INIT(); |
448 | 447 | ||
449 | if ( context->data_length != transfer->actual_length ) { | 448 | if ( context->data_length != transfer->actual_length ) { |
450 | context->srb->resid = context->data_length - transfer->actual_length; | 449 | context->srb->resid = context->data_length - transfer->actual_length; |
451 | } else if ( unlikely(transfer->status) ) { | 450 | } else if ( unlikely(status) ) { |
452 | context->srb->result = (transfer->status == -ENOENT ? DID_ABORT : DID_ERROR)<<16; | 451 | context->srb->result = (status == -ENOENT ? DID_ABORT : DID_ERROR)<<16; |
453 | } | 452 | } |
454 | 453 | ||
455 | mts_get_status(transfer); | 454 | mts_get_status(transfer); |
@@ -461,10 +460,11 @@ static void mts_data_done( struct urb* transfer ) | |||
461 | static void mts_command_done( struct urb *transfer ) | 460 | static void mts_command_done( struct urb *transfer ) |
462 | /* Interrupt context! */ | 461 | /* Interrupt context! */ |
463 | { | 462 | { |
463 | int status = transfer->status; | ||
464 | MTS_INT_INIT(); | 464 | MTS_INT_INIT(); |
465 | 465 | ||
466 | if ( unlikely(transfer->status) ) { | 466 | if ( unlikely(status) ) { |
467 | if (transfer->status == -ENOENT) { | 467 | if (status == -ENOENT) { |
468 | /* We are being killed */ | 468 | /* We are being killed */ |
469 | MTS_DEBUG_GOT_HERE(); | 469 | MTS_DEBUG_GOT_HERE(); |
470 | context->srb->result = DID_ABORT<<16; | 470 | context->srb->result = DID_ABORT<<16; |
@@ -502,12 +502,13 @@ static void mts_command_done( struct urb *transfer ) | |||
502 | static void mts_do_sg (struct urb* transfer) | 502 | static void mts_do_sg (struct urb* transfer) |
503 | { | 503 | { |
504 | struct scatterlist * sg; | 504 | struct scatterlist * sg; |
505 | int status = transfer->status; | ||
505 | MTS_INT_INIT(); | 506 | MTS_INT_INIT(); |
506 | 507 | ||
507 | MTS_DEBUG("Processing fragment %d of %d\n", context->fragment,context->srb->use_sg); | 508 | MTS_DEBUG("Processing fragment %d of %d\n", context->fragment,context->srb->use_sg); |
508 | 509 | ||
509 | if (unlikely(transfer->status)) { | 510 | if (unlikely(status)) { |
510 | context->srb->result = (transfer->status == -ENOENT ? DID_ABORT : DID_ERROR)<<16; | 511 | context->srb->result = (status == -ENOENT ? DID_ABORT : DID_ERROR)<<16; |
511 | mts_transfer_cleanup(transfer); | 512 | mts_transfer_cleanup(transfer); |
512 | } | 513 | } |
513 | 514 | ||
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c index d72c42e5f22d..e9fdbc8997b3 100644 --- a/drivers/usb/misc/adutux.c +++ b/drivers/usb/misc/adutux.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
25 | #include <linux/module.h> | 25 | #include <linux/module.h> |
26 | #include <linux/usb.h> | 26 | #include <linux/usb.h> |
27 | #include <linux/mutex.h> | ||
27 | #include <asm/uaccess.h> | 28 | #include <asm/uaccess.h> |
28 | 29 | ||
29 | #ifdef CONFIG_USB_DEBUG | 30 | #ifdef CONFIG_USB_DEBUG |
@@ -80,7 +81,7 @@ MODULE_DEVICE_TABLE(usb, device_table); | |||
80 | 81 | ||
81 | /* Structure to hold all of our device specific stuff */ | 82 | /* Structure to hold all of our device specific stuff */ |
82 | struct adu_device { | 83 | struct adu_device { |
83 | struct semaphore sem; /* locks this structure */ | 84 | struct mutex mtx; /* locks this structure */ |
84 | struct usb_device* udev; /* save off the usb device pointer */ | 85 | struct usb_device* udev; /* save off the usb device pointer */ |
85 | struct usb_interface* interface; | 86 | struct usb_interface* interface; |
86 | unsigned char minor; /* the starting minor number for this device */ | 87 | unsigned char minor; /* the starting minor number for this device */ |
@@ -178,17 +179,18 @@ static void adu_delete(struct adu_device *dev) | |||
178 | static void adu_interrupt_in_callback(struct urb *urb) | 179 | static void adu_interrupt_in_callback(struct urb *urb) |
179 | { | 180 | { |
180 | struct adu_device *dev = urb->context; | 181 | struct adu_device *dev = urb->context; |
182 | int status = urb->status; | ||
181 | 183 | ||
182 | dbg(4," %s : enter, status %d", __FUNCTION__, urb->status); | 184 | dbg(4," %s : enter, status %d", __FUNCTION__, status); |
183 | adu_debug_data(5, __FUNCTION__, urb->actual_length, | 185 | adu_debug_data(5, __FUNCTION__, urb->actual_length, |
184 | urb->transfer_buffer); | 186 | urb->transfer_buffer); |
185 | 187 | ||
186 | spin_lock(&dev->buflock); | 188 | spin_lock(&dev->buflock); |
187 | 189 | ||
188 | if (urb->status != 0) { | 190 | if (status != 0) { |
189 | if ((urb->status != -ENOENT) && (urb->status != -ECONNRESET)) { | 191 | if ((status != -ENOENT) && (status != -ECONNRESET)) { |
190 | dbg(1," %s : nonzero status received: %d", | 192 | dbg(1," %s : nonzero status received: %d", |
191 | __FUNCTION__, urb->status); | 193 | __FUNCTION__, status); |
192 | } | 194 | } |
193 | goto exit; | 195 | goto exit; |
194 | } | 196 | } |
@@ -216,21 +218,22 @@ exit: | |||
216 | wake_up_interruptible(&dev->read_wait); | 218 | wake_up_interruptible(&dev->read_wait); |
217 | adu_debug_data(5, __FUNCTION__, urb->actual_length, | 219 | adu_debug_data(5, __FUNCTION__, urb->actual_length, |
218 | urb->transfer_buffer); | 220 | urb->transfer_buffer); |
219 | dbg(4," %s : leave, status %d", __FUNCTION__, urb->status); | 221 | dbg(4," %s : leave, status %d", __FUNCTION__, status); |
220 | } | 222 | } |
221 | 223 | ||
222 | static void adu_interrupt_out_callback(struct urb *urb) | 224 | static void adu_interrupt_out_callback(struct urb *urb) |
223 | { | 225 | { |
224 | struct adu_device *dev = urb->context; | 226 | struct adu_device *dev = urb->context; |
227 | int status = urb->status; | ||
225 | 228 | ||
226 | dbg(4," %s : enter, status %d", __FUNCTION__, urb->status); | 229 | dbg(4," %s : enter, status %d", __FUNCTION__, status); |
227 | adu_debug_data(5,__FUNCTION__, urb->actual_length, urb->transfer_buffer); | 230 | adu_debug_data(5,__FUNCTION__, urb->actual_length, urb->transfer_buffer); |
228 | 231 | ||
229 | if (urb->status != 0) { | 232 | if (status != 0) { |
230 | if ((urb->status != -ENOENT) && | 233 | if ((status != -ENOENT) && |
231 | (urb->status != -ECONNRESET)) { | 234 | (status != -ECONNRESET)) { |
232 | dbg(1, " %s :nonzero status received: %d", | 235 | dbg(1, " %s :nonzero status received: %d", |
233 | __FUNCTION__, urb->status); | 236 | __FUNCTION__, status); |
234 | } | 237 | } |
235 | goto exit; | 238 | goto exit; |
236 | } | 239 | } |
@@ -240,7 +243,7 @@ exit: | |||
240 | 243 | ||
241 | adu_debug_data(5, __FUNCTION__, urb->actual_length, | 244 | adu_debug_data(5, __FUNCTION__, urb->actual_length, |
242 | urb->transfer_buffer); | 245 | urb->transfer_buffer); |
243 | dbg(4," %s : leave, status %d", __FUNCTION__, urb->status); | 246 | dbg(4," %s : leave, status %d", __FUNCTION__, status); |
244 | } | 247 | } |
245 | 248 | ||
246 | static int adu_open(struct inode *inode, struct file *file) | 249 | static int adu_open(struct inode *inode, struct file *file) |
@@ -269,8 +272,8 @@ static int adu_open(struct inode *inode, struct file *file) | |||
269 | } | 272 | } |
270 | 273 | ||
271 | /* lock this device */ | 274 | /* lock this device */ |
272 | if ((retval = down_interruptible(&dev->sem))) { | 275 | if ((retval = mutex_lock_interruptible(&dev->mtx))) { |
273 | dbg(2, "%s : sem down failed", __FUNCTION__); | 276 | dbg(2, "%s : mutex lock failed", __FUNCTION__); |
274 | goto exit_no_device; | 277 | goto exit_no_device; |
275 | } | 278 | } |
276 | 279 | ||
@@ -299,7 +302,7 @@ static int adu_open(struct inode *inode, struct file *file) | |||
299 | if (retval) | 302 | if (retval) |
300 | --dev->open_count; | 303 | --dev->open_count; |
301 | } | 304 | } |
302 | up(&dev->sem); | 305 | mutex_unlock(&dev->mtx); |
303 | 306 | ||
304 | exit_no_device: | 307 | exit_no_device: |
305 | dbg(2,"%s : leave, return value %d ", __FUNCTION__, retval); | 308 | dbg(2,"%s : leave, return value %d ", __FUNCTION__, retval); |
@@ -347,7 +350,7 @@ static int adu_release(struct inode *inode, struct file *file) | |||
347 | } | 350 | } |
348 | 351 | ||
349 | /* lock our device */ | 352 | /* lock our device */ |
350 | down(&dev->sem); /* not interruptible */ | 353 | mutex_lock(&dev->mtx); /* not interruptible */ |
351 | 354 | ||
352 | if (dev->open_count <= 0) { | 355 | if (dev->open_count <= 0) { |
353 | dbg(1," %s : device not opened", __FUNCTION__); | 356 | dbg(1," %s : device not opened", __FUNCTION__); |
@@ -357,7 +360,7 @@ static int adu_release(struct inode *inode, struct file *file) | |||
357 | 360 | ||
358 | if (dev->udev == NULL) { | 361 | if (dev->udev == NULL) { |
359 | /* the device was unplugged before the file was released */ | 362 | /* the device was unplugged before the file was released */ |
360 | up(&dev->sem); | 363 | mutex_unlock(&dev->mtx); |
361 | adu_delete(dev); | 364 | adu_delete(dev); |
362 | dev = NULL; | 365 | dev = NULL; |
363 | } else { | 366 | } else { |
@@ -367,7 +370,7 @@ static int adu_release(struct inode *inode, struct file *file) | |||
367 | 370 | ||
368 | exit: | 371 | exit: |
369 | if (dev) | 372 | if (dev) |
370 | up(&dev->sem); | 373 | mutex_unlock(&dev->mtx); |
371 | dbg(2," %s : leave, return value %d", __FUNCTION__, retval); | 374 | dbg(2," %s : leave, return value %d", __FUNCTION__, retval); |
372 | return retval; | 375 | return retval; |
373 | } | 376 | } |
@@ -390,7 +393,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count, | |||
390 | dev = file->private_data; | 393 | dev = file->private_data; |
391 | dbg(2," %s : dev=%p", __FUNCTION__, dev); | 394 | dbg(2," %s : dev=%p", __FUNCTION__, dev); |
392 | /* lock this object */ | 395 | /* lock this object */ |
393 | if (down_interruptible(&dev->sem)) | 396 | if (mutex_lock_interruptible(&dev->mtx)) |
394 | return -ERESTARTSYS; | 397 | return -ERESTARTSYS; |
395 | 398 | ||
396 | /* verify that the device wasn't unplugged */ | 399 | /* verify that the device wasn't unplugged */ |
@@ -522,7 +525,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count, | |||
522 | 525 | ||
523 | exit: | 526 | exit: |
524 | /* unlock the device */ | 527 | /* unlock the device */ |
525 | up(&dev->sem); | 528 | mutex_unlock(&dev->mtx); |
526 | 529 | ||
527 | dbg(2," %s : leave, return value %d", __FUNCTION__, retval); | 530 | dbg(2," %s : leave, return value %d", __FUNCTION__, retval); |
528 | return retval; | 531 | return retval; |
@@ -543,7 +546,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer, | |||
543 | dev = file->private_data; | 546 | dev = file->private_data; |
544 | 547 | ||
545 | /* lock this object */ | 548 | /* lock this object */ |
546 | retval = down_interruptible(&dev->sem); | 549 | retval = mutex_lock_interruptible(&dev->mtx); |
547 | if (retval) | 550 | if (retval) |
548 | goto exit_nolock; | 551 | goto exit_nolock; |
549 | 552 | ||
@@ -571,9 +574,9 @@ static ssize_t adu_write(struct file *file, const __user char *buffer, | |||
571 | retval = -EINTR; | 574 | retval = -EINTR; |
572 | goto exit; | 575 | goto exit; |
573 | } | 576 | } |
574 | up(&dev->sem); | 577 | mutex_unlock(&dev->mtx); |
575 | timeout = interruptible_sleep_on_timeout(&dev->write_wait, timeout); | 578 | timeout = interruptible_sleep_on_timeout(&dev->write_wait, timeout); |
576 | retval = down_interruptible(&dev->sem); | 579 | retval = mutex_lock_interruptible(&dev->mtx); |
577 | if (retval) { | 580 | if (retval) { |
578 | retval = bytes_written ? bytes_written : retval; | 581 | retval = bytes_written ? bytes_written : retval; |
579 | goto exit_nolock; | 582 | goto exit_nolock; |
@@ -638,7 +641,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer, | |||
638 | 641 | ||
639 | exit: | 642 | exit: |
640 | /* unlock the device */ | 643 | /* unlock the device */ |
641 | up(&dev->sem); | 644 | mutex_unlock(&dev->mtx); |
642 | exit_nolock: | 645 | exit_nolock: |
643 | 646 | ||
644 | dbg(2," %s : leave, return value %d", __FUNCTION__, retval); | 647 | dbg(2," %s : leave, return value %d", __FUNCTION__, retval); |
@@ -698,7 +701,7 @@ static int adu_probe(struct usb_interface *interface, | |||
698 | goto exit; | 701 | goto exit; |
699 | } | 702 | } |
700 | 703 | ||
701 | init_MUTEX(&dev->sem); | 704 | mutex_init(&dev->mtx); |
702 | spin_lock_init(&dev->buflock); | 705 | spin_lock_init(&dev->buflock); |
703 | dev->udev = udev; | 706 | dev->udev = udev; |
704 | init_waitqueue_head(&dev->read_wait); | 707 | init_waitqueue_head(&dev->read_wait); |
@@ -835,16 +838,16 @@ static void adu_disconnect(struct usb_interface *interface) | |||
835 | usb_deregister_dev(interface, &adu_class); | 838 | usb_deregister_dev(interface, &adu_class); |
836 | dev->minor = 0; | 839 | dev->minor = 0; |
837 | 840 | ||
838 | down(&dev->sem); /* not interruptible */ | 841 | mutex_lock(&dev->mtx); /* not interruptible */ |
839 | 842 | ||
840 | /* if the device is not opened, then we clean up right now */ | 843 | /* if the device is not opened, then we clean up right now */ |
841 | dbg(2," %s : open count %d", __FUNCTION__, dev->open_count); | 844 | dbg(2," %s : open count %d", __FUNCTION__, dev->open_count); |
842 | if (!dev->open_count) { | 845 | if (!dev->open_count) { |
843 | up(&dev->sem); | 846 | mutex_unlock(&dev->mtx); |
844 | adu_delete(dev); | 847 | adu_delete(dev); |
845 | } else { | 848 | } else { |
846 | dev->udev = NULL; | 849 | dev->udev = NULL; |
847 | up(&dev->sem); | 850 | mutex_unlock(&dev->mtx); |
848 | } | 851 | } |
849 | 852 | ||
850 | dev_info(&interface->dev, "ADU device adutux%d now disconnected", | 853 | dev_info(&interface->dev, "ADU device adutux%d now disconnected", |
diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c index cf70c16f0e3f..b09c83568c1a 100644 --- a/drivers/usb/misc/appledisplay.c +++ b/drivers/usb/misc/appledisplay.c | |||
@@ -88,9 +88,10 @@ static void appledisplay_complete(struct urb *urb) | |||
88 | { | 88 | { |
89 | struct appledisplay *pdata = urb->context; | 89 | struct appledisplay *pdata = urb->context; |
90 | unsigned long flags; | 90 | unsigned long flags; |
91 | int status = urb->status; | ||
91 | int retval; | 92 | int retval; |
92 | 93 | ||
93 | switch (urb->status) { | 94 | switch (status) { |
94 | case 0: | 95 | case 0: |
95 | /* success */ | 96 | /* success */ |
96 | break; | 97 | break; |
@@ -102,12 +103,12 @@ static void appledisplay_complete(struct urb *urb) | |||
102 | case -ENOENT: | 103 | case -ENOENT: |
103 | case -ESHUTDOWN: | 104 | case -ESHUTDOWN: |
104 | /* This urb is terminated, clean up */ | 105 | /* This urb is terminated, clean up */ |
105 | dbg("%s - urb shutting down with status: %d", | 106 | dbg("%s - urb shuttingdown with status: %d", |
106 | __FUNCTION__, urb->status); | 107 | __FUNCTION__, status); |
107 | return; | 108 | return; |
108 | default: | 109 | default: |
109 | dbg("%s - nonzero urb status received: %d", | 110 | dbg("%s - nonzero urb status received: %d", |
110 | __FUNCTION__, urb->status); | 111 | __FUNCTION__, status); |
111 | goto exit; | 112 | goto exit; |
112 | } | 113 | } |
113 | 114 | ||
diff --git a/drivers/usb/misc/auerswald.c b/drivers/usb/misc/auerswald.c index 42d4e6454a77..df7e1ecc810a 100644 --- a/drivers/usb/misc/auerswald.c +++ b/drivers/usb/misc/auerswald.c | |||
@@ -862,14 +862,16 @@ static void auerswald_ctrlread_wretcomplete (struct urb * urb) | |||
862 | pauerbuf_t bp = (pauerbuf_t) urb->context; | 862 | pauerbuf_t bp = (pauerbuf_t) urb->context; |
863 | pauerswald_t cp; | 863 | pauerswald_t cp; |
864 | int ret; | 864 | int ret; |
865 | int status = urb->status; | ||
866 | |||
865 | dbg ("auerswald_ctrlread_wretcomplete called"); | 867 | dbg ("auerswald_ctrlread_wretcomplete called"); |
866 | dbg ("complete with status: %d", urb->status); | 868 | dbg ("complete with status: %d", status); |
867 | cp = ((pauerswald_t)((char *)(bp->list)-(unsigned long)(&((pauerswald_t)0)->bufctl))); | 869 | cp = ((pauerswald_t)((char *)(bp->list)-(unsigned long)(&((pauerswald_t)0)->bufctl))); |
868 | 870 | ||
869 | /* check if it is possible to advance */ | 871 | /* check if it is possible to advance */ |
870 | if (!auerswald_status_retry (urb->status) || !cp->usbdev) { | 872 | if (!auerswald_status_retry(status) || !cp->usbdev) { |
871 | /* reuse the buffer */ | 873 | /* reuse the buffer */ |
872 | err ("control dummy: transmission error %d, can not retry", urb->status); | 874 | err ("control dummy: transmission error %d, can not retry", status); |
873 | auerbuf_releasebuf (bp); | 875 | auerbuf_releasebuf (bp); |
874 | /* Wake up all processes waiting for a buffer */ | 876 | /* Wake up all processes waiting for a buffer */ |
875 | wake_up (&cp->bufferwait); | 877 | wake_up (&cp->bufferwait); |
@@ -902,21 +904,23 @@ static void auerswald_ctrlread_complete (struct urb * urb) | |||
902 | pauerswald_t cp; | 904 | pauerswald_t cp; |
903 | pauerscon_t scp; | 905 | pauerscon_t scp; |
904 | pauerbuf_t bp = (pauerbuf_t) urb->context; | 906 | pauerbuf_t bp = (pauerbuf_t) urb->context; |
907 | int status = urb->status; | ||
905 | int ret; | 908 | int ret; |
909 | |||
906 | dbg ("auerswald_ctrlread_complete called"); | 910 | dbg ("auerswald_ctrlread_complete called"); |
907 | 911 | ||
908 | cp = ((pauerswald_t)((char *)(bp->list)-(unsigned long)(&((pauerswald_t)0)->bufctl))); | 912 | cp = ((pauerswald_t)((char *)(bp->list)-(unsigned long)(&((pauerswald_t)0)->bufctl))); |
909 | 913 | ||
910 | /* check if there is valid data in this urb */ | 914 | /* check if there is valid data in this urb */ |
911 | if (urb->status) { | 915 | if (status) { |
912 | dbg ("complete with non-zero status: %d", urb->status); | 916 | dbg ("complete with non-zero status: %d", status); |
913 | /* should we do a retry? */ | 917 | /* should we do a retry? */ |
914 | if (!auerswald_status_retry (urb->status) | 918 | if (!auerswald_status_retry(status) |
915 | || !cp->usbdev | 919 | || !cp->usbdev |
916 | || (cp->version < AUV_RETRY) | 920 | || (cp->version < AUV_RETRY) |
917 | || (bp->retries >= AU_RETRIES)) { | 921 | || (bp->retries >= AU_RETRIES)) { |
918 | /* reuse the buffer */ | 922 | /* reuse the buffer */ |
919 | err ("control read: transmission error %d, can not retry", urb->status); | 923 | err ("control read: transmission error %d, can not retry", status); |
920 | auerbuf_releasebuf (bp); | 924 | auerbuf_releasebuf (bp); |
921 | /* Wake up all processes waiting for a buffer */ | 925 | /* Wake up all processes waiting for a buffer */ |
922 | wake_up (&cp->bufferwait); | 926 | wake_up (&cp->bufferwait); |
@@ -974,12 +978,13 @@ static void auerswald_int_complete (struct urb * urb) | |||
974 | unsigned int channelid; | 978 | unsigned int channelid; |
975 | unsigned int bytecount; | 979 | unsigned int bytecount; |
976 | int ret; | 980 | int ret; |
981 | int status = urb->status; | ||
977 | pauerbuf_t bp = NULL; | 982 | pauerbuf_t bp = NULL; |
978 | pauerswald_t cp = (pauerswald_t) urb->context; | 983 | pauerswald_t cp = (pauerswald_t) urb->context; |
979 | 984 | ||
980 | dbg ("%s called", __FUNCTION__); | 985 | dbg ("%s called", __FUNCTION__); |
981 | 986 | ||
982 | switch (urb->status) { | 987 | switch (status) { |
983 | case 0: | 988 | case 0: |
984 | /* success */ | 989 | /* success */ |
985 | break; | 990 | break; |
@@ -987,10 +992,10 @@ static void auerswald_int_complete (struct urb * urb) | |||
987 | case -ENOENT: | 992 | case -ENOENT: |
988 | case -ESHUTDOWN: | 993 | case -ESHUTDOWN: |
989 | /* this urb is terminated, clean up */ | 994 | /* this urb is terminated, clean up */ |
990 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); | 995 | dbg("%s - urb shutting down with status: %d", __FUNCTION__, status); |
991 | return; | 996 | return; |
992 | default: | 997 | default: |
993 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); | 998 | dbg("%s - nonzero urb status received: %d", __FUNCTION__, status); |
994 | goto exit; | 999 | goto exit; |
995 | } | 1000 | } |
996 | 1001 | ||
diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c index e0f122e131d7..538b535e955b 100644 --- a/drivers/usb/misc/ftdi-elan.c +++ b/drivers/usb/misc/ftdi-elan.c | |||
@@ -44,6 +44,7 @@ | |||
44 | #include <linux/slab.h> | 44 | #include <linux/slab.h> |
45 | #include <linux/module.h> | 45 | #include <linux/module.h> |
46 | #include <linux/kref.h> | 46 | #include <linux/kref.h> |
47 | #include <linux/mutex.h> | ||
47 | #include <asm/uaccess.h> | 48 | #include <asm/uaccess.h> |
48 | #include <linux/usb.h> | 49 | #include <linux/usb.h> |
49 | #include <linux/workqueue.h> | 50 | #include <linux/workqueue.h> |
@@ -64,7 +65,7 @@ static struct workqueue_struct *respond_queue; | |||
64 | * ftdi_module_lock exists to protect access to global variables | 65 | * ftdi_module_lock exists to protect access to global variables |
65 | * | 66 | * |
66 | */ | 67 | */ |
67 | static struct semaphore ftdi_module_lock; | 68 | static struct mutex ftdi_module_lock; |
68 | static int ftdi_instances = 0; | 69 | static int ftdi_instances = 0; |
69 | static struct list_head ftdi_static_list; | 70 | static struct list_head ftdi_static_list; |
70 | /* | 71 | /* |
@@ -199,10 +200,10 @@ static void ftdi_elan_delete(struct kref *kref) | |||
199 | dev_warn(&ftdi->udev->dev, "FREEING ftdi=%p\n", ftdi); | 200 | dev_warn(&ftdi->udev->dev, "FREEING ftdi=%p\n", ftdi); |
200 | usb_put_dev(ftdi->udev); | 201 | usb_put_dev(ftdi->udev); |
201 | ftdi->disconnected += 1; | 202 | ftdi->disconnected += 1; |
202 | down(&ftdi_module_lock); | 203 | mutex_lock(&ftdi_module_lock); |
203 | list_del_init(&ftdi->ftdi_list); | 204 | list_del_init(&ftdi->ftdi_list); |
204 | ftdi_instances -= 1; | 205 | ftdi_instances -= 1; |
205 | up(&ftdi_module_lock); | 206 | mutex_unlock(&ftdi_module_lock); |
206 | kfree(ftdi->bulk_in_buffer); | 207 | kfree(ftdi->bulk_in_buffer); |
207 | ftdi->bulk_in_buffer = NULL; | 208 | ftdi->bulk_in_buffer = NULL; |
208 | } | 209 | } |
@@ -746,10 +747,12 @@ static ssize_t ftdi_elan_read(struct file *file, char __user *buffer, | |||
746 | static void ftdi_elan_write_bulk_callback(struct urb *urb) | 747 | static void ftdi_elan_write_bulk_callback(struct urb *urb) |
747 | { | 748 | { |
748 | struct usb_ftdi *ftdi = (struct usb_ftdi *)urb->context; | 749 | struct usb_ftdi *ftdi = (struct usb_ftdi *)urb->context; |
749 | if (urb->status && !(urb->status == -ENOENT || urb->status == | 750 | int status = urb->status; |
750 | -ECONNRESET || urb->status == -ESHUTDOWN)) { | 751 | |
752 | if (status && !(status == -ENOENT || status == -ECONNRESET || | ||
753 | status == -ESHUTDOWN)) { | ||
751 | dev_err(&ftdi->udev->dev, "urb=%p write bulk status received: %" | 754 | dev_err(&ftdi->udev->dev, "urb=%p write bulk status received: %" |
752 | "d\n", urb, urb->status); | 755 | "d\n", urb, status); |
753 | } | 756 | } |
754 | usb_buffer_free(urb->dev, urb->transfer_buffer_length, | 757 | usb_buffer_free(urb->dev, urb->transfer_buffer_length, |
755 | urb->transfer_buffer, urb->transfer_dma); | 758 | urb->transfer_buffer, urb->transfer_dma); |
@@ -2780,10 +2783,10 @@ static int ftdi_elan_probe(struct usb_interface *interface, | |||
2780 | return -ENOMEM; | 2783 | return -ENOMEM; |
2781 | } | 2784 | } |
2782 | memset(ftdi, 0x00, sizeof(struct usb_ftdi)); | 2785 | memset(ftdi, 0x00, sizeof(struct usb_ftdi)); |
2783 | down(&ftdi_module_lock); | 2786 | mutex_lock(&ftdi_module_lock); |
2784 | list_add_tail(&ftdi->ftdi_list, &ftdi_static_list); | 2787 | list_add_tail(&ftdi->ftdi_list, &ftdi_static_list); |
2785 | ftdi->sequence_num = ++ftdi_instances; | 2788 | ftdi->sequence_num = ++ftdi_instances; |
2786 | up(&ftdi_module_lock); | 2789 | mutex_unlock(&ftdi_module_lock); |
2787 | ftdi_elan_init_kref(ftdi); | 2790 | ftdi_elan_init_kref(ftdi); |
2788 | init_MUTEX(&ftdi->sw_lock); | 2791 | init_MUTEX(&ftdi->sw_lock); |
2789 | ftdi->udev = usb_get_dev(interface_to_usbdev(interface)); | 2792 | ftdi->udev = usb_get_dev(interface_to_usbdev(interface)); |
@@ -2909,7 +2912,7 @@ static int __init ftdi_elan_init(void) | |||
2909 | int result; | 2912 | int result; |
2910 | printk(KERN_INFO "driver %s built at %s on %s\n", ftdi_elan_driver.name, | 2913 | printk(KERN_INFO "driver %s built at %s on %s\n", ftdi_elan_driver.name, |
2911 | __TIME__, __DATE__); | 2914 | __TIME__, __DATE__); |
2912 | init_MUTEX(&ftdi_module_lock); | 2915 | mutex_init(&ftdi_module_lock); |
2913 | INIT_LIST_HEAD(&ftdi_static_list); | 2916 | INIT_LIST_HEAD(&ftdi_static_list); |
2914 | status_queue = create_singlethread_workqueue("ftdi-status-control"); | 2917 | status_queue = create_singlethread_workqueue("ftdi-status-control"); |
2915 | if (!status_queue) | 2918 | if (!status_queue) |
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c index 28548d186712..46d9f27ec173 100644 --- a/drivers/usb/misc/iowarrior.c +++ b/drivers/usb/misc/iowarrior.c | |||
@@ -158,9 +158,10 @@ static void iowarrior_callback(struct urb *urb) | |||
158 | int read_idx; | 158 | int read_idx; |
159 | int aux_idx; | 159 | int aux_idx; |
160 | int offset; | 160 | int offset; |
161 | int status; | 161 | int status = urb->status; |
162 | int retval; | ||
162 | 163 | ||
163 | switch (urb->status) { | 164 | switch (status) { |
164 | case 0: | 165 | case 0: |
165 | /* success */ | 166 | /* success */ |
166 | break; | 167 | break; |
@@ -213,10 +214,10 @@ static void iowarrior_callback(struct urb *urb) | |||
213 | wake_up_interruptible(&dev->read_wait); | 214 | wake_up_interruptible(&dev->read_wait); |
214 | 215 | ||
215 | exit: | 216 | exit: |
216 | status = usb_submit_urb(urb, GFP_ATOMIC); | 217 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
217 | if (status) | 218 | if (retval) |
218 | dev_err(&dev->interface->dev, "%s - usb_submit_urb failed with result %d", | 219 | dev_err(&dev->interface->dev, "%s - usb_submit_urb failed with result %d", |
219 | __FUNCTION__, status); | 220 | __FUNCTION__, retval); |
220 | 221 | ||
221 | } | 222 | } |
222 | 223 | ||
@@ -226,13 +227,15 @@ exit: | |||
226 | static void iowarrior_write_callback(struct urb *urb) | 227 | static void iowarrior_write_callback(struct urb *urb) |
227 | { | 228 | { |
228 | struct iowarrior *dev; | 229 | struct iowarrior *dev; |
230 | int status = urb->status; | ||
231 | |||
229 | dev = (struct iowarrior *)urb->context; | 232 | dev = (struct iowarrior *)urb->context; |
230 | /* sync/async unlink faults aren't errors */ | 233 | /* sync/async unlink faults aren't errors */ |
231 | if (urb->status && | 234 | if (status && |
232 | !(urb->status == -ENOENT || | 235 | !(status == -ENOENT || |
233 | urb->status == -ECONNRESET || urb->status == -ESHUTDOWN)) { | 236 | status == -ECONNRESET || status == -ESHUTDOWN)) { |
234 | dbg("%s - nonzero write bulk status received: %d", | 237 | dbg("%s - nonzero write bulk status received: %d", |
235 | __func__, urb->status); | 238 | __func__, status); |
236 | } | 239 | } |
237 | /* free up our allocated buffer */ | 240 | /* free up our allocated buffer */ |
238 | usb_buffer_free(urb->dev, urb->transfer_buffer_length, | 241 | usb_buffer_free(urb->dev, urb->transfer_buffer_length, |
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c index 5e950b90c541..8208496dfc63 100644 --- a/drivers/usb/misc/ldusb.c +++ b/drivers/usb/misc/ldusb.c | |||
@@ -219,16 +219,17 @@ static void ld_usb_interrupt_in_callback(struct urb *urb) | |||
219 | struct ld_usb *dev = urb->context; | 219 | struct ld_usb *dev = urb->context; |
220 | size_t *actual_buffer; | 220 | size_t *actual_buffer; |
221 | unsigned int next_ring_head; | 221 | unsigned int next_ring_head; |
222 | int status = urb->status; | ||
222 | int retval; | 223 | int retval; |
223 | 224 | ||
224 | if (urb->status) { | 225 | if (status) { |
225 | if (urb->status == -ENOENT || | 226 | if (status == -ENOENT || |
226 | urb->status == -ECONNRESET || | 227 | status == -ECONNRESET || |
227 | urb->status == -ESHUTDOWN) { | 228 | status == -ESHUTDOWN) { |
228 | goto exit; | 229 | goto exit; |
229 | } else { | 230 | } else { |
230 | dbg_info(&dev->intf->dev, "%s: nonzero status received: %d\n", | 231 | dbg_info(&dev->intf->dev, "%s: nonzero status received: %d\n", |
231 | __FUNCTION__, urb->status); | 232 | __FUNCTION__, status); |
232 | spin_lock(&dev->rbsl); | 233 | spin_lock(&dev->rbsl); |
233 | goto resubmit; /* maybe we can recover */ | 234 | goto resubmit; /* maybe we can recover */ |
234 | } | 235 | } |
@@ -275,14 +276,15 @@ exit: | |||
275 | static void ld_usb_interrupt_out_callback(struct urb *urb) | 276 | static void ld_usb_interrupt_out_callback(struct urb *urb) |
276 | { | 277 | { |
277 | struct ld_usb *dev = urb->context; | 278 | struct ld_usb *dev = urb->context; |
279 | int status = urb->status; | ||
278 | 280 | ||
279 | /* sync/async unlink faults aren't errors */ | 281 | /* sync/async unlink faults aren't errors */ |
280 | if (urb->status && !(urb->status == -ENOENT || | 282 | if (status && !(status == -ENOENT || |
281 | urb->status == -ECONNRESET || | 283 | status == -ECONNRESET || |
282 | urb->status == -ESHUTDOWN)) | 284 | status == -ESHUTDOWN)) |
283 | dbg_info(&dev->intf->dev, | 285 | dbg_info(&dev->intf->dev, |
284 | "%s - nonzero write interrupt status received: %d\n", | 286 | "%s - nonzero write interrupt status received: %d\n", |
285 | __FUNCTION__, urb->status); | 287 | __FUNCTION__, status); |
286 | 288 | ||
287 | dev->interrupt_out_busy = 0; | 289 | dev->interrupt_out_busy = 0; |
288 | wake_up_interruptible(&dev->write_wait); | 290 | wake_up_interruptible(&dev->write_wait); |
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c index 2ed0daea894c..561970b889a5 100644 --- a/drivers/usb/misc/legousbtower.c +++ b/drivers/usb/misc/legousbtower.c | |||
@@ -742,19 +742,20 @@ exit: | |||
742 | static void tower_interrupt_in_callback (struct urb *urb) | 742 | static void tower_interrupt_in_callback (struct urb *urb) |
743 | { | 743 | { |
744 | struct lego_usb_tower *dev = (struct lego_usb_tower *)urb->context; | 744 | struct lego_usb_tower *dev = (struct lego_usb_tower *)urb->context; |
745 | int status = urb->status; | ||
745 | int retval; | 746 | int retval; |
746 | 747 | ||
747 | dbg(4, "%s: enter, status %d", __FUNCTION__, urb->status); | 748 | dbg(4, "%s: enter, status %d", __FUNCTION__, status); |
748 | 749 | ||
749 | lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer); | 750 | lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer); |
750 | 751 | ||
751 | if (urb->status) { | 752 | if (status) { |
752 | if (urb->status == -ENOENT || | 753 | if (status == -ENOENT || |
753 | urb->status == -ECONNRESET || | 754 | status == -ECONNRESET || |
754 | urb->status == -ESHUTDOWN) { | 755 | status == -ESHUTDOWN) { |
755 | goto exit; | 756 | goto exit; |
756 | } else { | 757 | } else { |
757 | dbg(1, "%s: nonzero status received: %d", __FUNCTION__, urb->status); | 758 | dbg(1, "%s: nonzero status received: %d", __FUNCTION__, status); |
758 | goto resubmit; /* maybe we can recover */ | 759 | goto resubmit; /* maybe we can recover */ |
759 | } | 760 | } |
760 | } | 761 | } |
@@ -788,7 +789,7 @@ exit: | |||
788 | wake_up_interruptible (&dev->read_wait); | 789 | wake_up_interruptible (&dev->read_wait); |
789 | 790 | ||
790 | lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer); | 791 | lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer); |
791 | dbg(4, "%s: leave, status %d", __FUNCTION__, urb->status); | 792 | dbg(4, "%s: leave, status %d", __FUNCTION__, status); |
792 | } | 793 | } |
793 | 794 | ||
794 | 795 | ||
@@ -798,23 +799,24 @@ exit: | |||
798 | static void tower_interrupt_out_callback (struct urb *urb) | 799 | static void tower_interrupt_out_callback (struct urb *urb) |
799 | { | 800 | { |
800 | struct lego_usb_tower *dev = (struct lego_usb_tower *)urb->context; | 801 | struct lego_usb_tower *dev = (struct lego_usb_tower *)urb->context; |
802 | int status = urb->status; | ||
801 | 803 | ||
802 | dbg(4, "%s: enter, status %d", __FUNCTION__, urb->status); | 804 | dbg(4, "%s: enter, status %d", __FUNCTION__, status); |
803 | lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer); | 805 | lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer); |
804 | 806 | ||
805 | /* sync/async unlink faults aren't errors */ | 807 | /* sync/async unlink faults aren't errors */ |
806 | if (urb->status && !(urb->status == -ENOENT || | 808 | if (status && !(status == -ENOENT || |
807 | urb->status == -ECONNRESET || | 809 | status == -ECONNRESET || |
808 | urb->status == -ESHUTDOWN)) { | 810 | status == -ESHUTDOWN)) { |
809 | dbg(1, "%s - nonzero write bulk status received: %d", | 811 | dbg(1, "%s - nonzero write bulk status received: %d", |
810 | __FUNCTION__, urb->status); | 812 | __FUNCTION__, status); |
811 | } | 813 | } |
812 | 814 | ||
813 | dev->interrupt_out_busy = 0; | 815 | dev->interrupt_out_busy = 0; |
814 | wake_up_interruptible(&dev->write_wait); | 816 | wake_up_interruptible(&dev->write_wait); |
815 | 817 | ||
816 | lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer); | 818 | lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer); |
817 | dbg(4, "%s: leave, status %d", __FUNCTION__, urb->status); | 819 | dbg(4, "%s: leave, status %d", __FUNCTION__, status); |
818 | } | 820 | } |
819 | 821 | ||
820 | 822 | ||
diff --git a/drivers/usb/misc/phidgetkit.c b/drivers/usb/misc/phidgetkit.c index 371bf2b1197d..aa9bcceabe74 100644 --- a/drivers/usb/misc/phidgetkit.c +++ b/drivers/usb/misc/phidgetkit.c | |||
@@ -305,9 +305,10 @@ static void interfacekit_irq(struct urb *urb) | |||
305 | struct interfacekit *kit = urb->context; | 305 | struct interfacekit *kit = urb->context; |
306 | unsigned char *buffer = kit->data; | 306 | unsigned char *buffer = kit->data; |
307 | int i, level, sensor; | 307 | int i, level, sensor; |
308 | int status; | 308 | int retval; |
309 | int status = urb->status; | ||
309 | 310 | ||
310 | switch (urb->status) { | 311 | switch (status) { |
311 | case 0: /* success */ | 312 | case 0: /* success */ |
312 | break; | 313 | break; |
313 | case -ECONNRESET: /* unlink */ | 314 | case -ECONNRESET: /* unlink */ |
@@ -377,11 +378,11 @@ static void interfacekit_irq(struct urb *urb) | |||
377 | schedule_delayed_work(&kit->do_notify, 0); | 378 | schedule_delayed_work(&kit->do_notify, 0); |
378 | 379 | ||
379 | resubmit: | 380 | resubmit: |
380 | status = usb_submit_urb(urb, GFP_ATOMIC); | 381 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
381 | if (status) | 382 | if (retval) |
382 | err("can't resubmit intr, %s-%s/interfacekit0, status %d", | 383 | err("can't resubmit intr, %s-%s/interfacekit0, retval %d", |
383 | kit->udev->bus->bus_name, | 384 | kit->udev->bus->bus_name, |
384 | kit->udev->devpath, status); | 385 | kit->udev->devpath, retval); |
385 | } | 386 | } |
386 | 387 | ||
387 | static void do_notify(struct work_struct *work) | 388 | static void do_notify(struct work_struct *work) |
diff --git a/drivers/usb/misc/phidgetmotorcontrol.c b/drivers/usb/misc/phidgetmotorcontrol.c index 5727e1ea2f91..df0ebcdb9d6a 100644 --- a/drivers/usb/misc/phidgetmotorcontrol.c +++ b/drivers/usb/misc/phidgetmotorcontrol.c | |||
@@ -95,9 +95,10 @@ static void motorcontrol_irq(struct urb *urb) | |||
95 | struct motorcontrol *mc = urb->context; | 95 | struct motorcontrol *mc = urb->context; |
96 | unsigned char *buffer = mc->data; | 96 | unsigned char *buffer = mc->data; |
97 | int i, level; | 97 | int i, level; |
98 | int status; | 98 | int retval; |
99 | int status = urb->status;; | ||
99 | 100 | ||
100 | switch (urb->status) { | 101 | switch (status) { |
101 | case 0: /* success */ | 102 | case 0: /* success */ |
102 | break; | 103 | break; |
103 | case -ECONNRESET: /* unlink */ | 104 | case -ECONNRESET: /* unlink */ |
@@ -151,12 +152,12 @@ static void motorcontrol_irq(struct urb *urb) | |||
151 | schedule_delayed_work(&mc->do_notify, 0); | 152 | schedule_delayed_work(&mc->do_notify, 0); |
152 | 153 | ||
153 | resubmit: | 154 | resubmit: |
154 | status = usb_submit_urb(urb, GFP_ATOMIC); | 155 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
155 | if (status) | 156 | if (retval) |
156 | dev_err(&mc->intf->dev, | 157 | dev_err(&mc->intf->dev, |
157 | "can't resubmit intr, %s-%s/motorcontrol0, status %d", | 158 | "can't resubmit intr, %s-%s/motorcontrol0, retval %d", |
158 | mc->udev->bus->bus_name, | 159 | mc->udev->bus->bus_name, |
159 | mc->udev->devpath, status); | 160 | mc->udev->devpath, retval); |
160 | } | 161 | } |
161 | 162 | ||
162 | static void do_notify(struct work_struct *work) | 163 | static void do_notify(struct work_struct *work) |
diff --git a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c index 504f7221b0d0..719842032712 100644 --- a/drivers/usb/misc/usblcd.c +++ b/drivers/usb/misc/usblcd.c | |||
@@ -176,16 +176,17 @@ static int lcd_ioctl(struct inode *inode, struct file *file, unsigned int cmd, u | |||
176 | static void lcd_write_bulk_callback(struct urb *urb) | 176 | static void lcd_write_bulk_callback(struct urb *urb) |
177 | { | 177 | { |
178 | struct usb_lcd *dev; | 178 | struct usb_lcd *dev; |
179 | int status = urb->status; | ||
179 | 180 | ||
180 | dev = (struct usb_lcd *)urb->context; | 181 | dev = (struct usb_lcd *)urb->context; |
181 | 182 | ||
182 | /* sync/async unlink faults aren't errors */ | 183 | /* sync/async unlink faults aren't errors */ |
183 | if (urb->status && | 184 | if (status && |
184 | !(urb->status == -ENOENT || | 185 | !(status == -ENOENT || |
185 | urb->status == -ECONNRESET || | 186 | status == -ECONNRESET || |
186 | urb->status == -ESHUTDOWN)) { | 187 | status == -ESHUTDOWN)) { |
187 | dbg("USBLCD: %s - nonzero write bulk status received: %d", | 188 | dbg("USBLCD: %s - nonzero write bulk status received: %d", |
188 | __FUNCTION__, urb->status); | 189 | __FUNCTION__, status); |
189 | } | 190 | } |
190 | 191 | ||
191 | /* free up our allocated buffer */ | 192 | /* free up our allocated buffer */ |
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c index fb321864a92d..e901d31e051b 100644 --- a/drivers/usb/misc/usbtest.c +++ b/drivers/usb/misc/usbtest.c | |||
@@ -768,8 +768,8 @@ static void ctrl_complete (struct urb *urb) | |||
768 | 768 | ||
769 | /* some faults are allowed, not required */ | 769 | /* some faults are allowed, not required */ |
770 | if (subcase->expected > 0 && ( | 770 | if (subcase->expected > 0 && ( |
771 | ((urb->status == -subcase->expected /* happened */ | 771 | ((status == -subcase->expected /* happened */ |
772 | || urb->status == 0)))) /* didn't */ | 772 | || status == 0)))) /* didn't */ |
773 | status = 0; | 773 | status = 0; |
774 | /* sometimes more than one fault is allowed */ | 774 | /* sometimes more than one fault is allowed */ |
775 | else if (subcase->number == 12 && status == -EPIPE) | 775 | else if (subcase->number == 12 && status == -EPIPE) |
diff --git a/drivers/usb/misc/uss720.c b/drivers/usb/misc/uss720.c index 1a60f9c473ad..2734fe2b9c43 100644 --- a/drivers/usb/misc/uss720.c +++ b/drivers/usb/misc/uss720.c | |||
@@ -111,12 +111,13 @@ static void async_complete(struct urb *urb) | |||
111 | struct uss720_async_request *rq; | 111 | struct uss720_async_request *rq; |
112 | struct parport *pp; | 112 | struct parport *pp; |
113 | struct parport_uss720_private *priv; | 113 | struct parport_uss720_private *priv; |
114 | int status = urb->status; | ||
114 | 115 | ||
115 | rq = urb->context; | 116 | rq = urb->context; |
116 | priv = rq->priv; | 117 | priv = rq->priv; |
117 | pp = priv->pp; | 118 | pp = priv->pp; |
118 | if (urb->status) { | 119 | if (status) { |
119 | err("async_complete: urb error %d", urb->status); | 120 | err("async_complete: urb error %d", status); |
120 | } else if (rq->dr.bRequest == 3) { | 121 | } else if (rq->dr.bRequest == 3) { |
121 | memcpy(priv->reg, rq->reg, sizeof(priv->reg)); | 122 | memcpy(priv->reg, rq->reg, sizeof(priv->reg)); |
122 | #if 0 | 123 | #if 0 |
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c index 982b773d71e6..8f27a9e1c36b 100644 --- a/drivers/usb/mon/mon_text.c +++ b/drivers/usb/mon/mon_text.c | |||
@@ -340,7 +340,7 @@ static int mon_text_open(struct inode *inode, struct file *file) | |||
340 | snprintf(rp->slab_name, SLAB_NAME_SZ, "mon_text_%p", rp); | 340 | snprintf(rp->slab_name, SLAB_NAME_SZ, "mon_text_%p", rp); |
341 | rp->e_slab = kmem_cache_create(rp->slab_name, | 341 | rp->e_slab = kmem_cache_create(rp->slab_name, |
342 | sizeof(struct mon_event_text), sizeof(long), 0, | 342 | sizeof(struct mon_event_text), sizeof(long), 0, |
343 | mon_text_ctor, NULL); | 343 | mon_text_ctor); |
344 | if (rp->e_slab == NULL) { | 344 | if (rp->e_slab == NULL) { |
345 | rc = -ENOMEM; | 345 | rc = -ENOMEM; |
346 | goto err_slab; | 346 | goto err_slab; |
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c index 0d3903691e8c..b8670905bc3a 100644 --- a/drivers/usb/serial/io_ti.c +++ b/drivers/usb/serial/io_ti.c | |||
@@ -2794,16 +2794,14 @@ static void edge_shutdown (struct usb_serial *serial) | |||
2794 | 2794 | ||
2795 | dbg ("%s", __FUNCTION__); | 2795 | dbg ("%s", __FUNCTION__); |
2796 | 2796 | ||
2797 | for (i=0; i < serial->num_ports; ++i) { | 2797 | for (i = 0; i < serial->num_ports; ++i) { |
2798 | edge_port = usb_get_serial_port_data(serial->port[i]); | 2798 | edge_port = usb_get_serial_port_data(serial->port[i]); |
2799 | edge_remove_sysfs_attrs(edge_port->port); | 2799 | edge_remove_sysfs_attrs(edge_port->port); |
2800 | if (edge_port) { | 2800 | edge_buf_free(edge_port->ep_out_buf); |
2801 | edge_buf_free(edge_port->ep_out_buf); | 2801 | kfree(edge_port); |
2802 | kfree(edge_port); | ||
2803 | } | ||
2804 | usb_set_serial_port_data(serial->port[i], NULL); | 2802 | usb_set_serial_port_data(serial->port[i], NULL); |
2805 | } | 2803 | } |
2806 | kfree (usb_get_serial_data(serial)); | 2804 | kfree(usb_get_serial_data(serial)); |
2807 | usb_set_serial_data(serial, NULL); | 2805 | usb_set_serial_data(serial, NULL); |
2808 | } | 2806 | } |
2809 | 2807 | ||
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c index 231b584f6d0f..01e811becec4 100644 --- a/drivers/usb/serial/mos7720.c +++ b/drivers/usb/serial/mos7720.c | |||
@@ -110,11 +110,6 @@ static void mos7720_interrupt_callback(struct urb *urb) | |||
110 | 110 | ||
111 | dbg("%s"," : Entering\n"); | 111 | dbg("%s"," : Entering\n"); |
112 | 112 | ||
113 | if (!urb) { | ||
114 | dbg("%s","Invalid Pointer !!!!:\n"); | ||
115 | return; | ||
116 | } | ||
117 | |||
118 | switch (status) { | 113 | switch (status) { |
119 | case 0: | 114 | case 0: |
120 | /* success */ | 115 | /* success */ |
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index 37f41f576d3d..f76480f1455d 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c | |||
@@ -436,11 +436,6 @@ static void mos7840_control_callback(struct urb *urb) | |||
436 | int result = 0; | 436 | int result = 0; |
437 | int status = urb->status; | 437 | int status = urb->status; |
438 | 438 | ||
439 | if (!urb) { | ||
440 | dbg("%s", "Invalid Pointer !!!!:\n"); | ||
441 | return; | ||
442 | } | ||
443 | |||
444 | mos7840_port = (struct moschip_port *)urb->context; | 439 | mos7840_port = (struct moschip_port *)urb->context; |
445 | 440 | ||
446 | switch (status) { | 441 | switch (status) { |
@@ -525,10 +520,6 @@ static void mos7840_interrupt_callback(struct urb *urb) | |||
525 | int status = urb->status; | 520 | int status = urb->status; |
526 | 521 | ||
527 | dbg("%s", " : Entering\n"); | 522 | dbg("%s", " : Entering\n"); |
528 | if (!urb) { | ||
529 | dbg("%s", "Invalid Pointer !!!!:\n"); | ||
530 | return; | ||
531 | } | ||
532 | 523 | ||
533 | switch (status) { | 524 | switch (status) { |
534 | case 0: | 525 | case 0: |
@@ -676,11 +667,6 @@ static void mos7840_bulk_in_callback(struct urb *urb) | |||
676 | struct tty_struct *tty; | 667 | struct tty_struct *tty; |
677 | int status = urb->status; | 668 | int status = urb->status; |
678 | 669 | ||
679 | if (!urb) { | ||
680 | dbg("%s", "Invalid Pointer !!!!:\n"); | ||
681 | return; | ||
682 | } | ||
683 | |||
684 | if (status) { | 670 | if (status) { |
685 | dbg("nonzero read bulk status received: %d", status); | 671 | dbg("nonzero read bulk status received: %d", status); |
686 | return; | 672 | return; |
@@ -753,11 +739,6 @@ static void mos7840_bulk_out_data_callback(struct urb *urb) | |||
753 | int status = urb->status; | 739 | int status = urb->status; |
754 | int i; | 740 | int i; |
755 | 741 | ||
756 | if (!urb) { | ||
757 | dbg("%s", "Invalid Pointer !!!!:\n"); | ||
758 | return; | ||
759 | } | ||
760 | |||
761 | mos7840_port = (struct moschip_port *)urb->context; | 742 | mos7840_port = (struct moschip_port *)urb->context; |
762 | spin_lock(&mos7840_port->pool_lock); | 743 | spin_lock(&mos7840_port->pool_lock); |
763 | for (i = 0; i < NUM_URBS; i++) { | 744 | for (i = 0; i < NUM_URBS; i++) { |
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c index e7db20343d1a..0794ccdebfd4 100644 --- a/drivers/usb/serial/sierra.c +++ b/drivers/usb/serial/sierra.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | USB Driver for Sierra Wireless | 2 | USB Driver for Sierra Wireless |
3 | 3 | ||
4 | Copyright (C) 2006 Kevin Lloyd <linux@sierrawireless.com> | 4 | Copyright (C) 2006, 2007 Kevin Lloyd <linux@sierrawireless.com> |
5 | 5 | ||
6 | IMPORTANT DISCLAIMER: This driver is not commercially supported by | 6 | IMPORTANT DISCLAIMER: This driver is not commercially supported by |
7 | Sierra Wireless. Use at your own risk. | 7 | Sierra Wireless. Use at your own risk. |
@@ -12,10 +12,9 @@ | |||
12 | 12 | ||
13 | Portions based on the option driver by Matthias Urlichs <smurf@smurf.noris.de> | 13 | Portions based on the option driver by Matthias Urlichs <smurf@smurf.noris.de> |
14 | Whom based his on the Keyspan driver by Hugh Blemings <hugh@blemings.org> | 14 | Whom based his on the Keyspan driver by Hugh Blemings <hugh@blemings.org> |
15 | |||
16 | */ | 15 | */ |
17 | 16 | ||
18 | #define DRIVER_VERSION "v.1.0.6" | 17 | #define DRIVER_VERSION "v.1.2.5b" |
19 | #define DRIVER_AUTHOR "Kevin Lloyd <linux@sierrawireless.com>" | 18 | #define DRIVER_AUTHOR "Kevin Lloyd <linux@sierrawireless.com>" |
20 | #define DRIVER_DESC "USB Driver for Sierra Wireless USB modems" | 19 | #define DRIVER_DESC "USB Driver for Sierra Wireless USB modems" |
21 | 20 | ||
@@ -28,23 +27,98 @@ | |||
28 | #include <linux/usb.h> | 27 | #include <linux/usb.h> |
29 | #include <linux/usb/serial.h> | 28 | #include <linux/usb/serial.h> |
30 | 29 | ||
30 | #define SWIMS_USB_REQUEST_SetMode 0x0B | ||
31 | #define SWIMS_USB_REQUEST_TYPE_SetMode 0x40 | ||
32 | #define SWIMS_USB_INDEX_SetMode 0x0000 | ||
33 | #define SWIMS_SET_MODE_Modem 0x0001 | ||
34 | |||
35 | /* per port private data */ | ||
36 | #define N_IN_URB 4 | ||
37 | #define N_OUT_URB 4 | ||
38 | #define IN_BUFLEN 4096 | ||
39 | |||
40 | static int debug; | ||
41 | |||
42 | enum devicetype { | ||
43 | DEVICE_3_PORT = 0, | ||
44 | DEVICE_1_PORT = 1, | ||
45 | DEVICE_INSTALLER = 2, | ||
46 | }; | ||
47 | |||
48 | int sierra_set_power_state(struct usb_device *udev, __u16 swiState) | ||
49 | { | ||
50 | int result; | ||
51 | dev_dbg(&udev->dev, "%s", "SET POWER STATE"); | ||
52 | result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | ||
53 | 0x00, /* __u8 request */ | ||
54 | 0x40, /* __u8 request type */ | ||
55 | swiState, /* __u16 value */ | ||
56 | 0, /* __u16 index */ | ||
57 | NULL, /* void *data */ | ||
58 | 0, /* __u16 size */ | ||
59 | USB_CTRL_SET_TIMEOUT); /* int timeout */ | ||
60 | return result; | ||
61 | } | ||
62 | |||
63 | int sierra_set_ms_mode(struct usb_device *udev, __u16 eSocMode) | ||
64 | { | ||
65 | int result; | ||
66 | dev_dbg(&udev->dev, "%s", "DEVICE MODE SWITCH"); | ||
67 | result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | ||
68 | SWIMS_USB_REQUEST_SetMode, /* __u8 request */ | ||
69 | SWIMS_USB_REQUEST_TYPE_SetMode, /* __u8 request type */ | ||
70 | eSocMode, /* __u16 value */ | ||
71 | SWIMS_USB_INDEX_SetMode, /* __u16 index */ | ||
72 | NULL, /* void *data */ | ||
73 | 0, /* __u16 size */ | ||
74 | USB_CTRL_SET_TIMEOUT); /* int timeout */ | ||
75 | return result; | ||
76 | } | ||
77 | |||
78 | int sierra_probe(struct usb_interface *iface, const struct usb_device_id *id) | ||
79 | { | ||
80 | int result; | ||
81 | struct usb_device *udev; | ||
82 | |||
83 | udev = usb_get_dev(interface_to_usbdev(iface)); | ||
84 | |||
85 | /* Check if in installer mode */ | ||
86 | if (id->driver_info == DEVICE_INSTALLER) { | ||
87 | dev_dbg(&udev->dev, "%s", "FOUND DEVICE(SW)\n"); | ||
88 | result = sierra_set_ms_mode(udev, SWIMS_SET_MODE_Modem); | ||
89 | /*We do not want to bind to the device when in installer mode*/ | ||
90 | return -EIO; | ||
91 | } | ||
92 | |||
93 | return usb_serial_probe(iface, id); | ||
94 | } | ||
31 | 95 | ||
32 | static struct usb_device_id id_table [] = { | 96 | static struct usb_device_id id_table [] = { |
33 | { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */ | 97 | { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */ |
34 | { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */ | 98 | { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */ |
35 | { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */ | 99 | { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */ |
100 | { USB_DEVICE(0x0f30, 0x1b1d) }, /* Sierra Wireless MC5720 */ | ||
36 | { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */ | 101 | { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */ |
37 | { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */ | 102 | { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */ |
38 | { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless AirCard 595U */ | ||
39 | { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */ | 103 | { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */ |
104 | { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U */ | ||
105 | |||
40 | { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */ | 106 | { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */ |
41 | { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */ | 107 | { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */ |
42 | { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */ | 108 | { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */ |
43 | { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 */ | 109 | { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */ |
44 | { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */ | 110 | { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */ |
111 | { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/ | ||
112 | { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/ | ||
113 | { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */ | ||
114 | { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ | ||
115 | { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */ | ||
116 | { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881 E */ | ||
45 | 117 | ||
46 | { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */ | 118 | { USB_DEVICE(0x1199, 0x0112), .driver_info = DEVICE_1_PORT }, /* Sierra Wireless AirCard 580 */ |
47 | { USB_DEVICE(0x0F3D, 0x0112) }, /* AirPrime/Sierra PC 5220 */ | 119 | { USB_DEVICE(0x0F3D, 0x0112), .driver_info = DEVICE_1_PORT }, /* Airprime/Sierra PC 5220 */ |
120 | |||
121 | { USB_DEVICE(0x1199, 0x0FFF), .driver_info = DEVICE_INSTALLER}, | ||
48 | { } | 122 | { } |
49 | }; | 123 | }; |
50 | MODULE_DEVICE_TABLE(usb, id_table); | 124 | MODULE_DEVICE_TABLE(usb, id_table); |
@@ -58,35 +132,36 @@ static struct usb_device_id id_table_1port [] = { | |||
58 | static struct usb_device_id id_table_3port [] = { | 132 | static struct usb_device_id id_table_3port [] = { |
59 | { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */ | 133 | { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */ |
60 | { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */ | 134 | { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */ |
135 | { USB_DEVICE(0x0f30, 0x1b1d) }, /* Sierra Wireless MC5720 */ | ||
61 | { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */ | 136 | { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */ |
62 | { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */ | 137 | { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */ |
63 | { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */ | 138 | { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */ |
64 | { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless AirCard 595U */ | ||
65 | { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */ | 139 | { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */ |
140 | { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U*/ | ||
141 | |||
66 | { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */ | 142 | { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */ |
67 | { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */ | 143 | { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */ |
68 | { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */ | 144 | { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */ |
69 | { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 */ | 145 | { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */ |
70 | { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */ | 146 | { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */ |
147 | { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/ | ||
148 | { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/ | ||
149 | { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */ | ||
150 | { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ | ||
151 | { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880E */ | ||
152 | { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881E */ | ||
71 | { } | 153 | { } |
72 | }; | 154 | }; |
73 | 155 | ||
74 | static struct usb_driver sierra_driver = { | 156 | static struct usb_driver sierra_driver = { |
75 | .name = "sierra", | 157 | .name = "sierra", |
76 | .probe = usb_serial_probe, | 158 | .probe = sierra_probe, |
77 | .disconnect = usb_serial_disconnect, | 159 | .disconnect = usb_serial_disconnect, |
78 | .id_table = id_table, | 160 | .id_table = id_table, |
79 | .no_dynamic_id = 1, | 161 | .no_dynamic_id = 1, |
80 | }; | 162 | }; |
81 | 163 | ||
82 | 164 | ||
83 | static int debug; | ||
84 | |||
85 | /* per port private data */ | ||
86 | #define N_IN_URB 4 | ||
87 | #define N_OUT_URB 4 | ||
88 | #define IN_BUFLEN 4096 | ||
89 | |||
90 | struct sierra_port_private { | 165 | struct sierra_port_private { |
91 | spinlock_t lock; /* lock the structure */ | 166 | spinlock_t lock; /* lock the structure */ |
92 | int outstanding_urbs; /* number of out urbs in flight */ | 167 | int outstanding_urbs; /* number of out urbs in flight */ |
@@ -421,7 +496,6 @@ static int sierra_open(struct usb_serial_port *port, struct file *filp) | |||
421 | int i; | 496 | int i; |
422 | struct urb *urb; | 497 | struct urb *urb; |
423 | int result; | 498 | int result; |
424 | __u16 set_mode_dzero = 0x0000; | ||
425 | 499 | ||
426 | portdata = usb_get_serial_port_data(port); | 500 | portdata = usb_get_serial_port_data(port); |
427 | 501 | ||
@@ -457,12 +531,6 @@ static int sierra_open(struct usb_serial_port *port, struct file *filp) | |||
457 | 531 | ||
458 | port->tty->low_latency = 1; | 532 | port->tty->low_latency = 1; |
459 | 533 | ||
460 | /* set mode to D0 */ | ||
461 | result = usb_control_msg(serial->dev, | ||
462 | usb_rcvctrlpipe(serial->dev, 0), | ||
463 | 0x00, 0x40, set_mode_dzero, 0, NULL, | ||
464 | 0, USB_CTRL_SET_TIMEOUT); | ||
465 | |||
466 | sierra_send_setup(port); | 534 | sierra_send_setup(port); |
467 | 535 | ||
468 | /* start up the interrupt endpoint if we have one */ | 536 | /* start up the interrupt endpoint if we have one */ |
@@ -510,6 +578,9 @@ static int sierra_startup(struct usb_serial *serial) | |||
510 | 578 | ||
511 | dbg("%s", __FUNCTION__); | 579 | dbg("%s", __FUNCTION__); |
512 | 580 | ||
581 | /*Set Device mode to D0 */ | ||
582 | sierra_set_power_state(serial->dev, 0x0000); | ||
583 | |||
513 | /* Now setup per port private data */ | 584 | /* Now setup per port private data */ |
514 | for (i = 0; i < serial->num_ports; i++) { | 585 | for (i = 0; i < serial->num_ports; i++) { |
515 | port = serial->port[i]; | 586 | port = serial->port[i]; |
diff --git a/drivers/usb/storage/dpcm.c b/drivers/usb/storage/dpcm.c index 1628cb258562..9a410b5a6e5b 100644 --- a/drivers/usb/storage/dpcm.c +++ b/drivers/usb/storage/dpcm.c | |||
@@ -46,43 +46,43 @@ | |||
46 | */ | 46 | */ |
47 | int dpcm_transport(struct scsi_cmnd *srb, struct us_data *us) | 47 | int dpcm_transport(struct scsi_cmnd *srb, struct us_data *us) |
48 | { | 48 | { |
49 | int ret; | 49 | int ret; |
50 | 50 | ||
51 | if(srb == NULL) | 51 | if (srb == NULL) |
52 | return USB_STOR_TRANSPORT_ERROR; | 52 | return USB_STOR_TRANSPORT_ERROR; |
53 | 53 | ||
54 | US_DEBUGP("dpcm_transport: LUN=%d\n", srb->device->lun); | 54 | US_DEBUGP("dpcm_transport: LUN=%d\n", srb->device->lun); |
55 | 55 | ||
56 | switch(srb->device->lun) { | 56 | switch (srb->device->lun) { |
57 | case 0: | 57 | case 0: |
58 | 58 | ||
59 | /* | 59 | /* |
60 | * LUN 0 corresponds to the CompactFlash card reader. | 60 | * LUN 0 corresponds to the CompactFlash card reader. |
61 | */ | 61 | */ |
62 | ret = usb_stor_CB_transport(srb, us); | 62 | ret = usb_stor_CB_transport(srb, us); |
63 | break; | 63 | break; |
64 | 64 | ||
65 | #ifdef CONFIG_USB_STORAGE_SDDR09 | 65 | #ifdef CONFIG_USB_STORAGE_SDDR09 |
66 | case 1: | 66 | case 1: |
67 | 67 | ||
68 | /* | 68 | /* |
69 | * LUN 1 corresponds to the SmartMedia card reader. | 69 | * LUN 1 corresponds to the SmartMedia card reader. |
70 | */ | 70 | */ |
71 | 71 | ||
72 | /* | 72 | /* |
73 | * Set the LUN to 0 (just in case). | 73 | * Set the LUN to 0 (just in case). |
74 | */ | 74 | */ |
75 | srb->device->lun = 0; us->srb->device->lun = 0; | 75 | srb->device->lun = 0; us->srb->device->lun = 0; |
76 | ret = sddr09_transport(srb, us); | 76 | ret = sddr09_transport(srb, us); |
77 | srb->device->lun = 1; us->srb->device->lun = 1; | 77 | srb->device->lun = 1; us->srb->device->lun = 1; |
78 | break; | 78 | break; |
79 | 79 | ||
80 | #endif | 80 | #endif |
81 | 81 | ||
82 | default: | 82 | default: |
83 | US_DEBUGP("dpcm_transport: Invalid LUN %d\n", srb->device->lun); | 83 | US_DEBUGP("dpcm_transport: Invalid LUN %d\n", srb->device->lun); |
84 | ret = USB_STOR_TRANSPORT_ERROR; | 84 | ret = USB_STOR_TRANSPORT_ERROR; |
85 | break; | 85 | break; |
86 | } | 86 | } |
87 | return ret; | 87 | return ret; |
88 | } | 88 | } |
diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c index d35369392fed..dfd42fe9e5f0 100644 --- a/drivers/usb/storage/onetouch.c +++ b/drivers/usb/storage/onetouch.c | |||
@@ -57,9 +57,10 @@ static void usb_onetouch_irq(struct urb *urb) | |||
57 | struct usb_onetouch *onetouch = urb->context; | 57 | struct usb_onetouch *onetouch = urb->context; |
58 | signed char *data = onetouch->data; | 58 | signed char *data = onetouch->data; |
59 | struct input_dev *dev = onetouch->dev; | 59 | struct input_dev *dev = onetouch->dev; |
60 | int status; | 60 | int status = urb->status; |
61 | int retval; | ||
61 | 62 | ||
62 | switch (urb->status) { | 63 | switch (status) { |
63 | case 0: /* success */ | 64 | case 0: /* success */ |
64 | break; | 65 | break; |
65 | case -ECONNRESET: /* unlink */ | 66 | case -ECONNRESET: /* unlink */ |
@@ -75,11 +76,11 @@ static void usb_onetouch_irq(struct urb *urb) | |||
75 | input_sync(dev); | 76 | input_sync(dev); |
76 | 77 | ||
77 | resubmit: | 78 | resubmit: |
78 | status = usb_submit_urb (urb, GFP_ATOMIC); | 79 | retval = usb_submit_urb (urb, GFP_ATOMIC); |
79 | if (status) | 80 | if (retval) |
80 | err ("can't resubmit intr, %s-%s/input0, status %d", | 81 | err ("can't resubmit intr, %s-%s/input0, retval %d", |
81 | onetouch->udev->bus->bus_name, | 82 | onetouch->udev->bus->bus_name, |
82 | onetouch->udev->devpath, status); | 83 | onetouch->udev->devpath, retval); |
83 | } | 84 | } |
84 | 85 | ||
85 | static int usb_onetouch_open(struct input_dev *dev) | 86 | static int usb_onetouch_open(struct input_dev *dev) |
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h index b6bf31a97b60..a624e72f81dc 100644 --- a/drivers/usb/storage/unusual_devs.h +++ b/drivers/usb/storage/unusual_devs.h | |||
@@ -313,6 +313,13 @@ UNUSUAL_DEV( 0x04b0, 0x0301, 0x0010, 0x0010, | |||
313 | US_SC_DEVICE, US_PR_DEVICE,NULL, | 313 | US_SC_DEVICE, US_PR_DEVICE,NULL, |
314 | US_FL_NOT_LOCKABLE ), | 314 | US_FL_NOT_LOCKABLE ), |
315 | 315 | ||
316 | /* Reported by Stefan de Konink <skinkie@xs4all.nl> */ | ||
317 | UNUSUAL_DEV( 0x04b0, 0x0401, 0x0200, 0x0200, | ||
318 | "NIKON", | ||
319 | "NIKON DSC D100", | ||
320 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
321 | US_FL_FIX_CAPACITY), | ||
322 | |||
316 | /* Reported by Andreas Bockhold <andreas@bockionline.de> */ | 323 | /* Reported by Andreas Bockhold <andreas@bockionline.de> */ |
317 | UNUSUAL_DEV( 0x04b0, 0x0405, 0x0100, 0x0100, | 324 | UNUSUAL_DEV( 0x04b0, 0x0405, 0x0100, 0x0100, |
318 | "NIKON", | 325 | "NIKON", |
@@ -1384,6 +1391,17 @@ UNUSUAL_DEV( 0x1019, 0x0c55, 0x0000, 0x0110, | |||
1384 | US_SC_DEVICE, US_PR_DEVICE, usb_stor_ucr61s2b_init, | 1391 | US_SC_DEVICE, US_PR_DEVICE, usb_stor_ucr61s2b_init, |
1385 | 0 ), | 1392 | 0 ), |
1386 | 1393 | ||
1394 | /* Reported by Kevin Lloyd <linux@sierrawireless.com> | ||
1395 | * Entry is needed for the initializer function override, | ||
1396 | * which instructs the device to load as a modem | ||
1397 | * device. | ||
1398 | */ | ||
1399 | UNUSUAL_DEV( 0x1199, 0x0fff, 0x0000, 0x9999, | ||
1400 | "Sierra Wireless", | ||
1401 | "USB MMC Storage", | ||
1402 | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
1403 | US_FL_IGNORE_DEVICE), | ||
1404 | |||
1387 | /* Reported by Jaco Kroon <jaco@kroon.co.za> | 1405 | /* Reported by Jaco Kroon <jaco@kroon.co.za> |
1388 | * The usb-storage module found on the Digitech GNX4 (and supposedly other | 1406 | * The usb-storage module found on the Digitech GNX4 (and supposedly other |
1389 | * devices) misbehaves and causes a bunch of invalid I/O errors. | 1407 | * devices) misbehaves and causes a bunch of invalid I/O errors. |
diff --git a/drivers/video/backlight/cr_bllcd.c b/drivers/video/backlight/cr_bllcd.c index e9bbc3455c94..1b3f6586bc9f 100644 --- a/drivers/video/backlight/cr_bllcd.c +++ b/drivers/video/backlight/cr_bllcd.c | |||
@@ -174,7 +174,7 @@ static int cr_backlight_probe(struct platform_device *pdev) | |||
174 | struct cr_panel *crp; | 174 | struct cr_panel *crp; |
175 | u8 dev_en; | 175 | u8 dev_en; |
176 | 176 | ||
177 | crp = kzalloc(sizeof(crp), GFP_KERNEL); | 177 | crp = kzalloc(sizeof(*crp), GFP_KERNEL); |
178 | if (crp == NULL) | 178 | if (crp == NULL) |
179 | return -ENOMEM; | 179 | return -ENOMEM; |
180 | 180 | ||
diff --git a/drivers/video/logo/logo.c b/drivers/video/logo/logo.c index 80c03618eb53..2b0f799aa8da 100644 --- a/drivers/video/logo/logo.c +++ b/drivers/video/logo/logo.c | |||
@@ -34,8 +34,11 @@ extern const struct linux_logo logo_superh_vga16; | |||
34 | extern const struct linux_logo logo_superh_clut224; | 34 | extern const struct linux_logo logo_superh_clut224; |
35 | extern const struct linux_logo logo_m32r_clut224; | 35 | extern const struct linux_logo logo_m32r_clut224; |
36 | 36 | ||
37 | 37 | /* logo's are marked __initdata. Use __init_refok to tell | |
38 | const struct linux_logo *fb_find_logo(int depth) | 38 | * modpost that it is intended that this function uses data |
39 | * marked __initdata. | ||
40 | */ | ||
41 | const struct linux_logo * __init_refok fb_find_logo(int depth) | ||
39 | { | 42 | { |
40 | const struct linux_logo *logo = NULL; | 43 | const struct linux_logo *logo = NULL; |
41 | 44 | ||