18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef PINCTRL_PINCTRL_ABx500_H 38c2ecf20Sopenharmony_ci#define PINCTRL_PINCTRL_ABx500_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci/* Package definitions */ 68c2ecf20Sopenharmony_ci#define PINCTRL_AB8500 0 78c2ecf20Sopenharmony_ci#define PINCTRL_AB8505 1 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci/* pins alternate function */ 108c2ecf20Sopenharmony_cienum abx500_pin_func { 118c2ecf20Sopenharmony_ci ABX500_DEFAULT, 128c2ecf20Sopenharmony_ci ABX500_ALT_A, 138c2ecf20Sopenharmony_ci ABX500_ALT_B, 148c2ecf20Sopenharmony_ci ABX500_ALT_C, 158c2ecf20Sopenharmony_ci}; 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_cienum abx500_gpio_pull_updown { 188c2ecf20Sopenharmony_ci ABX500_GPIO_PULL_DOWN = 0x0, 198c2ecf20Sopenharmony_ci ABX500_GPIO_PULL_NONE = 0x1, 208c2ecf20Sopenharmony_ci ABX500_GPIO_PULL_UP = 0x3, 218c2ecf20Sopenharmony_ci}; 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cienum abx500_gpio_vinsel { 248c2ecf20Sopenharmony_ci ABX500_GPIO_VINSEL_VBAT = 0x0, 258c2ecf20Sopenharmony_ci ABX500_GPIO_VINSEL_VIN_1V8 = 0x1, 268c2ecf20Sopenharmony_ci ABX500_GPIO_VINSEL_VDD_BIF = 0x2, 278c2ecf20Sopenharmony_ci}; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci/** 308c2ecf20Sopenharmony_ci * struct abx500_function - ABx500 pinctrl mux function 318c2ecf20Sopenharmony_ci * @name: The name of the function, exported to pinctrl core. 328c2ecf20Sopenharmony_ci * @groups: An array of pin groups that may select this function. 338c2ecf20Sopenharmony_ci * @ngroups: The number of entries in @groups. 348c2ecf20Sopenharmony_ci */ 358c2ecf20Sopenharmony_cistruct abx500_function { 368c2ecf20Sopenharmony_ci const char *name; 378c2ecf20Sopenharmony_ci const char * const *groups; 388c2ecf20Sopenharmony_ci unsigned ngroups; 398c2ecf20Sopenharmony_ci}; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/** 428c2ecf20Sopenharmony_ci * struct abx500_pingroup - describes a ABx500 pin group 438c2ecf20Sopenharmony_ci * @name: the name of this specific pin group 448c2ecf20Sopenharmony_ci * @pins: an array of discrete physical pins used in this group, taken 458c2ecf20Sopenharmony_ci * from the driver-local pin enumeration space 468c2ecf20Sopenharmony_ci * @num_pins: the number of pins in this group array, i.e. the number of 478c2ecf20Sopenharmony_ci * elements in .pins so we can iterate over that array 488c2ecf20Sopenharmony_ci * @altsetting: the altsetting to apply to all pins in this group to 498c2ecf20Sopenharmony_ci * configure them to be used by a function 508c2ecf20Sopenharmony_ci */ 518c2ecf20Sopenharmony_cistruct abx500_pingroup { 528c2ecf20Sopenharmony_ci const char *name; 538c2ecf20Sopenharmony_ci const unsigned int *pins; 548c2ecf20Sopenharmony_ci const unsigned npins; 558c2ecf20Sopenharmony_ci int altsetting; 568c2ecf20Sopenharmony_ci}; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci#define ALTERNATE_FUNCTIONS(pin, sel_bit, alt1, alt2, alta, altb, altc) \ 598c2ecf20Sopenharmony_ci{ \ 608c2ecf20Sopenharmony_ci .pin_number = pin, \ 618c2ecf20Sopenharmony_ci .gpiosel_bit = sel_bit, \ 628c2ecf20Sopenharmony_ci .alt_bit1 = alt1, \ 638c2ecf20Sopenharmony_ci .alt_bit2 = alt2, \ 648c2ecf20Sopenharmony_ci .alta_val = alta, \ 658c2ecf20Sopenharmony_ci .altb_val = altb, \ 668c2ecf20Sopenharmony_ci .altc_val = altc, \ 678c2ecf20Sopenharmony_ci} 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci#define UNUSED -1 708c2ecf20Sopenharmony_ci/** 718c2ecf20Sopenharmony_ci * struct alternate_functions 728c2ecf20Sopenharmony_ci * @pin_number: The pin number 738c2ecf20Sopenharmony_ci * @gpiosel_bit: Control bit in GPIOSEL register, 748c2ecf20Sopenharmony_ci * @alt_bit1: First AlternateFunction bit used to select the 758c2ecf20Sopenharmony_ci * alternate function 768c2ecf20Sopenharmony_ci * @alt_bit2: Second AlternateFunction bit used to select the 778c2ecf20Sopenharmony_ci * alternate function 788c2ecf20Sopenharmony_ci * 798c2ecf20Sopenharmony_ci * these 3 following fields are necessary due to none 808c2ecf20Sopenharmony_ci * coherency on how to select the altA, altB and altC 818c2ecf20Sopenharmony_ci * function between the ABx500 SOC family when using 828c2ecf20Sopenharmony_ci * alternatfunc register. 838c2ecf20Sopenharmony_ci * @alta_val: value to write in alternatfunc to select altA function 848c2ecf20Sopenharmony_ci * @altb_val: value to write in alternatfunc to select altB function 858c2ecf20Sopenharmony_ci * @altc_val: value to write in alternatfunc to select altC function 868c2ecf20Sopenharmony_ci */ 878c2ecf20Sopenharmony_cistruct alternate_functions { 888c2ecf20Sopenharmony_ci unsigned pin_number; 898c2ecf20Sopenharmony_ci s8 gpiosel_bit; 908c2ecf20Sopenharmony_ci s8 alt_bit1; 918c2ecf20Sopenharmony_ci s8 alt_bit2; 928c2ecf20Sopenharmony_ci u8 alta_val; 938c2ecf20Sopenharmony_ci u8 altb_val; 948c2ecf20Sopenharmony_ci u8 altc_val; 958c2ecf20Sopenharmony_ci}; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci#define GPIO_IRQ_CLUSTER(a, b, c) \ 988c2ecf20Sopenharmony_ci{ \ 998c2ecf20Sopenharmony_ci .start = a, \ 1008c2ecf20Sopenharmony_ci .end = b, \ 1018c2ecf20Sopenharmony_ci .to_irq = c, \ 1028c2ecf20Sopenharmony_ci} 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci/** 1058c2ecf20Sopenharmony_ci * struct abx500_gpio_irq_cluster - indicates GPIOs which are interrupt 1068c2ecf20Sopenharmony_ci * capable 1078c2ecf20Sopenharmony_ci * @start: The pin number of the first pin interrupt capable 1088c2ecf20Sopenharmony_ci * @end: The pin number of the last pin interrupt capable 1098c2ecf20Sopenharmony_ci * @to_irq: The ABx500 GPIO's associated IRQs are clustered 1108c2ecf20Sopenharmony_ci * together throughout the interrupt numbers at irregular 1118c2ecf20Sopenharmony_ci * intervals. To solve this quandary, we will place the 1128c2ecf20Sopenharmony_ci * read-in values into the cluster information table 1138c2ecf20Sopenharmony_ci */ 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cistruct abx500_gpio_irq_cluster { 1168c2ecf20Sopenharmony_ci int start; 1178c2ecf20Sopenharmony_ci int end; 1188c2ecf20Sopenharmony_ci int to_irq; 1198c2ecf20Sopenharmony_ci}; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci/** 1228c2ecf20Sopenharmony_ci * struct abx500_pinrange - map pin numbers to GPIO offsets 1238c2ecf20Sopenharmony_ci * @offset: offset into the GPIO local numberspace, incidentally 1248c2ecf20Sopenharmony_ci * identical to the offset into the local pin numberspace 1258c2ecf20Sopenharmony_ci * @npins: number of pins to map from both offsets 1268c2ecf20Sopenharmony_ci * @altfunc: altfunc setting to be used to enable GPIO on a pin in 1278c2ecf20Sopenharmony_ci * this range (may vary) 1288c2ecf20Sopenharmony_ci */ 1298c2ecf20Sopenharmony_cistruct abx500_pinrange { 1308c2ecf20Sopenharmony_ci unsigned int offset; 1318c2ecf20Sopenharmony_ci unsigned int npins; 1328c2ecf20Sopenharmony_ci int altfunc; 1338c2ecf20Sopenharmony_ci}; 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci#define ABX500_PINRANGE(a, b, c) { .offset = a, .npins = b, .altfunc = c } 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci/** 1388c2ecf20Sopenharmony_ci * struct abx500_pinctrl_soc_data - ABx500 pin controller per-SoC configuration 1398c2ecf20Sopenharmony_ci * @gpio_ranges: An array of GPIO ranges for this SoC 1408c2ecf20Sopenharmony_ci * @gpio_num_ranges: The number of GPIO ranges for this SoC 1418c2ecf20Sopenharmony_ci * @pins: An array describing all pins the pin controller affects. 1428c2ecf20Sopenharmony_ci * All pins which are also GPIOs must be listed first within the 1438c2ecf20Sopenharmony_ci * array, and be numbered identically to the GPIO controller's 1448c2ecf20Sopenharmony_ci * numbering. 1458c2ecf20Sopenharmony_ci * @npins: The number of entries in @pins. 1468c2ecf20Sopenharmony_ci * @functions: The functions supported on this SoC. 1478c2ecf20Sopenharmony_ci * @nfunction: The number of entries in @functions. 1488c2ecf20Sopenharmony_ci * @groups: An array describing all pin groups the pin SoC supports. 1498c2ecf20Sopenharmony_ci * @ngroups: The number of entries in @groups. 1508c2ecf20Sopenharmony_ci * @alternate_functions: array describing pins which supports alternate and 1518c2ecf20Sopenharmony_ci * how to set it. 1528c2ecf20Sopenharmony_ci * @gpio_irq_cluster: An array of GPIO interrupt capable for this SoC 1538c2ecf20Sopenharmony_ci * @ngpio_irq_cluster: The number of GPIO inetrrupt capable for this SoC 1548c2ecf20Sopenharmony_ci * @irq_gpio_rising_offset: Interrupt offset used as base to compute specific 1558c2ecf20Sopenharmony_ci * setting strategy of the rising interrupt line 1568c2ecf20Sopenharmony_ci * @irq_gpio_falling_offset: Interrupt offset used as base to compute specific 1578c2ecf20Sopenharmony_ci * setting strategy of the falling interrupt line 1588c2ecf20Sopenharmony_ci * @irq_gpio_factor: Factor used to compute specific setting strategy of 1598c2ecf20Sopenharmony_ci * the interrupt line 1608c2ecf20Sopenharmony_ci */ 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_cistruct abx500_pinctrl_soc_data { 1638c2ecf20Sopenharmony_ci const struct abx500_pinrange *gpio_ranges; 1648c2ecf20Sopenharmony_ci unsigned gpio_num_ranges; 1658c2ecf20Sopenharmony_ci const struct pinctrl_pin_desc *pins; 1668c2ecf20Sopenharmony_ci unsigned npins; 1678c2ecf20Sopenharmony_ci const struct abx500_function *functions; 1688c2ecf20Sopenharmony_ci unsigned nfunctions; 1698c2ecf20Sopenharmony_ci const struct abx500_pingroup *groups; 1708c2ecf20Sopenharmony_ci unsigned ngroups; 1718c2ecf20Sopenharmony_ci struct alternate_functions *alternate_functions; 1728c2ecf20Sopenharmony_ci struct abx500_gpio_irq_cluster *gpio_irq_cluster; 1738c2ecf20Sopenharmony_ci unsigned ngpio_irq_cluster; 1748c2ecf20Sopenharmony_ci int irq_gpio_rising_offset; 1758c2ecf20Sopenharmony_ci int irq_gpio_falling_offset; 1768c2ecf20Sopenharmony_ci int irq_gpio_factor; 1778c2ecf20Sopenharmony_ci}; 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci#ifdef CONFIG_PINCTRL_AB8500 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_civoid abx500_pinctrl_ab8500_init(struct abx500_pinctrl_soc_data **soc); 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci#else 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_cistatic inline void 1868c2ecf20Sopenharmony_ciabx500_pinctrl_ab8500_init(struct abx500_pinctrl_soc_data **soc) 1878c2ecf20Sopenharmony_ci{ 1888c2ecf20Sopenharmony_ci} 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci#endif 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci#ifdef CONFIG_PINCTRL_AB8505 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_civoid abx500_pinctrl_ab8505_init(struct abx500_pinctrl_soc_data **soc); 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci#else 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_cistatic inline void 1998c2ecf20Sopenharmony_ciabx500_pinctrl_ab8505_init(struct abx500_pinctrl_soc_data **soc) 2008c2ecf20Sopenharmony_ci{ 2018c2ecf20Sopenharmony_ci} 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci#endif 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci#endif /* PINCTRL_PINCTRL_ABx500_H */ 206