diff options
author | Henrique de Moraes Holschuh <hmh@hmh.eng.br> | 2006-11-24 08:47:10 -0500 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2006-12-07 01:38:39 -0500 |
commit | c52f0aa574246f133a0bc2041e9468a06d34da7b (patch) | |
tree | 751cd39312a9cc2645735f736e1dea771d1d8d32 /drivers/acpi | |
parent | 3ef8a6096ca98d45a54999a97c7c8e14977d2e3e (diff) |
ACPI: ibm-acpi: break fan_read into separate functions
This patch breaks fan_read mechanics into a generic function to get fan
status and speed, and leaves only the procfs interface code in fan_read.
Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
Diffstat (limited to 'drivers/acpi')
-rw-r--r-- | drivers/acpi/ibm_acpi.c | 78 |
1 files changed, 66 insertions, 12 deletions
diff --git a/drivers/acpi/ibm_acpi.c b/drivers/acpi/ibm_acpi.c index e8de5e349d21..9275dfc130f2 100644 --- a/drivers/acpi/ibm_acpi.c +++ b/drivers/acpi/ibm_acpi.c | |||
@@ -1738,36 +1738,90 @@ static int fan_init(void) | |||
1738 | return 0; | 1738 | return 0; |
1739 | } | 1739 | } |
1740 | 1740 | ||
1741 | static int fan_read(char *p) | 1741 | static int fan_get_status(u8 *status) |
1742 | { | 1742 | { |
1743 | int len = 0; | 1743 | u8 s; |
1744 | u8 lo, hi, status; | ||
1745 | 1744 | ||
1746 | switch (fan_status_access_mode) { | 1745 | switch (fan_status_access_mode) { |
1747 | case IBMACPI_FAN_RD_ACPI_GFAN: | 1746 | case IBMACPI_FAN_RD_ACPI_GFAN: |
1748 | /* 570, 600e/x, 770e, 770x */ | 1747 | /* 570, 600e/x, 770e, 770x */ |
1749 | if (unlikely(!acpi_evalf(gfan_handle, &status, NULL, "d"))) | 1748 | |
1749 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) | ||
1750 | return -EIO; | 1750 | return -EIO; |
1751 | 1751 | ||
1752 | len += sprintf(p + len, "level:\t\t%d\n", status); | 1752 | if (likely(status)) |
1753 | *status = s & 0x07; | ||
1753 | 1754 | ||
1754 | break; | 1755 | break; |
1755 | 1756 | ||
1756 | case IBMACPI_FAN_RD_TPEC: | 1757 | case IBMACPI_FAN_RD_TPEC: |
1757 | /* all except 570, 600e/x, 770e, 770x */ | 1758 | /* all except 570, 600e/x, 770e, 770x */ |
1758 | if (unlikely(!acpi_ec_read(fan_status_offset, &status))) | 1759 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) |
1759 | return -EIO; | 1760 | return -EIO; |
1760 | else | ||
1761 | len += sprintf(p + len, "status:\t\t%s\n", | ||
1762 | enabled(status, 7)); | ||
1763 | 1761 | ||
1762 | if (likely(status)) | ||
1763 | *status = s; | ||
1764 | |||
1765 | break; | ||
1766 | |||
1767 | default: | ||
1768 | return -ENXIO; | ||
1769 | } | ||
1770 | |||
1771 | return 0; | ||
1772 | } | ||
1773 | |||
1774 | static int fan_get_speed(unsigned int *speed) | ||
1775 | { | ||
1776 | u8 hi, lo; | ||
1777 | |||
1778 | switch (fan_status_access_mode) { | ||
1779 | case IBMACPI_FAN_RD_TPEC: | ||
1780 | /* all except 570, 600e/x, 770e, 770x */ | ||
1764 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || | 1781 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
1765 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) | 1782 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) |
1766 | return -EIO; | 1783 | return -EIO; |
1767 | else | ||
1768 | len += sprintf(p + len, "speed:\t\t%d\n", | ||
1769 | (hi << 8) + lo); | ||
1770 | 1784 | ||
1785 | if (likely(speed)) | ||
1786 | *speed = (hi << 8) | lo; | ||
1787 | |||
1788 | break; | ||
1789 | |||
1790 | default: | ||
1791 | return -ENXIO; | ||
1792 | } | ||
1793 | |||
1794 | return 0; | ||
1795 | } | ||
1796 | |||
1797 | static int fan_read(char *p) | ||
1798 | { | ||
1799 | int len = 0; | ||
1800 | int rc; | ||
1801 | u8 status; | ||
1802 | unsigned int speed = 0; | ||
1803 | |||
1804 | switch (fan_status_access_mode) { | ||
1805 | case IBMACPI_FAN_RD_ACPI_GFAN: | ||
1806 | /* 570, 600e/x, 770e, 770x */ | ||
1807 | if ((rc = fan_get_status(&status)) < 0) | ||
1808 | return rc; | ||
1809 | |||
1810 | len += sprintf(p + len, "level:\t\t%d\n", status); | ||
1811 | |||
1812 | break; | ||
1813 | |||
1814 | case IBMACPI_FAN_RD_TPEC: | ||
1815 | /* all except 570, 600e/x, 770e, 770x */ | ||
1816 | if ((rc = fan_get_status(&status)) < 0) | ||
1817 | return rc; | ||
1818 | |||
1819 | len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 7)); | ||
1820 | |||
1821 | if ((rc = fan_get_speed(&speed)) < 0) | ||
1822 | return rc; | ||
1823 | |||
1824 | len += sprintf(p + len, "speed:\t\t%d\n", speed); | ||
1771 | break; | 1825 | break; |
1772 | 1826 | ||
1773 | case IBMACPI_FAN_NONE: | 1827 | case IBMACPI_FAN_NONE: |