aspeed-pwm-tacho.c (ece0c03a9e5f727435d19754411e59c3ae28cbb8) aspeed-pwm-tacho.c (44b413661b57cbbb7e4c3adf7b087fada42a443e)
1/*
2 * Copyright (c) 2016 Google, Inc
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 or later as
6 * published by the Free Software Foundation.
7 */
8

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

158 * 01: rising
159 * 10: both
160 * 11: reserved.
161 */
162#define M_TACH_MODE 0x02 /* 10b */
163#define M_TACH_UNIT 0x00c0
164#define INIT_FAN_CTRL 0xFF
165
1/*
2 * Copyright (c) 2016 Google, Inc
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 or later as
6 * published by the Free Software Foundation.
7 */
8

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

158 * 01: rising
159 * 10: both
160 * 11: reserved.
161 */
162#define M_TACH_MODE 0x02 /* 10b */
163#define M_TACH_UNIT 0x00c0
164#define INIT_FAN_CTRL 0xFF
165
166/* How long we sleep in us while waiting for an RPM result. */
167#define ASPEED_RPM_STATUS_SLEEP_USEC 500
168
166struct aspeed_pwm_tacho_data {
167 struct regmap *regmap;
168 unsigned long clk_freq;
169 bool pwm_present[8];
170 bool fan_tach_present[16];
171 u8 type_pwm_clock_unit[3];
172 u8 type_pwm_clock_division_h[3];
173 u8 type_pwm_clock_division_l[3];

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

503
504 tacho_div = 0x4 << (tacho_div * 2);
505 return clk / (clk_unit * div_h * div_l * tacho_div * tacho_unit);
506}
507
508static int aspeed_get_fan_tach_ch_rpm(struct aspeed_pwm_tacho_data *priv,
509 u8 fan_tach_ch)
510{
169struct aspeed_pwm_tacho_data {
170 struct regmap *regmap;
171 unsigned long clk_freq;
172 bool pwm_present[8];
173 bool fan_tach_present[16];
174 u8 type_pwm_clock_unit[3];
175 u8 type_pwm_clock_division_h[3];
176 u8 type_pwm_clock_division_l[3];

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

506
507 tacho_div = 0x4 << (tacho_div * 2);
508 return clk / (clk_unit * div_h * div_l * tacho_div * tacho_unit);
509}
510
511static int aspeed_get_fan_tach_ch_rpm(struct aspeed_pwm_tacho_data *priv,
512 u8 fan_tach_ch)
513{
511 u32 raw_data, tach_div, clk_source, sec, val;
514 u32 raw_data, tach_div, clk_source, msec, usec, val;
512 u8 fan_tach_ch_source, type, mode, both;
515 u8 fan_tach_ch_source, type, mode, both;
516 int ret;
513
514 regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0);
515 regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0x1 << fan_tach_ch);
516
517 fan_tach_ch_source = priv->fan_tach_ch_source[fan_tach_ch];
518 type = priv->pwm_port_type[fan_tach_ch_source];
519
517
518 regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0);
519 regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0x1 << fan_tach_ch);
520
521 fan_tach_ch_source = priv->fan_tach_ch_source[fan_tach_ch];
522 type = priv->pwm_port_type[fan_tach_ch_source];
523
520 sec = (1000 / aspeed_get_fan_tach_ch_measure_period(priv, type));
521 msleep(sec);
524 msec = (1000 / aspeed_get_fan_tach_ch_measure_period(priv, type));
525 usec = msec * 1000;
522
526
523 regmap_read(priv->regmap, ASPEED_PTCR_RESULT, &val);
524 if (!(val & RESULT_STATUS_MASK))
525 return -ETIMEDOUT;
527 ret = regmap_read_poll_timeout(
528 priv->regmap,
529 ASPEED_PTCR_RESULT,
530 val,
531 (val & RESULT_STATUS_MASK),
532 ASPEED_RPM_STATUS_SLEEP_USEC,
533 usec);
526
534
535 /* return -ETIMEDOUT if we didn't get an answer. */
536 if (ret)
537 return ret;
538
527 raw_data = val & RESULT_VALUE_MASK;
528 tach_div = priv->type_fan_tach_clock_division[type];
529 /*
530 * We need the mode to determine if the raw_data is double (from
531 * counting both edges).
532 */
533 mode = priv->type_fan_tach_mode[type];
534 both = (mode & BOTH_EDGES) ? 1 : 0;

--- 324 unchanged lines hidden ---
539 raw_data = val & RESULT_VALUE_MASK;
540 tach_div = priv->type_fan_tach_clock_division[type];
541 /*
542 * We need the mode to determine if the raw_data is double (from
543 * counting both edges).
544 */
545 mode = priv->type_fan_tach_mode[type];
546 both = (mode & BOTH_EDGES) ? 1 : 0;

--- 324 unchanged lines hidden ---