Lines Matching +full:8 +full:- +full:pin
18 #include <linux/pinctrl/pinconf-generic.h>
24 #include "pinctrl-utils.h"
32 /* LPC18XX SCU pin register definitions */
40 #define LPC18XX_SCU_PIN_EHD_POS 8
50 #define LPC18XX_SCU_I2C0_SDA_SHIFT 8
52 #define LPC18XX_SCU_FUNC_PER_PIN 8
54 /* LPC18XX SCU pin interrupt select registers */
61 #define LPC18XX_GPIO_PIN_INT_MAX 8
64 ((val) << (((n) % LPC18XX_SCU_IRQ_PER_PINTSEL) * 8))
66 /* LPC18xx pin types */
68 TYPE_ND, /* Normal-drive */
69 TYPE_HD, /* High-drive */
70 TYPE_HS, /* High-speed */
75 /* LPC18xx pin functions */
213 #define LPC_P(port, pin, f0, f1, f2, f3, f4, f5, f6, f7, a, t) \ argument
214 static struct lpc18xx_pin_caps lpc18xx_pin_p##port##_##pin = { \
215 .offset = 0x##port * 32 * 4 + pin * 4, \
239 /* Pin FUNC0 FUNC1 FUNC2 FUNC3 FUNC4 FUNC5 FUNC6 FUNC7 ANALOG TYPE */
250 LPC_P(1,8, GPIO, UART1, CTOUT, EMC, R, R, R, SDMMC, 0, ND);
271 LPC_P(2,8, SGPIO, CTOUT, UART3, EMC, GPIO, R, R, R, 0, ND);
285 LPC_P(3,8, R, SPI, SSP0, SPIFI, GPIO, SSP0_ALT, R, R, 0, ND);
294 LPC_P(4,8, R, CTIN, LCD, R, GPIO, LCD_ALT, CAN1, SGPIO, 0, ND);
313 LPC_P(6,8, R, EMC, SGPIO, USB0, GPIO, TIMER2, R, R, 0, ND);
326 LPC_P(8,0, GPIO, USB0, R, MCTRL, SGPIO, R, R, TIMER0, 0, HD);
327 LPC_P(8,1, GPIO, USB0, R, MCTRL, SGPIO, R, R, TIMER0, 0, HD);
328 LPC_P(8,2, GPIO, USB0, R, MCTRL, SGPIO, R, R, TIMER0, 0, HD);
329 LPC_P(8,3, GPIO, USB1, R, LCD, LCD_ALT, R, R, TIMER0, 0, ND);
330 LPC_P(8,4, GPIO, USB1, R, LCD, LCD_ALT, R, R, TIMER0, 0, ND);
331 LPC_P(8,5, GPIO, USB1, R, LCD, LCD_ALT, R, R, TIMER0, 0, ND);
332 LPC_P(8,6, GPIO, USB1, R, LCD, LCD_ALT, R, R, TIMER0, 0, ND);
333 LPC_P(8,7, GPIO, USB1, R, LCD, LCD_ALT, R, R, TIMER0, 0, ND);
334 LPC_P(8,8, R, USB1, R, R, R, R,CGU_OUT, I2S1, 0, ND);
362 LPC_P(c,8, R, USB1, R, ENET, GPIO, R, TIMER3, SDMMC, 0, ND);
377 LPC_P(d,8, R, CTIN, EMC, R, GPIO, R, R, SGPIO, 0, ND);
394 LPC_P(e,8, R, CTOUT, UART1, EMC, GPIO, R, R, R, 0, ND);
410 LPC_P(f,8, R, UART0, CTIN, TRACE, GPIO, R, SGPIO, R, ADC0|2, ND);
415 /* Pin Offset FUNC0 FUNC1 FUNC2 FUNC3 FUNC4 FUNC5 FUNC6 FUNC7 ANALOG TYPE */
425 #define LPC18XX_PIN_P(port, pin) { \ argument
426 .number = 0x##port * 32 + pin, \
427 .name = "p"#port"_"#pin, \
428 .drv_data = &lpc18xx_pin_p##port##_##pin \
431 /* Pin numbers for special pins */
460 LPC18XX_PIN_P(1,8),
481 LPC18XX_PIN_P(2,8),
495 LPC18XX_PIN_P(3,8),
504 LPC18XX_PIN_P(4,8),
523 LPC18XX_PIN_P(6,8),
536 LPC18XX_PIN_P(8,0),
537 LPC18XX_PIN_P(8,1),
538 LPC18XX_PIN_P(8,2),
539 LPC18XX_PIN_P(8,3),
540 LPC18XX_PIN_P(8,4),
541 LPC18XX_PIN_P(8,5),
542 LPC18XX_PIN_P(8,6),
543 LPC18XX_PIN_P(8,7),
544 LPC18XX_PIN_P(8,8),
572 LPC18XX_PIN_P(c,8),
587 LPC18XX_PIN_P(d,8),
604 LPC18XX_PIN_P(e,8),
620 LPC18XX_PIN_P(f,8),
635 /* PIN_CONFIG_GPIO_PIN_INT: route gpio to the gpio pin interrupt controller */
639 {"nxp,gpio-pin-interrupt", PIN_CONFIG_GPIO_PIN_INT, 0},
644 PCONFDUMP(PIN_CONFIG_GPIO_PIN_INT, "gpio pin int", NULL, true),
660 return -EINVAL; in lpc18xx_pconf_get_usb1()
667 return -EINVAL; in lpc18xx_pconf_get_usb1()
671 return -ENOTSUPP; in lpc18xx_pconf_get_usb1()
678 unsigned pin) in lpc18xx_pconf_get_i2c0() argument
682 if (pin == PIN_I2C0_SCL) in lpc18xx_pconf_get_i2c0()
692 return -EINVAL; in lpc18xx_pconf_get_i2c0()
711 return -EINVAL; in lpc18xx_pconf_get_i2c0()
717 return -ENOTSUPP; in lpc18xx_pconf_get_i2c0()
723 static int lpc18xx_pin_to_gpio(struct pinctrl_dev *pctldev, unsigned pin) in lpc18xx_pin_to_gpio() argument
727 range = pinctrl_find_gpio_range_from_pin_nolock(pctldev, pin); in lpc18xx_pin_to_gpio()
729 return -EINVAL; in lpc18xx_pin_to_gpio()
731 return pin - range->pin_base + range->base; in lpc18xx_pin_to_gpio()
748 return -EINVAL; in lpc18xx_get_pintsel()
762 int *arg, unsigned pin) in lpc18xx_pconf_get_gpio_pin_int() argument
768 gpio = lpc18xx_pin_to_gpio(pctldev, pin); in lpc18xx_pconf_get_gpio_pin_int()
770 return -ENOTSUPP; in lpc18xx_pconf_get_gpio_pin_int()
775 * Check if this pin has been enabled as a interrupt in any of the two in lpc18xx_pconf_get_gpio_pin_int()
776 * PINTSEL registers. *arg indicates which interrupt number (0-7). in lpc18xx_pconf_get_gpio_pin_int()
779 ret = lpc18xx_get_pintsel(scu->base + LPC18XX_SCU_PINTSEL0, val, arg); in lpc18xx_pconf_get_gpio_pin_int()
783 return lpc18xx_get_pintsel(scu->base + LPC18XX_SCU_PINTSEL1, val, arg); in lpc18xx_pconf_get_gpio_pin_int()
787 int *arg, u32 reg, unsigned pin, in lpc18xx_pconf_get_pin() argument
795 return -EINVAL; in lpc18xx_pconf_get_pin()
800 return -EINVAL; in lpc18xx_pconf_get_pin()
809 return -EINVAL; in lpc18xx_pconf_get_pin()
816 return -EINVAL; in lpc18xx_pconf_get_pin()
820 if (pin_cap->type == TYPE_HD) in lpc18xx_pconf_get_pin()
821 return -ENOTSUPP; in lpc18xx_pconf_get_pin()
831 return -EINVAL; in lpc18xx_pconf_get_pin()
837 if (pin_cap->type != TYPE_HD) in lpc18xx_pconf_get_pin()
838 return -ENOTSUPP; in lpc18xx_pconf_get_pin()
853 return lpc18xx_pconf_get_gpio_pin_int(pctldev, arg, pin); in lpc18xx_pconf_get_pin()
856 return -ENOTSUPP; in lpc18xx_pconf_get_pin()
862 static struct lpc18xx_pin_caps *lpc18xx_get_pin_caps(unsigned pin) in lpc18xx_get_pin_caps() argument
867 if (lpc18xx_pins[i].number == pin) in lpc18xx_get_pin_caps()
874 static int lpc18xx_pconf_get(struct pinctrl_dev *pctldev, unsigned pin, in lpc18xx_pconf_get() argument
883 pin_cap = lpc18xx_get_pin_caps(pin); in lpc18xx_pconf_get()
885 return -EINVAL; in lpc18xx_pconf_get()
887 reg = readl(scu->base + pin_cap->offset); in lpc18xx_pconf_get()
889 if (pin_cap->type == TYPE_I2C0) in lpc18xx_pconf_get()
890 ret = lpc18xx_pconf_get_i2c0(param, &arg, reg, pin); in lpc18xx_pconf_get()
891 else if (pin_cap->type == TYPE_USB1) in lpc18xx_pconf_get()
894 ret = lpc18xx_pconf_get_pin(pctldev, param, &arg, reg, pin, pin_cap); in lpc18xx_pconf_get()
925 dev_err(pctldev->dev, "Property not supported\n"); in lpc18xx_pconf_set_usb1()
926 return -ENOTSUPP; in lpc18xx_pconf_set_usb1()
935 unsigned pin) in lpc18xx_pconf_set_i2c0() argument
939 if (pin == PIN_I2C0_SCL) in lpc18xx_pconf_set_i2c0()
965 return -ENOTSUPP; in lpc18xx_pconf_set_i2c0()
976 dev_err(pctldev->dev, "Property not supported\n"); in lpc18xx_pconf_set_i2c0()
977 return -ENOTSUPP; in lpc18xx_pconf_set_i2c0()
984 u32 param_val, unsigned pin) in lpc18xx_pconf_set_gpio_pin_int() argument
991 return -EINVAL; in lpc18xx_pconf_set_gpio_pin_int()
993 gpio = lpc18xx_pin_to_gpio(pctldev, pin); in lpc18xx_pconf_set_gpio_pin_int()
995 return -ENOTSUPP; in lpc18xx_pconf_set_gpio_pin_int()
1001 reg_val = readl(scu->base + reg_offset); in lpc18xx_pconf_set_gpio_pin_int()
1004 writel(reg_val, scu->base + reg_offset); in lpc18xx_pconf_set_gpio_pin_int()
1010 u32 param_val, u32 *reg, unsigned pin, in lpc18xx_pconf_set_pin() argument
1035 if (pin_cap->type == TYPE_HD) { in lpc18xx_pconf_set_pin()
1036 dev_err(pctldev->dev, "Slew rate unsupported on high-drive pins\n"); in lpc18xx_pconf_set_pin()
1037 return -ENOTSUPP; in lpc18xx_pconf_set_pin()
1054 if (pin_cap->type != TYPE_HD) { in lpc18xx_pconf_set_pin()
1055 dev_err(pctldev->dev, "Drive strength available only on high-drive pins\n"); in lpc18xx_pconf_set_pin()
1056 return -ENOTSUPP; in lpc18xx_pconf_set_pin()
1061 case 20: param_val -= 5; in lpc18xx_pconf_set_pin()
1063 case 14: param_val -= 5; in lpc18xx_pconf_set_pin()
1065 case 8: param_val -= 3; in lpc18xx_pconf_set_pin()
1067 case 4: param_val -= 4; in lpc18xx_pconf_set_pin()
1070 dev_err(pctldev->dev, "Drive strength %u unsupported\n", param_val); in lpc18xx_pconf_set_pin()
1071 return -ENOTSUPP; in lpc18xx_pconf_set_pin()
1077 return lpc18xx_pconf_set_gpio_pin_int(pctldev, param_val, pin); in lpc18xx_pconf_set_pin()
1080 dev_err(pctldev->dev, "Property not supported\n"); in lpc18xx_pconf_set_pin()
1081 return -ENOTSUPP; in lpc18xx_pconf_set_pin()
1087 static int lpc18xx_pconf_set(struct pinctrl_dev *pctldev, unsigned pin, in lpc18xx_pconf_set() argument
1098 pin_cap = lpc18xx_get_pin_caps(pin); in lpc18xx_pconf_set()
1100 return -EINVAL; in lpc18xx_pconf_set()
1102 reg = readl(scu->base + pin_cap->offset); in lpc18xx_pconf_set()
1108 if (pin_cap->type == TYPE_I2C0) in lpc18xx_pconf_set()
1109 ret = lpc18xx_pconf_set_i2c0(pctldev, param, param_val, ®, pin); in lpc18xx_pconf_set()
1110 else if (pin_cap->type == TYPE_USB1) in lpc18xx_pconf_set()
1113 ret = lpc18xx_pconf_set_pin(pctldev, param, param_val, ®, pin, pin_cap); in lpc18xx_pconf_set()
1119 writel(reg, scu->base + pin_cap->offset); in lpc18xx_pconf_set()
1148 *groups = scu->func[function].groups; in lpc18xx_pmx_get_func_groups()
1149 *num_groups = scu->func[function].ngroups; in lpc18xx_pmx_get_func_groups()
1158 struct lpc18xx_pin_caps *pin = lpc18xx_pins[group].drv_data; in lpc18xx_pmx_set() local
1163 if (pin->type == TYPE_USB1) { in lpc18xx_pmx_set()
1170 if (pin->type == TYPE_I2C0) { in lpc18xx_pmx_set()
1177 if (function == FUNC_ADC && (pin->analog & LPC18XX_ANALOG_PIN)) { in lpc18xx_pmx_set()
1180 writel(LPC18XX_SCU_ANALOG_PIN_CFG, scu->base + pin->offset); in lpc18xx_pmx_set()
1182 if (LPC18XX_ANALOG_ADC(pin->analog) == 0) in lpc18xx_pmx_set()
1187 reg = readl(scu->base + offset); in lpc18xx_pmx_set()
1188 reg |= pin->analog & LPC18XX_ANALOG_BIT_MASK; in lpc18xx_pmx_set()
1189 writel(reg, scu->base + offset); in lpc18xx_pmx_set()
1194 if (function == FUNC_DAC && (pin->analog & LPC18XX_ANALOG_PIN)) { in lpc18xx_pmx_set()
1195 writel(LPC18XX_SCU_ANALOG_PIN_CFG, scu->base + pin->offset); in lpc18xx_pmx_set()
1197 reg = readl(scu->base + LPC18XX_SCU_REG_ENAIO2); in lpc18xx_pmx_set()
1199 writel(reg, scu->base + LPC18XX_SCU_REG_ENAIO2); in lpc18xx_pmx_set()
1205 if (function == pin->functions[func]) in lpc18xx_pmx_set()
1212 reg = readl(scu->base + pin->offset); in lpc18xx_pmx_set()
1214 writel(reg | func, scu->base + pin->offset); in lpc18xx_pmx_set()
1218 dev_err(pctldev->dev, "Pin %s can't be %s\n", lpc18xx_pins[group].name, in lpc18xx_pmx_set()
1220 return -EINVAL; in lpc18xx_pmx_set()
1261 .name = "lpc18xx/43xx-scu",
1275 static bool lpc18xx_valid_pin_function(unsigned pin, unsigned function) in lpc18xx_valid_pin_function() argument
1277 struct lpc18xx_pin_caps *p = lpc18xx_pins[pin].drv_data; in lpc18xx_valid_pin_function()
1280 if (function == FUNC_DAC && p->analog == DAC) in lpc18xx_valid_pin_function()
1283 if (function == FUNC_ADC && p->analog) in lpc18xx_valid_pin_function()
1286 if (function == FUNC_I2C0 && p->type == TYPE_I2C0) in lpc18xx_valid_pin_function()
1289 if (function == FUNC_USB1 && p->type == TYPE_USB1) in lpc18xx_valid_pin_function()
1293 if (function == p->functions[i]) in lpc18xx_valid_pin_function()
1312 scu->func[func].ngroups = ngroups; in lpc18xx_create_group_func_map()
1313 scu->func[func].groups = devm_kcalloc(dev, in lpc18xx_create_group_func_map()
1316 if (!scu->func[func].groups) in lpc18xx_create_group_func_map()
1317 return -ENOMEM; in lpc18xx_create_group_func_map()
1320 scu->func[func].groups[i] = lpc18xx_pins[pins[i]].name; in lpc18xx_create_group_func_map()
1331 scu = devm_kzalloc(&pdev->dev, sizeof(*scu), GFP_KERNEL); in lpc18xx_scu_probe()
1333 return -ENOMEM; in lpc18xx_scu_probe()
1335 scu->base = devm_platform_ioremap_resource(pdev, 0); in lpc18xx_scu_probe()
1336 if (IS_ERR(scu->base)) in lpc18xx_scu_probe()
1337 return PTR_ERR(scu->base); in lpc18xx_scu_probe()
1339 scu->clk = devm_clk_get(&pdev->dev, NULL); in lpc18xx_scu_probe()
1340 if (IS_ERR(scu->clk)) { in lpc18xx_scu_probe()
1341 dev_err(&pdev->dev, "Input clock not found.\n"); in lpc18xx_scu_probe()
1342 return PTR_ERR(scu->clk); in lpc18xx_scu_probe()
1345 ret = lpc18xx_create_group_func_map(&pdev->dev, scu); in lpc18xx_scu_probe()
1347 dev_err(&pdev->dev, "Unable to create group func map.\n"); in lpc18xx_scu_probe()
1351 ret = clk_prepare_enable(scu->clk); in lpc18xx_scu_probe()
1353 dev_err(&pdev->dev, "Unable to enable clock.\n"); in lpc18xx_scu_probe()
1359 scu->pctl = devm_pinctrl_register(&pdev->dev, &lpc18xx_scu_desc, scu); in lpc18xx_scu_probe()
1360 if (IS_ERR(scu->pctl)) { in lpc18xx_scu_probe()
1361 dev_err(&pdev->dev, "Could not register pinctrl driver\n"); in lpc18xx_scu_probe()
1362 clk_disable_unprepare(scu->clk); in lpc18xx_scu_probe()
1363 return PTR_ERR(scu->pctl); in lpc18xx_scu_probe()
1370 { .compatible = "nxp,lpc1850-scu" },
1377 .name = "lpc18xx-scu",