|
30 | 30 | #include <linux/debugfs.h> |
31 | 31 | #include <linux/delay.h> |
32 | 32 | #include <linux/io.h> |
| 33 | +#include <linux/math.h> |
33 | 34 | #include <linux/module.h> |
34 | 35 | #include <linux/of_device.h> |
35 | 36 | #include <linux/platform_device.h> |
@@ -502,6 +503,8 @@ struct bcm2835_clock_data { |
502 | 503 | bool low_jitter; |
503 | 504 |
|
504 | 505 | u32 tcnt_mux; |
| 506 | + |
| 507 | + bool round_up; |
505 | 508 | }; |
506 | 509 |
|
507 | 510 | struct bcm2835_gate_data { |
@@ -993,20 +996,47 @@ static long bcm2835_clock_rate_from_divisor(struct bcm2835_clock *clock, |
993 | 996 | return temp; |
994 | 997 | } |
995 | 998 |
|
| 999 | +static unsigned long bcm2835_round_rate(unsigned long rate) |
| 1000 | +{ |
| 1001 | + unsigned long scaler; |
| 1002 | + unsigned long limit; |
| 1003 | + |
| 1004 | + limit = rate / 100000; |
| 1005 | + |
| 1006 | + scaler = 1; |
| 1007 | + while (scaler < limit) |
| 1008 | + scaler *= 10; |
| 1009 | + |
| 1010 | + /* |
| 1011 | + * If increasing a clock by less than 0.1% changes it |
| 1012 | + * from ..999.. to ..000.., round up. |
| 1013 | + */ |
| 1014 | + if ((rate + scaler - 1) / scaler % 1000 == 0) |
| 1015 | + rate = roundup(rate, scaler); |
| 1016 | + |
| 1017 | + return rate; |
| 1018 | +} |
| 1019 | + |
996 | 1020 | static unsigned long bcm2835_clock_get_rate(struct clk_hw *hw, |
997 | 1021 | unsigned long parent_rate) |
998 | 1022 | { |
999 | 1023 | struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw); |
1000 | 1024 | struct bcm2835_cprman *cprman = clock->cprman; |
1001 | 1025 | const struct bcm2835_clock_data *data = clock->data; |
| 1026 | + unsigned long rate; |
1002 | 1027 | u32 div; |
1003 | 1028 |
|
1004 | 1029 | if (data->int_bits == 0 && data->frac_bits == 0) |
1005 | 1030 | return parent_rate; |
1006 | 1031 |
|
1007 | 1032 | div = cprman_read(cprman, data->div_reg); |
1008 | 1033 |
|
1009 | | - return bcm2835_clock_rate_from_divisor(clock, parent_rate, div); |
| 1034 | + rate = bcm2835_clock_rate_from_divisor(clock, parent_rate, div); |
| 1035 | + |
| 1036 | + if (data->round_up) |
| 1037 | + rate = bcm2835_round_rate(rate); |
| 1038 | + |
| 1039 | + return rate; |
1010 | 1040 | } |
1011 | 1041 |
|
1012 | 1042 | static void bcm2835_clock_wait_busy(struct bcm2835_clock *clock) |
@@ -2143,7 +2173,8 @@ static const struct bcm2835_clk_desc clk_desc_array[] = { |
2143 | 2173 | .div_reg = CM_UARTDIV, |
2144 | 2174 | .int_bits = 10, |
2145 | 2175 | .frac_bits = 12, |
2146 | | - .tcnt_mux = 28), |
| 2176 | + .tcnt_mux = 28, |
| 2177 | + .round_up = true), |
2147 | 2178 |
|
2148 | 2179 | /* TV encoder clock. Only operating frequency is 108Mhz. */ |
2149 | 2180 | [BCM2835_CLOCK_VEC] = REGISTER_PER_CLK( |
|
0 commit comments