| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: dbcool.c,v 1.31 2011/07/31 16:05:01 jmcneill Exp $ */ | | 1 | /* $NetBSD: dbcool.c,v 1.32 2011/08/01 22:42:57 macallan Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Paul Goyette | | 8 | * by Paul Goyette |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -40,27 +40,27 @@ | | | @@ -40,27 +40,27 @@ |
40 | * http://www.onsemi.com/pub/Collateral/ADT7466.PDF | | 40 | * http://www.onsemi.com/pub/Collateral/ADT7466.PDF |
41 | * http://www.onsemi.com/pub/Collateral/ADT7467-D.PDF | | 41 | * http://www.onsemi.com/pub/Collateral/ADT7467-D.PDF |
42 | * http://www.onsemi.com/pub/Collateral/ADT7468-D.PDF | | 42 | * http://www.onsemi.com/pub/Collateral/ADT7468-D.PDF |
43 | * http://www.onsemi.com/pub/Collateral/ADT7473-D.PDF | | 43 | * http://www.onsemi.com/pub/Collateral/ADT7473-D.PDF |
44 | * http://www.onsemi.com/pub/Collateral/ADT7475-D.PDF | | 44 | * http://www.onsemi.com/pub/Collateral/ADT7475-D.PDF |
45 | * http://www.onsemi.com/pub/Collateral/ADT7476-D.PDF | | 45 | * http://www.onsemi.com/pub/Collateral/ADT7476-D.PDF |
46 | * http://www.onsemi.com/pub/Collateral/ADT7490-D.PDF | | 46 | * http://www.onsemi.com/pub/Collateral/ADT7490-D.PDF |
47 | * http://www.smsc.com/media/Downloads_Public/Data_Sheets/6d103s.pdf | | 47 | * http://www.smsc.com/media/Downloads_Public/Data_Sheets/6d103s.pdf |
48 | * | | 48 | * |
49 | * (URLs are correct as of October 5, 2008) | | 49 | * (URLs are correct as of October 5, 2008) |
50 | */ | | 50 | */ |
51 | | | 51 | |
52 | #include <sys/cdefs.h> | | 52 | #include <sys/cdefs.h> |
53 | __KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.31 2011/07/31 16:05:01 jmcneill Exp $"); | | 53 | __KERNEL_RCSID(0, "$NetBSD: dbcool.c,v 1.32 2011/08/01 22:42:57 macallan Exp $"); |
54 | | | 54 | |
55 | #include <sys/param.h> | | 55 | #include <sys/param.h> |
56 | #include <sys/systm.h> | | 56 | #include <sys/systm.h> |
57 | #include <sys/kernel.h> | | 57 | #include <sys/kernel.h> |
58 | #include <sys/device.h> | | 58 | #include <sys/device.h> |
59 | #include <sys/malloc.h> | | 59 | #include <sys/malloc.h> |
60 | #include <sys/sysctl.h> | | 60 | #include <sys/sysctl.h> |
61 | #include <sys/module.h> | | 61 | #include <sys/module.h> |
62 | | | 62 | |
63 | #include <dev/i2c/dbcool_var.h> | | 63 | #include <dev/i2c/dbcool_var.h> |
64 | #include <dev/i2c/dbcool_reg.h> | | 64 | #include <dev/i2c/dbcool_reg.h> |
65 | | | 65 | |
66 | /* Config interface */ | | 66 | /* Config interface */ |
| @@ -1677,28 +1677,27 @@ dbcool_attach_sensor(struct dbcool_softc | | | @@ -1677,28 +1677,27 @@ dbcool_attach_sensor(struct dbcool_softc |
1677 | strlcpy(sc->sc_sensor[idx].desc, dbc_sensor_names[name_index], | | 1677 | strlcpy(sc->sc_sensor[idx].desc, dbc_sensor_names[name_index], |
1678 | sizeof(sc->sc_sensor[idx].desc)); | | 1678 | sizeof(sc->sc_sensor[idx].desc)); |
1679 | sc->sc_regs[idx] = &sc->sc_dc.dc_chip->table[idx].reg; | | 1679 | sc->sc_regs[idx] = &sc->sc_dc.dc_chip->table[idx].reg; |
1680 | sc->sc_nom_volt[idx] = sc->sc_dc.dc_chip->table[idx].nom_volt_index; | | 1680 | sc->sc_nom_volt[idx] = sc->sc_dc.dc_chip->table[idx].nom_volt_index; |
1681 | | | 1681 | |
1682 | error = sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensor[idx]); | | 1682 | error = sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensor[idx]); |
1683 | return error; | | 1683 | return error; |
1684 | } | | 1684 | } |
1685 | | | 1685 | |
1686 | static int | | 1686 | static int |
1687 | dbcool_attach_temp_control(struct dbcool_softc *sc, int idx, | | 1687 | dbcool_attach_temp_control(struct dbcool_softc *sc, int idx, |
1688 | struct chip_id *chip) | | 1688 | struct chip_id *chip) |
1689 | { | | 1689 | { |
1690 | const struct sysctlnode *me2 = NULL; | | 1690 | const struct sysctlnode *me2 = NULL, *node; |
1691 | struct sysctlnode *node = NULL; | | | |
1692 | int j, ret, sysctl_index, rw_flag; | | 1691 | int j, ret, sysctl_index, rw_flag; |
1693 | uint8_t sysctl_reg; | | 1692 | uint8_t sysctl_reg; |
1694 | char name[SYSCTL_NAMELEN]; | | 1693 | char name[SYSCTL_NAMELEN]; |
1695 | | | 1694 | |
1696 | /* Search for the corresponding temp sensor */ | | 1695 | /* Search for the corresponding temp sensor */ |
1697 | for (j = 0; j < idx; j++) { | | 1696 | for (j = 0; j < idx; j++) { |
1698 | if (j >= DBCOOL_MAXSENSORS || chip->table[j].type != DBC_TEMP) | | 1697 | if (j >= DBCOOL_MAXSENSORS || chip->table[j].type != DBC_TEMP) |
1699 | continue; | | 1698 | continue; |
1700 | if (chip->table[j].name_index == chip->table[idx].name_index) | | 1699 | if (chip->table[j].name_index == chip->table[idx].name_index) |
1701 | break; | | 1700 | break; |
1702 | } | | 1701 | } |
1703 | if (j >= idx) /* Temp sensor not found */ | | 1702 | if (j >= idx) /* Temp sensor not found */ |
1704 | return ENOENT; | | 1703 | return ENOENT; |
| @@ -1713,85 +1712,82 @@ dbcool_attach_temp_control(struct dbcool | | | @@ -1713,85 +1712,82 @@ dbcool_attach_temp_control(struct dbcool |
1713 | if (me2 != NULL) | | 1712 | if (me2 != NULL) |
1714 | sc->sc_sysctl_num[j] = me2->sysctl_num; | | 1713 | sc->sc_sysctl_num[j] = me2->sysctl_num; |
1715 | else | | 1714 | else |
1716 | return ret; | | 1715 | return ret; |
1717 | } | | 1716 | } |
1718 | /* add sysctl leaf node for this control variable */ | | 1717 | /* add sysctl leaf node for this control variable */ |
1719 | sysctl_index = chip->table[idx].sysctl_index; | | 1718 | sysctl_index = chip->table[idx].sysctl_index; |
1720 | sysctl_reg = chip->table[idx].reg.val_reg; | | 1719 | sysctl_reg = chip->table[idx].reg.val_reg; |
1721 | strlcpy(name, dbc_sysctl_table[sysctl_index].name, sizeof(name)); | | 1720 | strlcpy(name, dbc_sysctl_table[sysctl_index].name, sizeof(name)); |
1722 | if (dbc_sysctl_table[sysctl_index].lockable && dbcool_islocked(sc)) | | 1721 | if (dbc_sysctl_table[sysctl_index].lockable && dbcool_islocked(sc)) |
1723 | rw_flag = CTLFLAG_READONLY | CTLFLAG_OWNDESC; | | 1722 | rw_flag = CTLFLAG_READONLY | CTLFLAG_OWNDESC; |
1724 | else | | 1723 | else |
1725 | rw_flag = CTLFLAG_READWRITE | CTLFLAG_OWNDESC; | | 1724 | rw_flag = CTLFLAG_READWRITE | CTLFLAG_OWNDESC; |
| | | 1725 | |
1726 | ret = sysctl_createv(NULL, 0, NULL, | | 1726 | ret = sysctl_createv(NULL, 0, NULL, |
1727 | (const struct sysctlnode **)&node, rw_flag, | | 1727 | &node, rw_flag, |
1728 | CTLTYPE_INT, name, | | 1728 | CTLTYPE_INT, name, |
1729 | SYSCTL_DESCR(dbc_sysctl_table[sysctl_index].desc), | | 1729 | SYSCTL_DESCR(dbc_sysctl_table[sysctl_index].desc), |
1730 | dbc_sysctl_table[sysctl_index].helper, | | 1730 | dbc_sysctl_table[sysctl_index].helper, |
1731 | 0, sc, sizeof(int), | | 1731 | 0, sc, sizeof(int), |
1732 | CTL_HW, sc->sc_root_sysctl_num, | | 1732 | CTL_HW, sc->sc_root_sysctl_num, |
1733 | sc->sc_sysctl_num[j], | | 1733 | sc->sc_sysctl_num[j], |
1734 | DBC_PWM_SYSCTL(idx, sysctl_reg), CTL_EOL); | | 1734 | DBC_PWM_SYSCTL(idx, sysctl_reg), CTL_EOL); |
1735 | if (node != NULL) | | | |
1736 | node->sysctl_data = sc; | | | |
1737 | | | 1735 | |
1738 | return ret; | | 1736 | return ret; |
1739 | } | | 1737 | } |
1740 | | | 1738 | |
1741 | static void | | 1739 | static void |
1742 | dbcool_setup_controllers(struct dbcool_softc *sc) | | 1740 | dbcool_setup_controllers(struct dbcool_softc *sc) |
1743 | { | | 1741 | { |
1744 | int i, j, ret, rw_flag; | | 1742 | int i, j, ret, rw_flag; |
1745 | uint8_t sysctl_reg; | | 1743 | uint8_t sysctl_reg; |
1746 | struct chip_id *chip = sc->sc_dc.dc_chip; | | 1744 | struct chip_id *chip = sc->sc_dc.dc_chip; |
1747 | const struct sysctlnode *me2 = NULL; | | 1745 | const struct sysctlnode *me2 = NULL; |
1748 | struct sysctlnode *node = NULL; | | 1746 | const struct sysctlnode *node = NULL; |
1749 | char name[SYSCTL_NAMELEN]; | | 1747 | char name[SYSCTL_NAMELEN]; |
1750 | | | 1748 | |
1751 | for (i = 0; chip->power[i].desc != NULL; i++) { | | 1749 | for (i = 0; chip->power[i].desc != NULL; i++) { |
1752 | snprintf(name, sizeof(name), "fan_ctl_%d", i); | | 1750 | snprintf(name, sizeof(name), "fan_ctl_%d", i); |
1753 | ret = sysctl_createv(NULL, 0, NULL, &me2, | | 1751 | ret = sysctl_createv(NULL, 0, NULL, &me2, |
1754 | CTLFLAG_READWRITE | CTLFLAG_OWNDESC, | | 1752 | CTLFLAG_READWRITE | CTLFLAG_OWNDESC, |
1755 | CTLTYPE_NODE, name, NULL, | | 1753 | CTLTYPE_NODE, name, NULL, |
1756 | NULL, 0, NULL, 0, | | 1754 | NULL, 0, NULL, 0, |
1757 | CTL_HW, sc->sc_root_sysctl_num, CTL_CREATE, CTL_EOL); | | 1755 | CTL_HW, sc->sc_root_sysctl_num, CTL_CREATE, CTL_EOL); |
1758 | | | 1756 | |
1759 | for (j = DBC_PWM_BEHAVIOR; j < DBC_PWM_LAST_PARAM; j++) { | | 1757 | for (j = DBC_PWM_BEHAVIOR; j < DBC_PWM_LAST_PARAM; j++) { |
1760 | if (j == DBC_PWM_MAX_DUTY && | | 1758 | if (j == DBC_PWM_MAX_DUTY && |
1761 | (chip->flags & DBCFLAG_HAS_MAXDUTY) == 0) | | 1759 | (chip->flags & DBCFLAG_HAS_MAXDUTY) == 0) |
1762 | continue; | | 1760 | continue; |
1763 | sysctl_reg = chip->power[i].power_regs[j]; | | 1761 | sysctl_reg = chip->power[i].power_regs[j]; |
1764 | if (sysctl_reg == DBCOOL_NO_REG) | | 1762 | if (sysctl_reg == DBCOOL_NO_REG) |
1765 | continue; | | 1763 | continue; |
1766 | strlcpy(name, dbc_sysctl_table[j].name, sizeof(name)); | | 1764 | strlcpy(name, dbc_sysctl_table[j].name, sizeof(name)); |
1767 | if (dbc_sysctl_table[j].lockable && dbcool_islocked(sc)) | | 1765 | if (dbc_sysctl_table[j].lockable && dbcool_islocked(sc)) |
1768 | rw_flag = CTLFLAG_READONLY | CTLFLAG_OWNDESC; | | 1766 | rw_flag = CTLFLAG_READONLY | CTLFLAG_OWNDESC; |
1769 | else | | 1767 | else |
1770 | rw_flag = CTLFLAG_READWRITE | CTLFLAG_OWNDESC; | | 1768 | rw_flag = CTLFLAG_READWRITE | CTLFLAG_OWNDESC; |
1771 | ret = sysctl_createv(NULL, 0, NULL, | | 1769 | ret = sysctl_createv(NULL, 0, NULL, |
1772 | (const struct sysctlnode **)&node, rw_flag, | | 1770 | &node, rw_flag, |
1773 | (j == DBC_PWM_BEHAVIOR)? | | 1771 | (j == DBC_PWM_BEHAVIOR)? |
1774 | CTLTYPE_STRING:CTLTYPE_INT, | | 1772 | CTLTYPE_STRING:CTLTYPE_INT, |
1775 | name, | | 1773 | name, |
1776 | SYSCTL_DESCR(dbc_sysctl_table[j].desc), | | 1774 | SYSCTL_DESCR(dbc_sysctl_table[j].desc), |
1777 | dbc_sysctl_table[j].helper, | | 1775 | dbc_sysctl_table[j].helper, |
1778 | 0, sc, | | 1776 | 0, sc, |
1779 | ( j == DBC_PWM_BEHAVIOR)? | | 1777 | ( j == DBC_PWM_BEHAVIOR)? |
1780 | sizeof(dbcool_cur_behav): sizeof(int), | | 1778 | sizeof(dbcool_cur_behav): sizeof(int), |
1781 | CTL_HW, sc->sc_root_sysctl_num, me2->sysctl_num, | | 1779 | CTL_HW, sc->sc_root_sysctl_num, me2->sysctl_num, |
1782 | DBC_PWM_SYSCTL(j, sysctl_reg), CTL_EOL); | | 1780 | DBC_PWM_SYSCTL(j, sysctl_reg), CTL_EOL); |
1783 | if (node != NULL) | | | |
1784 | node->sysctl_data = sc; | | | |
1785 | } | | 1781 | } |
1786 | } | | 1782 | } |
1787 | } | | 1783 | } |
1788 | | | 1784 | |
1789 | static void | | 1785 | static void |
1790 | dbcool_refresh(struct sysmon_envsys *sme, envsys_data_t *edata) | | 1786 | dbcool_refresh(struct sysmon_envsys *sme, envsys_data_t *edata) |
1791 | { | | 1787 | { |
1792 | struct dbcool_softc *sc=sme->sme_cookie; | | 1788 | struct dbcool_softc *sc=sme->sme_cookie; |
1793 | int i, nom_volt_idx, cur; | | 1789 | int i, nom_volt_idx, cur; |
1794 | struct reg_list *reg; | | 1790 | struct reg_list *reg; |
1795 | | | 1791 | |
1796 | i = edata->sensor; | | 1792 | i = edata->sensor; |
1797 | reg = sc->sc_regs[i]; | | 1793 | reg = sc->sc_regs[i]; |