aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2014-07-03 09:51:43 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-08-04 10:01:37 -0400
commit97df55661a2d60e6554ce9a9ee6fb47606ddc772 (patch)
tree999393e9e8c069352d1a7f28f2ce9245e845fb91 /drivers/hwmon
parentaab3f57a11723c75477f43d7a510c148f2269d16 (diff)
hwmon: (adm1026) Avoid forward declaration
Reorder functions to avoid forward declaration. Signed-off-by: Axel Lin <axel.lin@ingics.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/adm1026.c452
1 files changed, 219 insertions, 233 deletions
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c
index b3498acb9ab4..cf3ed29943f3 100644
--- a/drivers/hwmon/adm1026.c
+++ b/drivers/hwmon/adm1026.c
@@ -298,37 +298,6 @@ struct adm1026_data {
298 u8 config3; /* Register value */ 298 u8 config3; /* Register value */
299}; 299};
300 300
301static int adm1026_probe(struct i2c_client *client,
302 const struct i2c_device_id *id);
303static int adm1026_detect(struct i2c_client *client,
304 struct i2c_board_info *info);
305static int adm1026_remove(struct i2c_client *client);
306static int adm1026_read_value(struct i2c_client *client, u8 reg);
307static int adm1026_write_value(struct i2c_client *client, u8 reg, int value);
308static void adm1026_print_gpio(struct i2c_client *client);
309static void adm1026_fixup_gpio(struct i2c_client *client);
310static struct adm1026_data *adm1026_update_device(struct device *dev);
311static void adm1026_init_client(struct i2c_client *client);
312
313
314static const struct i2c_device_id adm1026_id[] = {
315 { "adm1026", 0 },
316 { }
317};
318MODULE_DEVICE_TABLE(i2c, adm1026_id);
319
320static struct i2c_driver adm1026_driver = {
321 .class = I2C_CLASS_HWMON,
322 .driver = {
323 .name = "adm1026",
324 },
325 .probe = adm1026_probe,
326 .remove = adm1026_remove,
327 .id_table = adm1026_id,
328 .detect = adm1026_detect,
329 .address_list = normal_i2c,
330};
331
332static int adm1026_read_value(struct i2c_client *client, u8 reg) 301static int adm1026_read_value(struct i2c_client *client, u8 reg)
333{ 302{
334 int res; 303 int res;
@@ -357,208 +326,6 @@ static int adm1026_write_value(struct i2c_client *client, u8 reg, int value)
357 return res; 326 return res;
358} 327}
359 328
360static void adm1026_init_client(struct i2c_client *client)
361{
362 int value, i;
363 struct adm1026_data *data = i2c_get_clientdata(client);
364
365 dev_dbg(&client->dev, "Initializing device\n");
366 /* Read chip config */
367 data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
368 data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
369 data->config3 = adm1026_read_value(client, ADM1026_REG_CONFIG3);
370
371 /* Inform user of chip config */
372 dev_dbg(&client->dev, "ADM1026_REG_CONFIG1 is: 0x%02x\n",
373 data->config1);
374 if ((data->config1 & CFG1_MONITOR) == 0) {
375 dev_dbg(&client->dev,
376 "Monitoring not currently enabled.\n");
377 }
378 if (data->config1 & CFG1_INT_ENABLE) {
379 dev_dbg(&client->dev,
380 "SMBALERT interrupts are enabled.\n");
381 }
382 if (data->config1 & CFG1_AIN8_9) {
383 dev_dbg(&client->dev,
384 "in8 and in9 enabled. temp3 disabled.\n");
385 } else {
386 dev_dbg(&client->dev,
387 "temp3 enabled. in8 and in9 disabled.\n");
388 }
389 if (data->config1 & CFG1_THERM_HOT) {
390 dev_dbg(&client->dev,
391 "Automatic THERM, PWM, and temp limits enabled.\n");
392 }
393
394 if (data->config3 & CFG3_GPIO16_ENABLE) {
395 dev_dbg(&client->dev,
396 "GPIO16 enabled. THERM pin disabled.\n");
397 } else {
398 dev_dbg(&client->dev,
399 "THERM pin enabled. GPIO16 disabled.\n");
400 }
401 if (data->config3 & CFG3_VREF_250)
402 dev_dbg(&client->dev, "Vref is 2.50 Volts.\n");
403 else
404 dev_dbg(&client->dev, "Vref is 1.82 Volts.\n");
405 /* Read and pick apart the existing GPIO configuration */
406 value = 0;
407 for (i = 0; i <= 15; ++i) {
408 if ((i & 0x03) == 0) {
409 value = adm1026_read_value(client,
410 ADM1026_REG_GPIO_CFG_0_3 + i / 4);
411 }
412 data->gpio_config[i] = value & 0x03;
413 value >>= 2;
414 }
415 data->gpio_config[16] = (data->config3 >> 6) & 0x03;
416
417 /* ... and then print it */
418 adm1026_print_gpio(client);
419
420 /*
421 * If the user asks us to reprogram the GPIO config, then
422 * do it now.
423 */
424 if (gpio_input[0] != -1 || gpio_output[0] != -1
425 || gpio_inverted[0] != -1 || gpio_normal[0] != -1
426 || gpio_fan[0] != -1) {
427 adm1026_fixup_gpio(client);
428 }
429
430 /*
431 * WE INTENTIONALLY make no changes to the limits,
432 * offsets, pwms, fans and zones. If they were
433 * configured, we don't want to mess with them.
434 * If they weren't, the default is 100% PWM, no
435 * control and will suffice until 'sensors -s'
436 * can be run by the user. We DO set the default
437 * value for pwm1.auto_pwm_min to its maximum
438 * so that enabling automatic pwm fan control
439 * without first setting a value for pwm1.auto_pwm_min
440 * will not result in potentially dangerous fan speed decrease.
441 */
442 data->pwm1.auto_pwm_min = 255;
443 /* Start monitoring */
444 value = adm1026_read_value(client, ADM1026_REG_CONFIG1);
445 /* Set MONITOR, clear interrupt acknowledge and s/w reset */
446 value = (value | CFG1_MONITOR) & (~CFG1_INT_CLEAR & ~CFG1_RESET);
447 dev_dbg(&client->dev, "Setting CONFIG to: 0x%02x\n", value);
448 data->config1 = value;
449 adm1026_write_value(client, ADM1026_REG_CONFIG1, value);
450
451 /* initialize fan_div[] to hardware defaults */
452 value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3) |
453 (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7) << 8);
454 for (i = 0; i <= 7; ++i) {
455 data->fan_div[i] = DIV_FROM_REG(value & 0x03);
456 value >>= 2;
457 }
458}
459
460static void adm1026_print_gpio(struct i2c_client *client)
461{
462 struct adm1026_data *data = i2c_get_clientdata(client);
463 int i;
464
465 dev_dbg(&client->dev, "GPIO config is:\n");
466 for (i = 0; i <= 7; ++i) {
467 if (data->config2 & (1 << i)) {
468 dev_dbg(&client->dev, "\t%sGP%s%d\n",
469 data->gpio_config[i] & 0x02 ? "" : "!",
470 data->gpio_config[i] & 0x01 ? "OUT" : "IN",
471 i);
472 } else {
473 dev_dbg(&client->dev, "\tFAN%d\n", i);
474 }
475 }
476 for (i = 8; i <= 15; ++i) {
477 dev_dbg(&client->dev, "\t%sGP%s%d\n",
478 data->gpio_config[i] & 0x02 ? "" : "!",
479 data->gpio_config[i] & 0x01 ? "OUT" : "IN",
480 i);
481 }
482 if (data->config3 & CFG3_GPIO16_ENABLE) {
483 dev_dbg(&client->dev, "\t%sGP%s16\n",
484 data->gpio_config[16] & 0x02 ? "" : "!",
485 data->gpio_config[16] & 0x01 ? "OUT" : "IN");
486 } else {
487 /* GPIO16 is THERM */
488 dev_dbg(&client->dev, "\tTHERM\n");
489 }
490}
491
492static void adm1026_fixup_gpio(struct i2c_client *client)
493{
494 struct adm1026_data *data = i2c_get_clientdata(client);
495 int i;
496 int value;
497
498 /* Make the changes requested. */
499 /*
500 * We may need to unlock/stop monitoring or soft-reset the
501 * chip before we can make changes. This hasn't been
502 * tested much. FIXME
503 */
504
505 /* Make outputs */
506 for (i = 0; i <= 16; ++i) {
507 if (gpio_output[i] >= 0 && gpio_output[i] <= 16)
508 data->gpio_config[gpio_output[i]] |= 0x01;
509 /* if GPIO0-7 is output, it isn't a FAN tach */
510 if (gpio_output[i] >= 0 && gpio_output[i] <= 7)
511 data->config2 |= 1 << gpio_output[i];
512 }
513
514 /* Input overrides output */
515 for (i = 0; i <= 16; ++i) {
516 if (gpio_input[i] >= 0 && gpio_input[i] <= 16)
517 data->gpio_config[gpio_input[i]] &= ~0x01;
518 /* if GPIO0-7 is input, it isn't a FAN tach */
519 if (gpio_input[i] >= 0 && gpio_input[i] <= 7)
520 data->config2 |= 1 << gpio_input[i];
521 }
522
523 /* Inverted */
524 for (i = 0; i <= 16; ++i) {
525 if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16)
526 data->gpio_config[gpio_inverted[i]] &= ~0x02;
527 }
528
529 /* Normal overrides inverted */
530 for (i = 0; i <= 16; ++i) {
531 if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16)
532 data->gpio_config[gpio_normal[i]] |= 0x02;
533 }
534
535 /* Fan overrides input and output */
536 for (i = 0; i <= 7; ++i) {
537 if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7)
538 data->config2 &= ~(1 << gpio_fan[i]);
539 }
540
541 /* Write new configs to registers */
542 adm1026_write_value(client, ADM1026_REG_CONFIG2, data->config2);
543 data->config3 = (data->config3 & 0x3f)
544 | ((data->gpio_config[16] & 0x03) << 6);
545 adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3);
546 for (i = 15, value = 0; i >= 0; --i) {
547 value <<= 2;
548 value |= data->gpio_config[i] & 0x03;
549 if ((i & 0x03) == 0) {
550 adm1026_write_value(client,
551 ADM1026_REG_GPIO_CFG_0_3 + i/4,
552 value);
553 value = 0;
554 }
555 }
556
557 /* Print the new config */
558 adm1026_print_gpio(client);
559}
560
561
562static struct adm1026_data *adm1026_update_device(struct device *dev) 329static struct adm1026_data *adm1026_update_device(struct device *dev)
563{ 330{
564 struct i2c_client *client = to_i2c_client(dev); 331 struct i2c_client *client = to_i2c_client(dev);
@@ -1829,6 +1596,207 @@ static int adm1026_detect(struct i2c_client *client,
1829 return 0; 1596 return 0;
1830} 1597}
1831 1598
1599static void adm1026_print_gpio(struct i2c_client *client)
1600{
1601 struct adm1026_data *data = i2c_get_clientdata(client);
1602 int i;
1603
1604 dev_dbg(&client->dev, "GPIO config is:\n");
1605 for (i = 0; i <= 7; ++i) {
1606 if (data->config2 & (1 << i)) {
1607 dev_dbg(&client->dev, "\t%sGP%s%d\n",
1608 data->gpio_config[i] & 0x02 ? "" : "!",
1609 data->gpio_config[i] & 0x01 ? "OUT" : "IN",
1610 i);
1611 } else {
1612 dev_dbg(&client->dev, "\tFAN%d\n", i);
1613 }
1614 }
1615 for (i = 8; i <= 15; ++i) {
1616 dev_dbg(&client->dev, "\t%sGP%s%d\n",
1617 data->gpio_config[i] & 0x02 ? "" : "!",
1618 data->gpio_config[i] & 0x01 ? "OUT" : "IN",
1619 i);
1620 }
1621 if (data->config3 & CFG3_GPIO16_ENABLE) {
1622 dev_dbg(&client->dev, "\t%sGP%s16\n",
1623 data->gpio_config[16] & 0x02 ? "" : "!",
1624 data->gpio_config[16] & 0x01 ? "OUT" : "IN");
1625 } else {
1626 /* GPIO16 is THERM */
1627 dev_dbg(&client->dev, "\tTHERM\n");
1628 }
1629}
1630
1631static void adm1026_fixup_gpio(struct i2c_client *client)
1632{
1633 struct adm1026_data *data = i2c_get_clientdata(client);
1634 int i;
1635 int value;
1636
1637 /* Make the changes requested. */
1638 /*
1639 * We may need to unlock/stop monitoring or soft-reset the
1640 * chip before we can make changes. This hasn't been
1641 * tested much. FIXME
1642 */
1643
1644 /* Make outputs */
1645 for (i = 0; i <= 16; ++i) {
1646 if (gpio_output[i] >= 0 && gpio_output[i] <= 16)
1647 data->gpio_config[gpio_output[i]] |= 0x01;
1648 /* if GPIO0-7 is output, it isn't a FAN tach */
1649 if (gpio_output[i] >= 0 && gpio_output[i] <= 7)
1650 data->config2 |= 1 << gpio_output[i];
1651 }
1652
1653 /* Input overrides output */
1654 for (i = 0; i <= 16; ++i) {
1655 if (gpio_input[i] >= 0 && gpio_input[i] <= 16)
1656 data->gpio_config[gpio_input[i]] &= ~0x01;
1657 /* if GPIO0-7 is input, it isn't a FAN tach */
1658 if (gpio_input[i] >= 0 && gpio_input[i] <= 7)
1659 data->config2 |= 1 << gpio_input[i];
1660 }
1661
1662 /* Inverted */
1663 for (i = 0; i <= 16; ++i) {
1664 if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16)
1665 data->gpio_config[gpio_inverted[i]] &= ~0x02;
1666 }
1667
1668 /* Normal overrides inverted */
1669 for (i = 0; i <= 16; ++i) {
1670 if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16)
1671 data->gpio_config[gpio_normal[i]] |= 0x02;
1672 }
1673
1674 /* Fan overrides input and output */
1675 for (i = 0; i <= 7; ++i) {
1676 if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7)
1677 data->config2 &= ~(1 << gpio_fan[i]);
1678 }
1679
1680 /* Write new configs to registers */
1681 adm1026_write_value(client, ADM1026_REG_CONFIG2, data->config2);
1682 data->config3 = (data->config3 & 0x3f)
1683 | ((data->gpio_config[16] & 0x03) << 6);
1684 adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3);
1685 for (i = 15, value = 0; i >= 0; --i) {
1686 value <<= 2;
1687 value |= data->gpio_config[i] & 0x03;
1688 if ((i & 0x03) == 0) {
1689 adm1026_write_value(client,
1690 ADM1026_REG_GPIO_CFG_0_3 + i/4,
1691 value);
1692 value = 0;
1693 }
1694 }
1695
1696 /* Print the new config */
1697 adm1026_print_gpio(client);
1698}
1699
1700static void adm1026_init_client(struct i2c_client *client)
1701{
1702 int value, i;
1703 struct adm1026_data *data = i2c_get_clientdata(client);
1704
1705 dev_dbg(&client->dev, "Initializing device\n");
1706 /* Read chip config */
1707 data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
1708 data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
1709 data->config3 = adm1026_read_value(client, ADM1026_REG_CONFIG3);
1710
1711 /* Inform user of chip config */
1712 dev_dbg(&client->dev, "ADM1026_REG_CONFIG1 is: 0x%02x\n",
1713 data->config1);
1714 if ((data->config1 & CFG1_MONITOR) == 0) {
1715 dev_dbg(&client->dev,
1716 "Monitoring not currently enabled.\n");
1717 }
1718 if (data->config1 & CFG1_INT_ENABLE) {
1719 dev_dbg(&client->dev,
1720 "SMBALERT interrupts are enabled.\n");
1721 }
1722 if (data->config1 & CFG1_AIN8_9) {
1723 dev_dbg(&client->dev,
1724 "in8 and in9 enabled. temp3 disabled.\n");
1725 } else {
1726 dev_dbg(&client->dev,
1727 "temp3 enabled. in8 and in9 disabled.\n");
1728 }
1729 if (data->config1 & CFG1_THERM_HOT) {
1730 dev_dbg(&client->dev,
1731 "Automatic THERM, PWM, and temp limits enabled.\n");
1732 }
1733
1734 if (data->config3 & CFG3_GPIO16_ENABLE) {
1735 dev_dbg(&client->dev,
1736 "GPIO16 enabled. THERM pin disabled.\n");
1737 } else {
1738 dev_dbg(&client->dev,
1739 "THERM pin enabled. GPIO16 disabled.\n");
1740 }
1741 if (data->config3 & CFG3_VREF_250)
1742 dev_dbg(&client->dev, "Vref is 2.50 Volts.\n");
1743 else
1744 dev_dbg(&client->dev, "Vref is 1.82 Volts.\n");
1745 /* Read and pick apart the existing GPIO configuration */
1746 value = 0;
1747 for (i = 0; i <= 15; ++i) {
1748 if ((i & 0x03) == 0) {
1749 value = adm1026_read_value(client,
1750 ADM1026_REG_GPIO_CFG_0_3 + i / 4);
1751 }
1752 data->gpio_config[i] = value & 0x03;
1753 value >>= 2;
1754 }
1755 data->gpio_config[16] = (data->config3 >> 6) & 0x03;
1756
1757 /* ... and then print it */
1758 adm1026_print_gpio(client);
1759
1760 /*
1761 * If the user asks us to reprogram the GPIO config, then
1762 * do it now.
1763 */
1764 if (gpio_input[0] != -1 || gpio_output[0] != -1
1765 || gpio_inverted[0] != -1 || gpio_normal[0] != -1
1766 || gpio_fan[0] != -1) {
1767 adm1026_fixup_gpio(client);
1768 }
1769
1770 /*
1771 * WE INTENTIONALLY make no changes to the limits,
1772 * offsets, pwms, fans and zones. If they were
1773 * configured, we don't want to mess with them.
1774 * If they weren't, the default is 100% PWM, no
1775 * control and will suffice until 'sensors -s'
1776 * can be run by the user. We DO set the default
1777 * value for pwm1.auto_pwm_min to its maximum
1778 * so that enabling automatic pwm fan control
1779 * without first setting a value for pwm1.auto_pwm_min
1780 * will not result in potentially dangerous fan speed decrease.
1781 */
1782 data->pwm1.auto_pwm_min = 255;
1783 /* Start monitoring */
1784 value = adm1026_read_value(client, ADM1026_REG_CONFIG1);
1785 /* Set MONITOR, clear interrupt acknowledge and s/w reset */
1786 value = (value | CFG1_MONITOR) & (~CFG1_INT_CLEAR & ~CFG1_RESET);
1787 dev_dbg(&client->dev, "Setting CONFIG to: 0x%02x\n", value);
1788 data->config1 = value;
1789 adm1026_write_value(client, ADM1026_REG_CONFIG1, value);
1790
1791 /* initialize fan_div[] to hardware defaults */
1792 value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3) |
1793 (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7) << 8);
1794 for (i = 0; i <= 7; ++i) {
1795 data->fan_div[i] = DIV_FROM_REG(value & 0x03);
1796 value >>= 2;
1797 }
1798}
1799
1832static int adm1026_probe(struct i2c_client *client, 1800static int adm1026_probe(struct i2c_client *client,
1833 const struct i2c_device_id *id) 1801 const struct i2c_device_id *id)
1834{ 1802{
@@ -1892,6 +1860,24 @@ static int adm1026_remove(struct i2c_client *client)
1892 return 0; 1860 return 0;
1893} 1861}
1894 1862
1863static const struct i2c_device_id adm1026_id[] = {
1864 { "adm1026", 0 },
1865 { }
1866};
1867MODULE_DEVICE_TABLE(i2c, adm1026_id);
1868
1869static struct i2c_driver adm1026_driver = {
1870 .class = I2C_CLASS_HWMON,
1871 .driver = {
1872 .name = "adm1026",
1873 },
1874 .probe = adm1026_probe,
1875 .remove = adm1026_remove,
1876 .id_table = adm1026_id,
1877 .detect = adm1026_detect,
1878 .address_list = normal_i2c,
1879};
1880
1895module_i2c_driver(adm1026_driver); 1881module_i2c_driver(adm1026_driver);
1896 1882
1897MODULE_LICENSE("GPL"); 1883MODULE_LICENSE("GPL");