aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/w83795.c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2010-10-28 14:31:46 -0400
committerJean Delvare <khali@endymion.delvare>2010-10-28 14:31:46 -0400
commit71caf46fbf39207a324a16ddb6d8ef37c05777b9 (patch)
tree9df260f10ffc8a644c47cec4952bea5df85d34c4 /drivers/hwmon/w83795.c
parent6f9dfd85f7b14dd3ea87106909dc54def08947b1 (diff)
hwmon: (w83795) Clean up probe function
* The data structure is zalloc'd, so no need to set individual fields to 0 explicitly. * Refactor the handling of pins that can be used for either temperature or voltage monitoring. * Misc other clean-ups. Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon/w83795.c')
-rw-r--r--drivers/hwmon/w83795.c91
1 files changed, 34 insertions, 57 deletions
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c
index 77b4f7859df9..b797b9ce2907 100644
--- a/drivers/hwmon/w83795.c
+++ b/drivers/hwmon/w83795.c
@@ -1844,6 +1844,26 @@ static int device_remove_file_wrapper(struct device *dev,
1844 return 0; 1844 return 0;
1845} 1845}
1846 1846
1847/* Check pins that can be used for either temperature or voltage monitoring */
1848static void w83795_apply_temp_config(struct w83795_data *data, u8 config,
1849 int temp_chan, int in_chan)
1850{
1851 /* config is a 2-bit value */
1852 switch (config) {
1853 case 0x2: /* Voltage monitoring */
1854 data->has_in |= 1 << in_chan;
1855 break;
1856 case 0x1: /* Thermal diode */
1857 if (temp_chan >= 4)
1858 break;
1859 data->temp_mode |= 1 << temp_chan;
1860 /* fall through */
1861 case 0x3: /* Thermistor */
1862 data->has_temp |= 1 << temp_chan;
1863 break;
1864 }
1865}
1866
1847static int w83795_probe(struct i2c_client *client, 1867static int w83795_probe(struct i2c_client *client,
1848 const struct i2c_device_id *id) 1868 const struct i2c_device_id *id)
1849{ 1869{
@@ -1851,7 +1871,7 @@ static int w83795_probe(struct i2c_client *client,
1851 u8 tmp; 1871 u8 tmp;
1852 struct device *dev = &client->dev; 1872 struct device *dev = &client->dev;
1853 struct w83795_data *data; 1873 struct w83795_data *data;
1854 int err = 0; 1874 int err;
1855 1875
1856 data = kzalloc(sizeof(struct w83795_data), GFP_KERNEL); 1876 data = kzalloc(sizeof(struct w83795_data), GFP_KERNEL);
1857 if (!data) { 1877 if (!data) {
@@ -1867,68 +1887,26 @@ static int w83795_probe(struct i2c_client *client,
1867 /* Initialize the chip */ 1887 /* Initialize the chip */
1868 w83795_init_client(client); 1888 w83795_init_client(client);
1869 1889
1870 data->has_in = w83795_read(client, W83795_REG_VOLT_CTRL1); 1890 /* Check which voltages and fans are present */
1871 data->has_in |= w83795_read(client, W83795_REG_VOLT_CTRL2) << 8; 1891 data->has_in = w83795_read(client, W83795_REG_VOLT_CTRL1)
1872 /* VSEN11-9 not for 795adg */ 1892 | (w83795_read(client, W83795_REG_VOLT_CTRL2) << 8);
1873 if (data->chip_type == w83795adg) 1893 data->has_fan = w83795_read(client, W83795_REG_FANIN_CTRL1)
1874 data->has_in &= 0xf8ff; 1894 | (w83795_read(client, W83795_REG_FANIN_CTRL2) << 8);
1875 data->has_fan = w83795_read(client, W83795_REG_FANIN_CTRL1);
1876 data->has_fan |= w83795_read(client, W83795_REG_FANIN_CTRL2) << 8;
1877 1895
1878 /* VDSEN12-17 and TR1-6, TD1-4 use same register */ 1896 /* Check which analog temperatures and extra voltages are present */
1879 tmp = w83795_read(client, W83795_REG_TEMP_CTRL1); 1897 tmp = w83795_read(client, W83795_REG_TEMP_CTRL1);
1880 if (tmp & 0x20) 1898 if (tmp & 0x20)
1881 data->enable_dts = 1; 1899 data->enable_dts = 1;
1882 else 1900 w83795_apply_temp_config(data, (tmp >> 2) & 0x3, 5, 16);
1883 data->enable_dts = 0; 1901 w83795_apply_temp_config(data, tmp & 0x3, 4, 15);
1884 data->has_temp = 0;
1885 data->temp_mode = 0;
1886 if (tmp & 0x08) {
1887 if (tmp & 0x04)
1888 data->has_temp |= 0x20;
1889 else
1890 data->has_in |= 0x10000;
1891 }
1892 if (tmp & 0x02) {
1893 if (tmp & 0x01)
1894 data->has_temp |= 0x10;
1895 else
1896 data->has_in |= 0x8000;
1897 }
1898 tmp = w83795_read(client, W83795_REG_TEMP_CTRL2); 1902 tmp = w83795_read(client, W83795_REG_TEMP_CTRL2);
1899 if (tmp & 0x40) { 1903 w83795_apply_temp_config(data, tmp >> 6, 3, 20);
1900 data->has_temp |= 0x08; 1904 w83795_apply_temp_config(data, (tmp >> 4) & 0x3, 2, 19);
1901 if (!(tmp & 0x80)) 1905 w83795_apply_temp_config(data, (tmp >> 2) & 0x3, 1, 18);
1902 data->temp_mode |= 0x08; 1906 w83795_apply_temp_config(data, tmp & 0x3, 0, 17);
1903 } else if (tmp & 0x80) {
1904 data->has_in |= 0x100000;
1905 }
1906 if (tmp & 0x10) {
1907 data->has_temp |= 0x04;
1908 if (!(tmp & 0x20))
1909 data->temp_mode |= 0x04;
1910 } else if (tmp & 0x20) {
1911 data->has_in |= 0x80000;
1912 }
1913 if (tmp & 0x04) {
1914 data->has_temp |= 0x02;
1915 if (!(tmp & 0x08))
1916 data->temp_mode |= 0x02;
1917 } else if (tmp & 0x08) {
1918 data->has_in |= 0x40000;
1919 }
1920 if (tmp & 0x01) {
1921 data->has_temp |= 0x01;
1922 if (!(tmp & 0x02))
1923 data->temp_mode |= 0x01;
1924 } else if (tmp & 0x02) {
1925 data->has_in |= 0x20000;
1926 }
1927 1907
1928 /* Check DTS enable status */ 1908 /* Check DTS enable status */
1929 if (data->enable_dts == 0) { 1909 if (data->enable_dts) {
1930 data->has_dts = 0;
1931 } else {
1932 if (1 & w83795_read(client, W83795_REG_DTSC)) 1910 if (1 & w83795_read(client, W83795_REG_DTSC))
1933 data->enable_dts |= 2; 1911 data->enable_dts |= 2;
1934 data->has_dts = w83795_read(client, W83795_REG_DTSE); 1912 data->has_dts = w83795_read(client, W83795_REG_DTSE);
@@ -2017,7 +1995,6 @@ static int w83795_probe(struct i2c_client *client,
2017 data->has_pwm = 2; 1995 data->has_pwm = 2;
2018 data->pwm_fcms[0] = w83795_read(client, W83795_REG_FCMS1); 1996 data->pwm_fcms[0] = w83795_read(client, W83795_REG_FCMS1);
2019 data->pwm_fcms[1] = w83795_read(client, W83795_REG_FCMS2); 1997 data->pwm_fcms[1] = w83795_read(client, W83795_REG_FCMS2);
2020 /* w83795adg only support pwm2-0 */
2021 for (i = 0; i < W83795_REG_TEMP_NUM; i++) 1998 for (i = 0; i < W83795_REG_TEMP_NUM; i++)
2022 data->pwm_tfmr[i] = w83795_read(client, W83795_REG_TFMR(i)); 1999 data->pwm_tfmr[i] = w83795_read(client, W83795_REG_TFMR(i));
2023 data->pwm_fomc = w83795_read(client, W83795_REG_FOMC); 2000 data->pwm_fomc = w83795_read(client, W83795_REG_FOMC);