aspeed-pwm-tacho.c (fe33c0fbed75dd464747c0faaedf94c7d8eb4101) | aspeed-pwm-tacho.c (1168491e7f53581ba7b6014a39a49cfbbb722feb) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright (c) 2016 Google, Inc 4 */ 5 6#include <linux/clk.h> 7#include <linux/delay.h> 8#include <linux/errno.h> --- 181 unchanged lines hidden (view full) --- 190 u8 type_fan_tach_clock_division[3]; 191 u8 type_fan_tach_mode[3]; 192 u16 type_fan_tach_unit[3]; 193 u8 pwm_port_type[8]; 194 u8 pwm_port_fan_ctrl[8]; 195 u8 fan_tach_ch_source[MAX_ASPEED_FAN_TACH_CHANNELS]; 196 struct aspeed_cooling_device *cdev[8]; 197 const struct attribute_group *groups[3]; | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright (c) 2016 Google, Inc 4 */ 5 6#include <linux/clk.h> 7#include <linux/delay.h> 8#include <linux/errno.h> --- 181 unchanged lines hidden (view full) --- 190 u8 type_fan_tach_clock_division[3]; 191 u8 type_fan_tach_mode[3]; 192 u16 type_fan_tach_unit[3]; 193 u8 pwm_port_type[8]; 194 u8 pwm_port_fan_ctrl[8]; 195 u8 fan_tach_ch_source[MAX_ASPEED_FAN_TACH_CHANNELS]; 196 struct aspeed_cooling_device *cdev[8]; 197 const struct attribute_group *groups[3]; |
198 /* protects access to shared ASPEED_PTCR_RESULT */ 199 struct mutex tach_lock; |
|
198}; 199 200enum type { TYPEM, TYPEN, TYPEO }; 201 202struct type_params { 203 u32 l_value; 204 u32 h_value; 205 u32 unit_value; --- 318 unchanged lines hidden (view full) --- 524 525static int aspeed_get_fan_tach_ch_rpm(struct aspeed_pwm_tacho_data *priv, 526 u8 fan_tach_ch) 527{ 528 u32 raw_data, tach_div, clk_source, msec, usec, val; 529 u8 fan_tach_ch_source, type, mode, both; 530 int ret; 531 | 200}; 201 202enum type { TYPEM, TYPEN, TYPEO }; 203 204struct type_params { 205 u32 l_value; 206 u32 h_value; 207 u32 unit_value; --- 318 unchanged lines hidden (view full) --- 526 527static int aspeed_get_fan_tach_ch_rpm(struct aspeed_pwm_tacho_data *priv, 528 u8 fan_tach_ch) 529{ 530 u32 raw_data, tach_div, clk_source, msec, usec, val; 531 u8 fan_tach_ch_source, type, mode, both; 532 int ret; 533 |
534 mutex_lock(&priv->tach_lock); 535 |
|
532 regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0); 533 regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0x1 << fan_tach_ch); 534 535 fan_tach_ch_source = priv->fan_tach_ch_source[fan_tach_ch]; 536 type = priv->pwm_port_type[fan_tach_ch_source]; 537 538 msec = (1000 / aspeed_get_fan_tach_ch_measure_period(priv, type)); 539 usec = msec * 1000; 540 541 ret = regmap_read_poll_timeout( 542 priv->regmap, 543 ASPEED_PTCR_RESULT, 544 val, 545 (val & RESULT_STATUS_MASK), 546 ASPEED_RPM_STATUS_SLEEP_USEC, 547 usec); 548 | 536 regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0); 537 regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0x1 << fan_tach_ch); 538 539 fan_tach_ch_source = priv->fan_tach_ch_source[fan_tach_ch]; 540 type = priv->pwm_port_type[fan_tach_ch_source]; 541 542 msec = (1000 / aspeed_get_fan_tach_ch_measure_period(priv, type)); 543 usec = msec * 1000; 544 545 ret = regmap_read_poll_timeout( 546 priv->regmap, 547 ASPEED_PTCR_RESULT, 548 val, 549 (val & RESULT_STATUS_MASK), 550 ASPEED_RPM_STATUS_SLEEP_USEC, 551 usec); 552 |
553 mutex_unlock(&priv->tach_lock); 554 |
|
549 /* return -ETIMEDOUT if we didn't get an answer. */ 550 if (ret) 551 return ret; 552 553 raw_data = val & RESULT_VALUE_MASK; 554 tach_div = priv->type_fan_tach_clock_division[type]; 555 /* 556 * We need the mode to determine if the raw_data is double (from --- 353 unchanged lines hidden (view full) --- 910 911 np = dev->of_node; 912 regs = devm_platform_ioremap_resource(pdev, 0); 913 if (IS_ERR(regs)) 914 return PTR_ERR(regs); 915 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 916 if (!priv) 917 return -ENOMEM; | 555 /* return -ETIMEDOUT if we didn't get an answer. */ 556 if (ret) 557 return ret; 558 559 raw_data = val & RESULT_VALUE_MASK; 560 tach_div = priv->type_fan_tach_clock_division[type]; 561 /* 562 * We need the mode to determine if the raw_data is double (from --- 353 unchanged lines hidden (view full) --- 916 917 np = dev->of_node; 918 regs = devm_platform_ioremap_resource(pdev, 0); 919 if (IS_ERR(regs)) 920 return PTR_ERR(regs); 921 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 922 if (!priv) 923 return -ENOMEM; |
924 mutex_init(&priv->tach_lock); |
|
918 priv->regmap = devm_regmap_init(dev, NULL, (__force void *)regs, 919 &aspeed_pwm_tacho_regmap_config); 920 if (IS_ERR(priv->regmap)) 921 return PTR_ERR(priv->regmap); 922 923 priv->rst = devm_reset_control_get_exclusive(dev, NULL); 924 if (IS_ERR(priv->rst)) { 925 dev_err(dev, --- 58 unchanged lines hidden --- | 925 priv->regmap = devm_regmap_init(dev, NULL, (__force void *)regs, 926 &aspeed_pwm_tacho_regmap_config); 927 if (IS_ERR(priv->regmap)) 928 return PTR_ERR(priv->regmap); 929 930 priv->rst = devm_reset_control_get_exclusive(dev, NULL); 931 if (IS_ERR(priv->rst)) { 932 dev_err(dev, --- 58 unchanged lines hidden --- |