@ -163,6 +163,9 @@
# define M_TACH_UNIT 0x00c0
# define M_TACH_UNIT 0x00c0
# define INIT_FAN_CTRL 0xFF
# define INIT_FAN_CTRL 0xFF
/* How long we sleep in us while waiting for an RPM result. */
# define ASPEED_RPM_STATUS_SLEEP_USEC 500
struct aspeed_pwm_tacho_data {
struct aspeed_pwm_tacho_data {
struct regmap * regmap ;
struct regmap * regmap ;
unsigned long clk_freq ;
unsigned long clk_freq ;
@ -508,8 +511,9 @@ static u32 aspeed_get_fan_tach_ch_measure_period(struct aspeed_pwm_tacho_data
static int aspeed_get_fan_tach_ch_rpm ( struct aspeed_pwm_tacho_data * priv ,
static int aspeed_get_fan_tach_ch_rpm ( struct aspeed_pwm_tacho_data * priv ,
u8 fan_tach_ch )
u8 fan_tach_ch )
{
{
u32 raw_data , tach_div , clk_source , sec , val ;
u32 raw_data , tach_div , clk_source , msec , u sec, val ;
u8 fan_tach_ch_source , type , mode , both ;
u8 fan_tach_ch_source , type , mode , both ;
int ret ;
regmap_write ( priv - > regmap , ASPEED_PTCR_TRIGGER , 0 ) ;
regmap_write ( priv - > regmap , ASPEED_PTCR_TRIGGER , 0 ) ;
regmap_write ( priv - > regmap , ASPEED_PTCR_TRIGGER , 0x1 < < fan_tach_ch ) ;
regmap_write ( priv - > regmap , ASPEED_PTCR_TRIGGER , 0x1 < < fan_tach_ch ) ;
@ -517,12 +521,20 @@ static int aspeed_get_fan_tach_ch_rpm(struct aspeed_pwm_tacho_data *priv,
fan_tach_ch_source = priv - > fan_tach_ch_source [ fan_tach_ch ] ;
fan_tach_ch_source = priv - > fan_tach_ch_source [ fan_tach_ch ] ;
type = priv - > pwm_port_type [ fan_tach_ch_source ] ;
type = priv - > pwm_port_type [ fan_tach_ch_source ] ;
sec = ( 1000 / aspeed_get_fan_tach_ch_measure_period ( priv , type ) ) ;
msec = ( 1000 / aspeed_get_fan_tach_ch_measure_period ( priv , type ) ) ;
msleep ( sec ) ;
usec = msec * 1000 ;
ret = regmap_read_poll_timeout (
priv - > regmap ,
ASPEED_PTCR_RESULT ,
val ,
( val & RESULT_STATUS_MASK ) ,
ASPEED_RPM_STATUS_SLEEP_USEC ,
usec ) ;
regmap_read ( priv - > regmap , ASPEED_PTCR_RESULT , & val ) ;
/* return -ETIMEDOUT if we didn't get an answer. */
if ( ! ( val & RESULT_STATUS_MASK ) )
if ( ret )
return - ETIMEDOUT ;
return ret ;
raw_data = val & RESULT_VALUE_MASK ;
raw_data = val & RESULT_VALUE_MASK ;
tach_div = priv - > type_fan_tach_clock_division [ type ] ;
tach_div = priv - > type_fan_tach_clock_division [ type ] ;