adt7475.c (cbecf716ca618fd44feda6bd9a64a8179d031fc5) adt7475.c (7b8664f126e90d1d2129b8653c587bf230dd800c)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * adt7475 - Thermal sensor driver for the ADT7475 chip and derivatives
4 * Copyright (C) 2007-2008, Advanced Micro Devices, Inc.
5 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>
6 * Copyright (C) 2008 Hans de Goede <hdegoede@redhat.com>
7 * Copyright (C) 2009 Jean Delvare <jdelvare@suse.de>
8 *

--- 98 unchanged lines hidden (view full) ---

107#define VID_VIDSEL 0x80 /* ADT7476 only */
108
109#define CONFIG2_ATTN 0x20
110
111#define CONFIG3_SMBALERT 0x01
112#define CONFIG3_THERM 0x02
113
114#define CONFIG4_PINFUNC 0x03
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * adt7475 - Thermal sensor driver for the ADT7475 chip and derivatives
4 * Copyright (C) 2007-2008, Advanced Micro Devices, Inc.
5 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>
6 * Copyright (C) 2008 Hans de Goede <hdegoede@redhat.com>
7 * Copyright (C) 2009 Jean Delvare <jdelvare@suse.de>
8 *

--- 98 unchanged lines hidden (view full) ---

107#define VID_VIDSEL 0x80 /* ADT7476 only */
108
109#define CONFIG2_ATTN 0x20
110
111#define CONFIG3_SMBALERT 0x01
112#define CONFIG3_THERM 0x02
113
114#define CONFIG4_PINFUNC 0x03
115#define CONFIG4_THERM 0x01
116#define CONFIG4_SMBALERT 0x02
115#define CONFIG4_MAXDUTY 0x08
116#define CONFIG4_ATTN_IN10 0x30
117#define CONFIG4_ATTN_IN43 0xC0
118
119#define CONFIG5_TWOSCOMP 0x01
120#define CONFIG5_TEMPOFFSET 0x02
121#define CONFIG5_VIDGPIO 0x10 /* ADT7476 only */
122

--- 1332 unchanged lines hidden (view full) ---

1455 ret = adt7475_read(TEMP_TRANGE_REG(2));
1456 if (ret < 0)
1457 return ret;
1458 data->range[2] = ret;
1459
1460 return 0;
1461}
1462
117#define CONFIG4_MAXDUTY 0x08
118#define CONFIG4_ATTN_IN10 0x30
119#define CONFIG4_ATTN_IN43 0xC0
120
121#define CONFIG5_TWOSCOMP 0x01
122#define CONFIG5_TEMPOFFSET 0x02
123#define CONFIG5_VIDGPIO 0x10 /* ADT7476 only */
124

--- 1332 unchanged lines hidden (view full) ---

