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

pinctrl: sh-pfc: Add helper to handle bias lookup table

On some SoC there are no simple mapping of pins to bias register bits
and a lookup table is needed. This logic is already implemented in some
SoC specific drivers that could benefit from a generic implementation.

Add helpers to deal with the lookup which later can be used by the SoC
specific drivers. The logic used to lookup are different from the one it
aims to replace, this is intentional. This new method reduces the memory
consumption at the cost of increased CPU usage and fix a bug where a
WARN() would incorrectly be triggered if the register offset is 0.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

authored by

Niklas Söderlund and committed by
Geert Uytterhoeven
c314c9f1 5d7400c4

+25
+15
drivers/pinctrl/sh-pfc/core.c
··· 389 389 return 0; 390 390 } 391 391 392 + const struct sh_pfc_bias_info * 393 + sh_pfc_pin_to_bias_info(const struct sh_pfc_bias_info *info, 394 + unsigned int num, unsigned int pin) 395 + { 396 + unsigned int i; 397 + 398 + for (i = 0; i < num; i++) 399 + if (info[i].pin == pin) 400 + return &info[i]; 401 + 402 + WARN_ONCE(1, "Pin %u is not in bias info list\n", pin); 403 + 404 + return NULL; 405 + } 406 + 392 407 static int sh_pfc_init_ranges(struct sh_pfc *pfc) 393 408 { 394 409 struct sh_pfc_pin_range *range;
+4
drivers/pinctrl/sh-pfc/core.h
··· 33 33 int sh_pfc_get_pin_index(struct sh_pfc *pfc, unsigned int pin); 34 34 int sh_pfc_config_mux(struct sh_pfc *pfc, unsigned mark, int pinmux_type); 35 35 36 + const struct sh_pfc_bias_info * 37 + sh_pfc_pin_to_bias_info(const struct sh_pfc_bias_info *info, 38 + unsigned int num, unsigned int pin); 39 + 36 40 #endif /* __SH_PFC_CORE_H__ */
+6
drivers/pinctrl/sh-pfc/sh_pfc.h
··· 189 189 unsigned long size; 190 190 }; 191 191 192 + struct sh_pfc_bias_info { 193 + u16 pin; 194 + u16 reg : 11; 195 + u16 bit : 5; 196 + }; 197 + 192 198 struct sh_pfc_pin_range; 193 199 194 200 struct sh_pfc {