Lines Matching +full:pctl +full:- +full:regmap

1 // SPDX-License-Identifier: GPL-2.0-only
9 * The handling of the 4-bit chips (SX1501/SX1504/SX1507) is untested.
14 #include <linux/regmap.h>
26 #include <linux/pinctrl/pinconf-generic.h>
30 #include "pinctrl-utils.h"
101 struct regmap *regmap; member
359 return -ENOTSUPP; in sx150x_pinctrl_get_group_pins()
372 static bool sx150x_pin_is_oscio(struct sx150x_pinctrl *pctl, unsigned int pin) in sx150x_pin_is_oscio() argument
374 if (pin >= pctl->data->npins) in sx150x_pin_is_oscio()
378 if (pctl->data->model != SX150X_789) in sx150x_pin_is_oscio()
381 return !strcmp(pctl->data->pins[pin].name, "oscio"); in sx150x_pin_is_oscio()
387 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip); in sx150x_gpio_get_direction() local
391 if (sx150x_pin_is_oscio(pctl, offset)) in sx150x_gpio_get_direction()
394 ret = regmap_read(pctl->regmap, pctl->data->reg_dir, &value); in sx150x_gpio_get_direction()
406 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip); in sx150x_gpio_get() local
410 if (sx150x_pin_is_oscio(pctl, offset)) in sx150x_gpio_get()
411 return -EINVAL; in sx150x_gpio_get()
413 ret = regmap_read(pctl->regmap, pctl->data->reg_data, &value); in sx150x_gpio_get()
420 static int __sx150x_gpio_set(struct sx150x_pinctrl *pctl, unsigned int offset, in __sx150x_gpio_set() argument
423 return regmap_write_bits(pctl->regmap, pctl->data->reg_data, in __sx150x_gpio_set()
427 static int sx150x_gpio_oscio_set(struct sx150x_pinctrl *pctl, in sx150x_gpio_oscio_set() argument
430 return regmap_write(pctl->regmap, in sx150x_gpio_oscio_set()
431 pctl->data->pri.x789.reg_clock, in sx150x_gpio_oscio_set()
438 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip); in sx150x_gpio_set() local
440 if (sx150x_pin_is_oscio(pctl, offset)) in sx150x_gpio_set()
441 sx150x_gpio_oscio_set(pctl, value); in sx150x_gpio_set()
443 __sx150x_gpio_set(pctl, offset, value); in sx150x_gpio_set()
450 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip); in sx150x_gpio_set_multiple() local
452 regmap_write_bits(pctl->regmap, pctl->data->reg_data, *mask, *bits); in sx150x_gpio_set_multiple()
458 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip); in sx150x_gpio_direction_input() local
460 if (sx150x_pin_is_oscio(pctl, offset)) in sx150x_gpio_direction_input()
461 return -EINVAL; in sx150x_gpio_direction_input()
463 return regmap_write_bits(pctl->regmap, in sx150x_gpio_direction_input()
464 pctl->data->reg_dir, in sx150x_gpio_direction_input()
471 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip); in sx150x_gpio_direction_output() local
474 if (sx150x_pin_is_oscio(pctl, offset)) in sx150x_gpio_direction_output()
475 return sx150x_gpio_oscio_set(pctl, value); in sx150x_gpio_direction_output()
477 ret = __sx150x_gpio_set(pctl, offset, value); in sx150x_gpio_direction_output()
481 return regmap_write_bits(pctl->regmap, in sx150x_gpio_direction_output()
482 pctl->data->reg_dir, in sx150x_gpio_direction_output()
489 struct sx150x_pinctrl *pctl = gpiochip_get_data(gc); in sx150x_irq_mask() local
492 pctl->irq.masked |= BIT(n); in sx150x_irq_mask()
499 struct sx150x_pinctrl *pctl = gpiochip_get_data(gc); in sx150x_irq_unmask() local
503 pctl->irq.masked &= ~BIT(n); in sx150x_irq_unmask()
506 static void sx150x_irq_set_sense(struct sx150x_pinctrl *pctl, in sx150x_irq_set_sense() argument
517 pctl->irq.sense &= mask; in sx150x_irq_set_sense()
518 pctl->irq.sense |= sense << n; in sx150x_irq_set_sense()
524 struct sx150x_pinctrl *pctl = gpiochip_get_data(gc); in sx150x_irq_set_type() local
528 return -EINVAL; in sx150x_irq_set_type()
537 sx150x_irq_set_sense(pctl, n, val); in sx150x_irq_set_type()
543 struct sx150x_pinctrl *pctl = (struct sx150x_pinctrl *)dev_id; in sx150x_irq_thread_fn() local
548 err = regmap_read(pctl->regmap, pctl->data->reg_irq_src, &val); in sx150x_irq_thread_fn()
552 err = regmap_write(pctl->regmap, pctl->data->reg_irq_src, val); in sx150x_irq_thread_fn()
557 for_each_set_bit(n, &status, pctl->data->ngpios) in sx150x_irq_thread_fn()
558 handle_nested_irq(irq_find_mapping(pctl->gpio.irq.domain, n)); in sx150x_irq_thread_fn()
566 struct sx150x_pinctrl *pctl = gpiochip_get_data(gc); in sx150x_irq_bus_lock() local
568 mutex_lock(&pctl->lock); in sx150x_irq_bus_lock()
574 struct sx150x_pinctrl *pctl = gpiochip_get_data(gc); in sx150x_irq_bus_sync_unlock() local
576 regmap_write(pctl->regmap, pctl->data->reg_irq_mask, pctl->irq.masked); in sx150x_irq_bus_sync_unlock()
577 regmap_write(pctl->regmap, pctl->data->reg_sense, pctl->irq.sense); in sx150x_irq_bus_sync_unlock()
578 mutex_unlock(&pctl->lock); in sx150x_irq_bus_sync_unlock()
585 struct sx150x_pinctrl *pctl = gpiochip_get_data(gc); in sx150x_irq_print_chip() local
587 seq_printf(p, pctl->client->name); in sx150x_irq_print_chip()
604 struct sx150x_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in sx150x_pinconf_get() local
610 if (sx150x_pin_is_oscio(pctl, pin)) { in sx150x_pinconf_get()
614 ret = regmap_read(pctl->regmap, in sx150x_pinconf_get()
615 pctl->data->pri.x789.reg_clock, in sx150x_pinconf_get()
628 return -EINVAL; in sx150x_pinconf_get()
633 return -ENOTSUPP; in sx150x_pinconf_get()
641 ret = regmap_read(pctl->regmap, in sx150x_pinconf_get()
642 pctl->data->reg_pulldn, in sx150x_pinconf_get()
650 return -EINVAL; in sx150x_pinconf_get()
656 ret = regmap_read(pctl->regmap, in sx150x_pinconf_get()
657 pctl->data->reg_pullup, in sx150x_pinconf_get()
665 return -EINVAL; in sx150x_pinconf_get()
671 if (pctl->data->model != SX150X_789) in sx150x_pinconf_get()
672 return -ENOTSUPP; in sx150x_pinconf_get()
674 ret = regmap_read(pctl->regmap, in sx150x_pinconf_get()
675 pctl->data->pri.x789.reg_drain, in sx150x_pinconf_get()
683 return -EINVAL; in sx150x_pinconf_get()
689 if (pctl->data->model != SX150X_789) in sx150x_pinconf_get()
692 ret = regmap_read(pctl->regmap, in sx150x_pinconf_get()
693 pctl->data->pri.x789.reg_drain, in sx150x_pinconf_get()
701 return -EINVAL; in sx150x_pinconf_get()
708 ret = sx150x_gpio_get_direction(&pctl->gpio, pin); in sx150x_pinconf_get()
713 return -EINVAL; in sx150x_pinconf_get()
715 ret = sx150x_gpio_get(&pctl->gpio, pin); in sx150x_pinconf_get()
723 return -ENOTSUPP; in sx150x_pinconf_get()
735 struct sx150x_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in sx150x_pinconf_set() local
745 if (sx150x_pin_is_oscio(pctl, pin)) { in sx150x_pinconf_set()
747 ret = sx150x_gpio_direction_output(&pctl->gpio, in sx150x_pinconf_set()
754 return -ENOTSUPP; in sx150x_pinconf_set()
760 ret = regmap_write_bits(pctl->regmap, in sx150x_pinconf_set()
761 pctl->data->reg_pulldn, in sx150x_pinconf_set()
766 ret = regmap_write_bits(pctl->regmap, in sx150x_pinconf_set()
767 pctl->data->reg_pullup, in sx150x_pinconf_set()
775 ret = regmap_write_bits(pctl->regmap, in sx150x_pinconf_set()
776 pctl->data->reg_pullup, in sx150x_pinconf_set()
784 ret = regmap_write_bits(pctl->regmap, in sx150x_pinconf_set()
785 pctl->data->reg_pulldn, in sx150x_pinconf_set()
793 if (pctl->data->model != SX150X_789 || in sx150x_pinconf_set()
794 sx150x_pin_is_oscio(pctl, pin)) in sx150x_pinconf_set()
795 return -ENOTSUPP; in sx150x_pinconf_set()
797 ret = regmap_write_bits(pctl->regmap, in sx150x_pinconf_set()
798 pctl->data->pri.x789.reg_drain, in sx150x_pinconf_set()
806 if (pctl->data->model != SX150X_789 || in sx150x_pinconf_set()
807 sx150x_pin_is_oscio(pctl, pin)) in sx150x_pinconf_set()
810 ret = regmap_write_bits(pctl->regmap, in sx150x_pinconf_set()
811 pctl->data->pri.x789.reg_drain, in sx150x_pinconf_set()
819 ret = sx150x_gpio_direction_output(&pctl->gpio, in sx150x_pinconf_set()
827 return -ENOTSUPP; in sx150x_pinconf_set()
866 static int sx150x_reset(struct sx150x_pinctrl *pctl) in sx150x_reset() argument
870 err = i2c_smbus_write_byte_data(pctl->client, in sx150x_reset()
871 pctl->data->pri.x789.reg_reset, in sx150x_reset()
876 err = i2c_smbus_write_byte_data(pctl->client, in sx150x_reset()
877 pctl->data->pri.x789.reg_reset, in sx150x_reset()
882 static int sx150x_init_misc(struct sx150x_pinctrl *pctl) in sx150x_init_misc() argument
886 switch (pctl->data->model) { in sx150x_init_misc()
888 reg = pctl->data->pri.x789.reg_misc; in sx150x_init_misc()
892 reg = pctl->data->pri.x456.reg_advanced; in sx150x_init_misc()
903 reg = pctl->data->pri.x123.reg_advanced; in sx150x_init_misc()
907 WARN(1, "Unknown chip model %d\n", pctl->data->model); in sx150x_init_misc()
908 return -EINVAL; in sx150x_init_misc()
911 return regmap_write(pctl->regmap, reg, value); in sx150x_init_misc()
914 static int sx150x_init_hw(struct sx150x_pinctrl *pctl) in sx150x_init_hw() argument
917 [SX150X_789] = pctl->data->pri.x789.reg_polarity, in sx150x_init_hw()
918 [SX150X_456] = pctl->data->pri.x456.reg_pld_mode, in sx150x_init_hw()
919 [SX150X_123] = pctl->data->pri.x123.reg_pld_mode, in sx150x_init_hw()
923 if (pctl->data->model == SX150X_789 && in sx150x_init_hw()
924 of_property_read_bool(pctl->dev->of_node, "semtech,probe-reset")) { in sx150x_init_hw()
925 err = sx150x_reset(pctl); in sx150x_init_hw()
930 err = sx150x_init_misc(pctl); in sx150x_init_hw()
935 return regmap_write(pctl->regmap, reg[pctl->data->model], 0); in sx150x_init_hw()
938 static int sx150x_regmap_reg_width(struct sx150x_pinctrl *pctl, in sx150x_regmap_reg_width() argument
941 const struct sx150x_device_data *data = pctl->data; in sx150x_regmap_reg_width()
943 if (reg == data->reg_sense) { in sx150x_regmap_reg_width()
949 return 2 * data->ngpios; in sx150x_regmap_reg_width()
950 } else if ((data->model == SX150X_789 && in sx150x_regmap_reg_width()
951 (reg == data->pri.x789.reg_misc || in sx150x_regmap_reg_width()
952 reg == data->pri.x789.reg_clock || in sx150x_regmap_reg_width()
953 reg == data->pri.x789.reg_reset)) in sx150x_regmap_reg_width()
955 (data->model == SX150X_123 && in sx150x_regmap_reg_width()
956 reg == data->pri.x123.reg_advanced) in sx150x_regmap_reg_width()
958 (data->model == SX150X_456 && in sx150x_regmap_reg_width()
959 data->pri.x456.reg_advanced && in sx150x_regmap_reg_width()
960 reg == data->pri.x456.reg_advanced)) { in sx150x_regmap_reg_width()
963 return data->ngpios; in sx150x_regmap_reg_width()
967 static unsigned int sx150x_maybe_swizzle(struct sx150x_pinctrl *pctl, in sx150x_maybe_swizzle() argument
971 const struct sx150x_device_data *data = pctl->data; in sx150x_maybe_swizzle()
989 * inner bytes of a 4-byte result in sx150x_maybe_swizzle()
992 if (reg == data->reg_sense && in sx150x_maybe_swizzle()
993 data->ngpios == 16 && in sx150x_maybe_swizzle()
994 (data->model == SX150X_123 || in sx150x_maybe_swizzle()
995 data->model == SX150X_456)) { in sx150x_maybe_swizzle()
1009 * devices we set up a sligthly ficticious regmap that pretends to be
1010 * a set of 32-bit (to accommodate RegSenseLow/RegSenseHigh
1015 * regmap API, can work assuming that each GPIO pin is represented by
1023 struct sx150x_pinctrl *pctl = context; in sx150x_regmap_reg_read() local
1024 struct i2c_client *i2c = pctl->client; in sx150x_regmap_reg_read()
1025 const int width = sx150x_regmap_reg_width(pctl, reg); in sx150x_regmap_reg_read()
1031 * 1) 8-pin chip, single configuration bit register in sx150x_regmap_reg_read()
1036 * 2) 8-pin chip, double configuration bit register (RegSense) in sx150x_regmap_reg_read()
1042 * 3) 16-pin chip, single configuration bit register in sx150x_regmap_reg_read()
1048 * 4) 16-pin chip, double configuration bit register (RegSense) in sx150x_regmap_reg_read()
1057 for (n = width, val = 0, idx = reg; n > 0; n -= 8, idx++) { in sx150x_regmap_reg_read()
1067 *result = sx150x_maybe_swizzle(pctl, reg, val); in sx150x_regmap_reg_read()
1076 struct sx150x_pinctrl *pctl = context; in sx150x_regmap_reg_write() local
1077 struct i2c_client *i2c = pctl->client; in sx150x_regmap_reg_write()
1078 const int width = sx150x_regmap_reg_width(pctl, reg); in sx150x_regmap_reg_write()
1080 val = sx150x_maybe_swizzle(pctl, reg, val); in sx150x_regmap_reg_write()
1082 n = (width - 1) & ~7; in sx150x_regmap_reg_write()
1091 n -= 8; in sx150x_regmap_reg_write()
1099 struct sx150x_pinctrl *pctl = i2c_get_clientdata(to_i2c_client(dev)); in sx150x_reg_volatile() local
1101 return reg == pctl->data->reg_irq_src || reg == pctl->data->reg_data; in sx150x_reg_volatile()
1122 struct device *dev = &client->dev; in sx150x_probe()
1123 struct sx150x_pinctrl *pctl; in sx150x_probe() local
1126 if (!i2c_check_functionality(client->adapter, i2c_funcs)) in sx150x_probe()
1127 return -ENOSYS; in sx150x_probe()
1129 pctl = devm_kzalloc(dev, sizeof(*pctl), GFP_KERNEL); in sx150x_probe()
1130 if (!pctl) in sx150x_probe()
1131 return -ENOMEM; in sx150x_probe()
1133 i2c_set_clientdata(client, pctl); in sx150x_probe()
1135 pctl->dev = dev; in sx150x_probe()
1136 pctl->client = client; in sx150x_probe()
1138 if (dev->of_node) in sx150x_probe()
1139 pctl->data = of_device_get_match_data(dev); in sx150x_probe()
1141 pctl->data = (struct sx150x_device_data *)id->driver_data; in sx150x_probe()
1143 if (!pctl->data) in sx150x_probe()
1144 return -EINVAL; in sx150x_probe()
1146 pctl->regmap = devm_regmap_init(dev, NULL, pctl, in sx150x_probe()
1148 if (IS_ERR(pctl->regmap)) { in sx150x_probe()
1149 ret = PTR_ERR(pctl->regmap); in sx150x_probe()
1155 mutex_init(&pctl->lock); in sx150x_probe()
1157 ret = sx150x_init_hw(pctl); in sx150x_probe()
1162 pctl->pinctrl_desc.name = "sx150x-pinctrl"; in sx150x_probe()
1163 pctl->pinctrl_desc.pctlops = &sx150x_pinctrl_ops; in sx150x_probe()
1164 pctl->pinctrl_desc.confops = &sx150x_pinconf_ops; in sx150x_probe()
1165 pctl->pinctrl_desc.pins = pctl->data->pins; in sx150x_probe()
1166 pctl->pinctrl_desc.npins = pctl->data->npins; in sx150x_probe()
1167 pctl->pinctrl_desc.owner = THIS_MODULE; in sx150x_probe()
1169 ret = devm_pinctrl_register_and_init(dev, &pctl->pinctrl_desc, in sx150x_probe()
1170 pctl, &pctl->pctldev); in sx150x_probe()
1177 pctl->gpio.base = -1; in sx150x_probe()
1178 pctl->gpio.ngpio = pctl->data->npins; in sx150x_probe()
1179 pctl->gpio.get_direction = sx150x_gpio_get_direction; in sx150x_probe()
1180 pctl->gpio.direction_input = sx150x_gpio_direction_input; in sx150x_probe()
1181 pctl->gpio.direction_output = sx150x_gpio_direction_output; in sx150x_probe()
1182 pctl->gpio.get = sx150x_gpio_get; in sx150x_probe()
1183 pctl->gpio.set = sx150x_gpio_set; in sx150x_probe()
1184 pctl->gpio.set_config = gpiochip_generic_config; in sx150x_probe()
1185 pctl->gpio.parent = dev; in sx150x_probe()
1186 pctl->gpio.can_sleep = true; in sx150x_probe()
1187 pctl->gpio.label = devm_kstrdup(dev, client->name, GFP_KERNEL); in sx150x_probe()
1188 if (!pctl->gpio.label) in sx150x_probe()
1189 return -ENOMEM; in sx150x_probe()
1193 * handled by the same regmap register. The oscio pin (present in sx150x_probe()
1197 if (pctl->data->model != SX150X_789) in sx150x_probe()
1198 pctl->gpio.set_multiple = sx150x_gpio_set_multiple; in sx150x_probe()
1201 if (client->irq > 0) { in sx150x_probe()
1204 pctl->irq.masked = ~0; in sx150x_probe()
1205 pctl->irq.sense = 0; in sx150x_probe()
1217 girq = &pctl->gpio.irq; in sx150x_probe()
1220 girq->parent_handler = NULL; in sx150x_probe()
1221 girq->num_parents = 0; in sx150x_probe()
1222 girq->parents = NULL; in sx150x_probe()
1223 girq->default_type = IRQ_TYPE_NONE; in sx150x_probe()
1224 girq->handler = handle_bad_irq; in sx150x_probe()
1225 girq->threaded = true; in sx150x_probe()
1227 ret = devm_request_threaded_irq(dev, client->irq, NULL, in sx150x_probe()
1231 client->name, pctl); in sx150x_probe()
1236 ret = devm_gpiochip_add_data(dev, &pctl->gpio, pctl); in sx150x_probe()
1245 ret = pinctrl_enable(pctl->pctldev); in sx150x_probe()
1251 ret = gpiochip_add_pin_range(&pctl->gpio, dev_name(dev), in sx150x_probe()
1252 0, 0, pctl->data->npins); in sx150x_probe()
1261 .name = "sx150x-pinctrl",