Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

memory: ti-aemif: Create aemif_check_cs_timings()

aemif_calc_rate() checks the validity of a new computed timing against a
'max' value given as input. This isn't convenient if we want to check
the CS timing configuration somewhere else in the code.

Wrap the verification of all the chip select's timing configuration into a
single function to ease its exportation in upcoming patches.
Remove the validity check from aemif_calc_rate(). Also remove the no
longer used 'max' input and change the return type to u32.
Remove the check of the aemif_calc_rate()'s return value during
device-tree parsing as aemif_calc_rate() can't fail anymore.

Signed-off-by: Bastien Curutchet <bastien.curutchet@bootlin.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/r/20241204094319.1050826-5-bastien.curutchet@bootlin.com
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

authored by

Bastien Curutchet and committed by
Krzysztof Kozlowski
2c7b585d 30b4da67

+51 -60
+51 -60
drivers/memory/ti-aemif.c
··· 134 134 }; 135 135 136 136 /** 137 + * aemif_check_cs_timings() - Check the validity of a CS timing configuration. 138 + * @timings: timings configuration 139 + * 140 + * @return: 0 if the timing configuration is valid, negative error number otherwise. 141 + */ 142 + static int aemif_check_cs_timings(struct aemif_cs_timings *timings) 143 + { 144 + if (timings->ta > TA_MAX) 145 + return -EINVAL; 146 + 147 + if (timings->rhold > RHOLD_MAX) 148 + return -EINVAL; 149 + 150 + if (timings->rstrobe > RSTROBE_MAX) 151 + return -EINVAL; 152 + 153 + if (timings->rsetup > RSETUP_MAX) 154 + return -EINVAL; 155 + 156 + if (timings->whold > WHOLD_MAX) 157 + return -EINVAL; 158 + 159 + if (timings->wstrobe > WSTROBE_MAX) 160 + return -EINVAL; 161 + 162 + if (timings->wsetup > WSETUP_MAX) 163 + return -EINVAL; 164 + 165 + return 0; 166 + } 167 + 168 + /** 137 169 * aemif_calc_rate - calculate timing data. 138 170 * @pdev: platform device to calculate for 139 171 * @wanted: The cycle time needed in nanoseconds. 140 172 * @clk: The input clock rate in kHz. 141 - * @max: The maximum divider value that can be programmed. 142 173 * 143 - * On success, returns the calculated timing value minus 1 for easy 144 - * programming into AEMIF timing registers, else negative errno. 174 + * @return: the calculated timing value minus 1 for easy 175 + * programming into AEMIF timing registers. 145 176 */ 146 - static int aemif_calc_rate(struct platform_device *pdev, int wanted, 147 - unsigned long clk, int max) 177 + static u32 aemif_calc_rate(struct platform_device *pdev, int wanted, unsigned long clk) 148 178 { 149 179 int result; 150 180 ··· 186 156 /* It is generally OK to have a more relaxed timing than requested... */ 187 157 if (result < 0) 188 158 result = 0; 189 - 190 - /* ... But configuring tighter timings is not an option. */ 191 - else if (result > max) 192 - result = -EINVAL; 193 159 194 160 return result; 195 161 } ··· 276 250 struct aemif_device *aemif = platform_get_drvdata(pdev); 277 251 unsigned long clk_rate = aemif->clk_rate; 278 252 struct aemif_cs_data *data; 279 - int ret; 280 253 u32 cs; 281 254 u32 val; 282 255 ··· 301 276 aemif_get_hw_params(pdev, aemif->num_cs++); 302 277 303 278 /* override the values from device node */ 304 - if (!of_property_read_u32(np, "ti,cs-min-turnaround-ns", &val)) { 305 - ret = aemif_calc_rate(pdev, val, clk_rate, TA_MAX); 306 - if (ret < 0) 307 - return ret; 279 + if (!of_property_read_u32(np, "ti,cs-min-turnaround-ns", &val)) 280 + data->timings.ta = aemif_calc_rate(pdev, val, clk_rate); 308 281 309 - data->timings.ta = ret; 310 - } 282 + if (!of_property_read_u32(np, "ti,cs-read-hold-ns", &val)) 283 + data->timings.rhold = aemif_calc_rate(pdev, val, clk_rate); 311 284 312 - if (!of_property_read_u32(np, "ti,cs-read-hold-ns", &val)) { 313 - ret = aemif_calc_rate(pdev, val, clk_rate, RHOLD_MAX); 314 - if (ret < 0) 315 - return ret; 285 + if (!of_property_read_u32(np, "ti,cs-read-strobe-ns", &val)) 286 + data->timings.rstrobe = aemif_calc_rate(pdev, val, clk_rate); 316 287 317 - data->timings.rhold = ret; 318 - } 288 + if (!of_property_read_u32(np, "ti,cs-read-setup-ns", &val)) 289 + data->timings.rsetup = aemif_calc_rate(pdev, val, clk_rate); 319 290 320 - if (!of_property_read_u32(np, "ti,cs-read-strobe-ns", &val)) { 321 - ret = aemif_calc_rate(pdev, val, clk_rate, RSTROBE_MAX); 322 - if (ret < 0) 323 - return ret; 291 + if (!of_property_read_u32(np, "ti,cs-write-hold-ns", &val)) 292 + data->timings.whold = aemif_calc_rate(pdev, val, clk_rate); 324 293 325 - data->timings.rstrobe = ret; 326 - } 294 + if (!of_property_read_u32(np, "ti,cs-write-strobe-ns", &val)) 295 + data->timings.wstrobe = aemif_calc_rate(pdev, val, clk_rate); 327 296 328 - if (!of_property_read_u32(np, "ti,cs-read-setup-ns", &val)) { 329 - ret = aemif_calc_rate(pdev, val, clk_rate, RSETUP_MAX); 330 - if (ret < 0) 331 - return ret; 332 - 333 - data->timings.rsetup = ret; 334 - } 335 - 336 - if (!of_property_read_u32(np, "ti,cs-write-hold-ns", &val)) { 337 - ret = aemif_calc_rate(pdev, val, clk_rate, WHOLD_MAX); 338 - if (ret < 0) 339 - return ret; 340 - 341 - data->timings.whold = ret; 342 - } 343 - 344 - if (!of_property_read_u32(np, "ti,cs-write-strobe-ns", &val)) { 345 - ret = aemif_calc_rate(pdev, val, clk_rate, WSTROBE_MAX); 346 - if (ret < 0) 347 - return ret; 348 - 349 - data->timings.wstrobe = ret; 350 - } 351 - 352 - if (!of_property_read_u32(np, "ti,cs-write-setup-ns", &val)) { 353 - ret = aemif_calc_rate(pdev, val, clk_rate, WSETUP_MAX); 354 - if (ret < 0) 355 - return ret; 356 - 357 - data->timings.wsetup = ret; 358 - } 297 + if (!of_property_read_u32(np, "ti,cs-write-setup-ns", &val)) 298 + data->timings.wsetup = aemif_calc_rate(pdev, val, clk_rate); 359 299 360 300 if (!of_property_read_u32(np, "ti,cs-bus-width", &val)) 361 301 if (val == 16) 362 302 data->asize = 1; 363 303 data->enable_ew = of_property_read_bool(np, "ti,cs-extended-wait-mode"); 364 304 data->enable_ss = of_property_read_bool(np, "ti,cs-select-strobe-mode"); 365 - return 0; 305 + 306 + return aemif_check_cs_timings(&data->timings); 366 307 } 367 308 368 309 static const struct of_device_id aemif_of_match[] = {