|
16 | 16 | #include <linux/pm_runtime.h>
|
17 | 17 | #include <linux/soc/qcom/geni-se.h>
|
18 | 18 | #include <linux/spinlock.h>
|
| 19 | +#include <linux/units.h> |
19 | 20 |
|
20 | 21 | #define SE_I2C_TX_TRANS_LEN 0x26c
|
21 | 22 | #define SE_I2C_RX_TRANS_LEN 0x270
|
@@ -146,22 +147,36 @@ struct geni_i2c_clk_fld {
|
146 | 147 | * clk_freq_out = t / t_cycle
|
147 | 148 | * source_clock = 19.2 MHz
|
148 | 149 | */
|
149 |
| -static const struct geni_i2c_clk_fld geni_i2c_clk_map[] = { |
| 150 | +static const struct geni_i2c_clk_fld geni_i2c_clk_map_19p2mhz[] = { |
150 | 151 | {KHZ(100), 7, 10, 11, 26},
|
151 | 152 | {KHZ(400), 2, 5, 12, 24},
|
152 | 153 | {KHZ(1000), 1, 3, 9, 18},
|
| 154 | + {}, |
| 155 | +}; |
| 156 | + |
| 157 | +/* source_clock = 32 MHz */ |
| 158 | +static const struct geni_i2c_clk_fld geni_i2c_clk_map_32mhz[] = { |
| 159 | + {KHZ(100), 8, 14, 18, 40}, |
| 160 | + {KHZ(400), 4, 3, 11, 20}, |
| 161 | + {KHZ(1000), 2, 3, 6, 15}, |
| 162 | + {}, |
153 | 163 | };
|
154 | 164 |
|
155 | 165 | static int geni_i2c_clk_map_idx(struct geni_i2c_dev *gi2c)
|
156 | 166 | {
|
157 |
| - int i; |
158 |
| - const struct geni_i2c_clk_fld *itr = geni_i2c_clk_map; |
| 167 | + const struct geni_i2c_clk_fld *itr; |
| 168 | + |
| 169 | + if (clk_get_rate(gi2c->se.clk) == 32 * HZ_PER_MHZ) |
| 170 | + itr = geni_i2c_clk_map_32mhz; |
| 171 | + else |
| 172 | + itr = geni_i2c_clk_map_19p2mhz; |
159 | 173 |
|
160 |
| - for (i = 0; i < ARRAY_SIZE(geni_i2c_clk_map); i++, itr++) { |
| 174 | + while (itr->clk_freq_out != 0) { |
161 | 175 | if (itr->clk_freq_out == gi2c->clk_freq_out) {
|
162 | 176 | gi2c->clk_fld = itr;
|
163 | 177 | return 0;
|
164 | 178 | }
|
| 179 | + itr++; |
165 | 180 | }
|
166 | 181 | return -EINVAL;
|
167 | 182 | }
|
|
0 commit comments