g762.c (594ce0b8a998aa4d05827cd7c0d0dcec9a1e3ae2) | g762.c (6ce402327a6fb714a9f40a0bb59bcbfe383839a5) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * g762 - Driver for the Global Mixed-mode Technology Inc. fan speed 4 * PWM controller chips from G762 family, i.e. G762 and G763 5 * 6 * Copyright (C) 2013, Arnaud EBALARD <arno@natisbad.org> 7 * 8 * This work is based on a basic version for 2.6.31 kernel developed --- 55 unchanged lines hidden (view full) --- 64#define G762_REG_FAN_CMD1_DET_FAN_OOC 0x40 /* enable fan_out_of_control */ 65#define G762_REG_FAN_CMD1_OUT_MODE 0x20 /* out mode: PWM or DC */ 66#define G762_REG_FAN_CMD1_FAN_MODE 0x10 /* fan mode: closed/open-loop */ 67#define G762_REG_FAN_CMD1_CLK_DIV_ID1 0x08 /* clock divisor value */ 68#define G762_REG_FAN_CMD1_CLK_DIV_ID0 0x04 69#define G762_REG_FAN_CMD1_PWM_POLARITY 0x02 /* PWM polarity */ 70#define G762_REG_FAN_CMD1_PULSE_PER_REV 0x01 /* pulse per fan revolution */ 71 | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * g762 - Driver for the Global Mixed-mode Technology Inc. fan speed 4 * PWM controller chips from G762 family, i.e. G762 and G763 5 * 6 * Copyright (C) 2013, Arnaud EBALARD <arno@natisbad.org> 7 * 8 * This work is based on a basic version for 2.6.31 kernel developed --- 55 unchanged lines hidden (view full) --- 64#define G762_REG_FAN_CMD1_DET_FAN_OOC 0x40 /* enable fan_out_of_control */ 65#define G762_REG_FAN_CMD1_OUT_MODE 0x20 /* out mode: PWM or DC */ 66#define G762_REG_FAN_CMD1_FAN_MODE 0x10 /* fan mode: closed/open-loop */ 67#define G762_REG_FAN_CMD1_CLK_DIV_ID1 0x08 /* clock divisor value */ 68#define G762_REG_FAN_CMD1_CLK_DIV_ID0 0x04 69#define G762_REG_FAN_CMD1_PWM_POLARITY 0x02 /* PWM polarity */ 70#define G762_REG_FAN_CMD1_PULSE_PER_REV 0x01 /* pulse per fan revolution */ 71 |
72#define G761_REG_FAN_CMD2_FAN_CLOCK 0x20 /* choose internal clock*/ |
|
72#define G762_REG_FAN_CMD2_GEAR_MODE_1 0x08 /* fan gear mode */ 73#define G762_REG_FAN_CMD2_GEAR_MODE_0 0x04 74#define G762_REG_FAN_CMD2_FAN_STARTV_1 0x02 /* fan startup voltage */ 75#define G762_REG_FAN_CMD2_FAN_STARTV_0 0x01 76 77#define G762_REG_FAN_STA_FAIL 0x02 /* fan fail */ 78#define G762_REG_FAN_STA_OOC 0x01 /* fan out of control */ 79 --- 30 unchanged lines hidden (view full) --- 110 * FAN_CMD2 register value. 111 */ 112#define G762_GEARMULT_FROM_REG(reg) \ 113 (1 << (((reg) & (G762_REG_FAN_CMD2_GEAR_MODE_0 | \ 114 G762_REG_FAN_CMD2_GEAR_MODE_1)) >> 2)) 115 116struct g762_data { 117 struct i2c_client *client; | 73#define G762_REG_FAN_CMD2_GEAR_MODE_1 0x08 /* fan gear mode */ 74#define G762_REG_FAN_CMD2_GEAR_MODE_0 0x04 75#define G762_REG_FAN_CMD2_FAN_STARTV_1 0x02 /* fan startup voltage */ 76#define G762_REG_FAN_CMD2_FAN_STARTV_0 0x01 77 78#define G762_REG_FAN_STA_FAIL 0x02 /* fan fail */ 79#define G762_REG_FAN_STA_OOC 0x01 /* fan out of control */ 80 --- 30 unchanged lines hidden (view full) --- 111 * FAN_CMD2 register value. 112 */ 113#define G762_GEARMULT_FROM_REG(reg) \ 114 (1 << (((reg) & (G762_REG_FAN_CMD2_GEAR_MODE_0 | \ 115 G762_REG_FAN_CMD2_GEAR_MODE_1)) >> 2)) 116 117struct g762_data { 118 struct i2c_client *client; |
119 bool internal_clock; |
|
118 struct clk *clk; 119 120 /* update mutex */ 121 struct mutex update_lock; 122 123 /* board specific parameters. */ 124 u32 clk_freq; 125 --- 435 unchanged lines hidden (view full) --- 561 562/* 563 * Helper to import hardware characteristics from .dts file and push 564 * those to the chip. 565 */ 566 567#ifdef CONFIG_OF 568static const struct of_device_id g762_dt_match[] = { | 120 struct clk *clk; 121 122 /* update mutex */ 123 struct mutex update_lock; 124 125 /* board specific parameters. */ 126 u32 clk_freq; 127 --- 435 unchanged lines hidden (view full) --- 563 564/* 565 * Helper to import hardware characteristics from .dts file and push 566 * those to the chip. 567 */ 568 569#ifdef CONFIG_OF 570static const struct of_device_id g762_dt_match[] = { |
571 { .compatible = "gmt,g761" }, |
|
569 { .compatible = "gmt,g762" }, 570 { .compatible = "gmt,g763" }, 571 { }, 572}; 573MODULE_DEVICE_TABLE(of, g762_dt_match); 574 575/* 576 * Grab clock (a required property), enable it, get (fixed) clock frequency --- 15 unchanged lines hidden (view full) --- 592 struct g762_data *data; 593 unsigned long clk_freq; 594 struct clk *clk; 595 int ret; 596 597 if (!client->dev.of_node) 598 return 0; 599 | 572 { .compatible = "gmt,g762" }, 573 { .compatible = "gmt,g763" }, 574 { }, 575}; 576MODULE_DEVICE_TABLE(of, g762_dt_match); 577 578/* 579 * Grab clock (a required property), enable it, get (fixed) clock frequency --- 15 unchanged lines hidden (view full) --- 595 struct g762_data *data; 596 unsigned long clk_freq; 597 struct clk *clk; 598 int ret; 599 600 if (!client->dev.of_node) 601 return 0; 602 |
603 data = i2c_get_clientdata(client); 604 605 /* 606 * Skip CLK detection and handling if we use internal clock. 607 * This is only valid for g761. 608 */ 609 data->internal_clock = of_device_is_compatible(client->dev.of_node, 610 "gmt,g761") && 611 !of_property_present(client->dev.of_node, 612 "clocks"); 613 if (data->internal_clock) { 614 do_set_clk_freq(&client->dev, 32768); 615 return 0; 616 } 617 |
|
600 clk = of_clk_get(client->dev.of_node, 0); 601 if (IS_ERR(clk)) { 602 dev_err(&client->dev, "failed to get clock\n"); 603 return PTR_ERR(clk); 604 } 605 606 ret = clk_prepare_enable(clk); 607 if (ret) { 608 dev_err(&client->dev, "failed to enable clock\n"); 609 goto clk_put; 610 } 611 612 clk_freq = clk_get_rate(clk); 613 ret = do_set_clk_freq(&client->dev, clk_freq); 614 if (ret) { 615 dev_err(&client->dev, "invalid clock freq %lu\n", clk_freq); 616 goto clk_unprep; 617 } 618 | 618 clk = of_clk_get(client->dev.of_node, 0); 619 if (IS_ERR(clk)) { 620 dev_err(&client->dev, "failed to get clock\n"); 621 return PTR_ERR(clk); 622 } 623 624 ret = clk_prepare_enable(clk); 625 if (ret) { 626 dev_err(&client->dev, "failed to enable clock\n"); 627 goto clk_put; 628 } 629 630 clk_freq = clk_get_rate(clk); 631 ret = do_set_clk_freq(&client->dev, clk_freq); 632 if (ret) { 633 dev_err(&client->dev, "invalid clock freq %lu\n", clk_freq); 634 goto clk_unprep; 635 } 636 |
619 data = i2c_get_clientdata(client); | |
620 data->clk = clk; 621 622 ret = devm_add_action(&client->dev, g762_of_clock_disable, data); 623 if (ret) { 624 dev_err(&client->dev, "failed to add disable clock action\n"); 625 goto clk_unprep; 626 } 627 --- 392 unchanged lines hidden (view full) --- 1020/* 1021 * Enable both fan failure detection and fan out of control protection. The 1022 * function does not protect change/access to data structure; it must thus 1023 * only be called during initialization. 1024 */ 1025static inline int g762_fan_init(struct device *dev) 1026{ 1027 struct g762_data *data = g762_update_client(dev); | 637 data->clk = clk; 638 639 ret = devm_add_action(&client->dev, g762_of_clock_disable, data); 640 if (ret) { 641 dev_err(&client->dev, "failed to add disable clock action\n"); 642 goto clk_unprep; 643 } 644 --- 392 unchanged lines hidden (view full) --- 1037/* 1038 * Enable both fan failure detection and fan out of control protection. The 1039 * function does not protect change/access to data structure; it must thus 1040 * only be called during initialization. 1041 */ 1042static inline int g762_fan_init(struct device *dev) 1043{ 1044 struct g762_data *data = g762_update_client(dev); |
1045 int ret; |
|
1028 1029 if (IS_ERR(data)) 1030 return PTR_ERR(data); 1031 | 1046 1047 if (IS_ERR(data)) 1048 return PTR_ERR(data); 1049 |
1050 /* internal_clock can only be set with compatible g761 */ 1051 if (data->internal_clock) 1052 data->fan_cmd2 |= G761_REG_FAN_CMD2_FAN_CLOCK; 1053 |
|
1032 data->fan_cmd1 |= G762_REG_FAN_CMD1_DET_FAN_FAIL; 1033 data->fan_cmd1 |= G762_REG_FAN_CMD1_DET_FAN_OOC; 1034 data->valid = false; 1035 | 1054 data->fan_cmd1 |= G762_REG_FAN_CMD1_DET_FAN_FAIL; 1055 data->fan_cmd1 |= G762_REG_FAN_CMD1_DET_FAN_OOC; 1056 data->valid = false; 1057 |
1036 return i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD1, 1037 data->fan_cmd1); | 1058 ret = i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD1, 1059 data->fan_cmd1); 1060 if (ret) 1061 return ret; 1062 1063 return i2c_smbus_write_byte_data(data->client, G762_REG_FAN_CMD2, 1064 data->fan_cmd2); |
1038} 1039 1040static int g762_probe(struct i2c_client *client) 1041{ 1042 struct device *dev = &client->dev; 1043 struct device *hwmon_dev; 1044 struct g762_data *data; 1045 int ret; --- 49 unchanged lines hidden --- | 1065} 1066 1067static int g762_probe(struct i2c_client *client) 1068{ 1069 struct device *dev = &client->dev; 1070 struct device *hwmon_dev; 1071 struct g762_data *data; 1072 int ret; --- 49 unchanged lines hidden --- |