1457 ret = adt7475_read(TEMP_TRANGE_REG(2));
1458 if (ret < 0)
1459 return ret;
1460 data->range[2] = ret;
1461
1462 return 0;
1463}
1464
1465static int load_config3(const struct i2c_client *client, const char *propname)
1466{
1467 const char *function;
1468 u8 config3;
1469 int ret;
1470
1471 ret = of_property_read_string(client->dev.of_node, propname, &function);
1472 if (!ret) {
1473 ret = adt7475_read(REG_CONFIG3);
1474 if (ret < 0)
1475 return ret;
1476
1477 config3 = ret & ~CONFIG3_SMBALERT;
1478 if (!strcmp("pwm2", function))
1479 ;
1480 else if (!strcmp("smbalert#", function))
1481 config3 |= CONFIG3_SMBALERT;
1482 else
1483 return -EINVAL;
1484
1485 return i2c_smbus_write_byte_data(client, REG_CONFIG3, config3);
1486 }
1487
1488 return 0;
1489}
1490
1491static int load_config4(const struct i2c_client *client, const char *propname)
1492{
1493 const char *function;
1494 u8 config4;
1495 int ret;
1496
1497 ret = of_property_read_string(client->dev.of_node, propname, &function);
1498 if (!ret) {
1499 ret = adt7475_read(REG_CONFIG4);
1500 if (ret < 0)
1501 return ret;
1502
1503 config4 = ret & ~CONFIG4_PINFUNC;
1504
1505 if (!strcmp("tach4", function))
1506 ;
1507 else if (!strcmp("therm#", function))
1508 config4 |= CONFIG4_THERM;
1509 else if (!strcmp("smbalert#", function))
1510 config4 |= CONFIG4_SMBALERT;
1511 else if (!strcmp("gpio", function))
1512 config4 |= CONFIG4_PINFUNC;
1513 else
1514 return -EINVAL;
1515
1516 return i2c_smbus_write_byte_data(client, REG_CONFIG4, config4);
1517 }
1518
1519 return 0;
1520}
1521
1522static int load_config(const struct i2c_client *client, enum chips chip)
1523{
1524 int err;
1525 const char *prop1, *prop2;
1526
1527 switch (chip) {
1528 case adt7473:
1529 case adt7475:
1530 prop1 = "adi,pin5-function";
1531 prop2 = "adi,pin9-function";
1532 break;
1533 case adt7476:
1534 case adt7490:
1535 prop1 = "adi,pin10-function";
1536 prop2 = "adi,pin14-function";
1537 break;
1538 }
1539
1540 err = load_config3(client, prop1);
1541 if (err) {
1542 dev_err(&client->dev, "failed to configure %s\n", prop1);
1543 return err;
1544 }
1545
1546 err = load_config4(client, prop2);
1547 if (err) {
1548 dev_err(&client->dev, "failed to configure %s\n", prop2);
1549 return err;
1550 }
1551
1552 return 0;
1553}
1554
1463static int set_property_bit(const struct i2c_client *client, char *property,
1464 u8 *config, u8 bit_index)
1465{
1466 u32 prop_value = 0;
1467 int ret = of_property_read_u32(client->dev.of_node, property,
1468 &prop_value);
1469
1470 if (!ret) {

--- 109 unchanged lines hidden (view full) ---

1580 if (revision == 0x03)
1581 revision += adt7475_read(REG_DEVREV2);
1582 break;
1583 default:
1584 data->has_voltage = 0x06; /* in1, in2 */
1585 revision = adt7475_read(REG_DEVID2) & 0x07;
1586 }
1587
1555static int set_property_bit(const struct i2c_client *client, char *property,
1556 u8 *config, u8 bit_index)
1557{
1558 u32 prop_value = 0;
1559 int ret = of_property_read_u32(client->dev.of_node, property,
1560 &prop_value);
1561
1562 if (!ret) {

--- 109 unchanged lines hidden (view full) ---

1672 if (revision == 0x03)
1673 revision += adt7475_read(REG_DEVREV2);
1674 break;
1675 default:
1676 data->has_voltage = 0x06; /* in1, in2 */
1677 revision = adt7475_read(REG_DEVID2) & 0x07;
1678 }
1679
1680 ret = load_config(client, chip);
1681 if (ret)
1682 return ret;
1683
1588 config3 = adt7475_read(REG_CONFIG3);
1589 /* Pin PWM2 may alternatively be used for ALERT output */
1590 if (!(config3 & CONFIG3_SMBALERT))
1591 data->has_pwm2 = 1;
1592 /* Meaning of this bit is inverted for the ADT7473-1 */
1593 if (id->driver_data == adt7473 && revision >= 1)
1594 data->has_pwm2 = !data->has_pwm2;
1595

--- 334 unchanged lines hidden ---
1684 config3 = adt7475_read(REG_CONFIG3);
1685 /* Pin PWM2 may alternatively be used for ALERT output */
1686 if (!(config3 & CONFIG3_SMBALERT))
1687 data->has_pwm2 = 1;
1688 /* Meaning of this bit is inverted for the ADT7473-1 */
1689 if (id->driver_data == adt7473 && revision >= 1)
1690 data->has_pwm2 = !data->has_pwm2;
1691

--- 334 unchanged lines hidden ---