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>
27 #include <linux/pinctrl/pinconf-generic.h>
31 #include "pinctrl-utils.h"
103 struct regmap *regmap; member
361 return -ENOTSUPP; in sx150x_pinctrl_get_group_pins()
374 static bool sx150x_pin_is_oscio(struct sx150x_pinctrl *pctl, unsigned int pin) in sx150x_pin_is_oscio() argument
376 if (pin >= pctl->data->npins) in sx150x_pin_is_oscio()
380 if (pctl->data->model != SX150X_789) in sx150x_pin_is_oscio()
383 return !strcmp(pctl->data->pins[pin].name, "oscio"); in sx150x_pin_is_oscio()
389 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip); in sx150x_gpio_get_direction() local
393 if (sx150x_pin_is_oscio(pctl, offset)) in sx150x_gpio_get_direction()
396 ret = regmap_read(pctl->regmap, pctl->data->reg_dir, &value); in sx150x_gpio_get_direction()
408 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip); in sx150x_gpio_get() local
412 if (sx150x_pin_is_oscio(pctl, offset)) in sx150x_gpio_get()
413 return -EINVAL; in sx150x_gpio_get()
415 ret = regmap_read(pctl->regmap, pctl->data->reg_data, &value); in sx150x_gpio_get()
422 static int __sx150x_gpio_set(struct sx150x_pinctrl *pctl, unsigned int offset, in __sx150x_gpio_set() argument
425 return regmap_write_bits(pctl->regmap, pctl->data->reg_data, in __sx150x_gpio_set()
429 static int sx150x_gpio_oscio_set(struct sx150x_pinctrl *pctl, in sx150x_gpio_oscio_set() argument
432 return regmap_write(pctl->regmap, in sx150x_gpio_oscio_set()
433 pctl->data->pri.x789.reg_clock, in sx150x_gpio_oscio_set()
440 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip); in sx150x_gpio_set() local
442 if (sx150x_pin_is_oscio(pctl, offset)) in sx150x_gpio_set()
443 sx150x_gpio_oscio_set(pctl, value); in sx150x_gpio_set()
445 __sx150x_gpio_set(pctl, offset, value); in sx150x_gpio_set()
452 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip); in sx150x_gpio_set_multiple() local
454 regmap_write_bits(pctl->regmap, pctl->data->reg_data, *mask, *bits); in sx150x_gpio_set_multiple()
460 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip); in sx150x_gpio_direction_input() local
462 if (sx150x_pin_is_oscio(pctl, offset)) in sx150x_gpio_direction_input()
463 return -EINVAL; in sx150x_gpio_direction_input()
465 return regmap_write_bits(pctl->regmap, in sx150x_gpio_direction_input()
466 pctl->data->reg_dir, in sx150x_gpio_direction_input()
473 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip); in sx150x_gpio_direction_output() local
476 if (sx150x_pin_is_oscio(pctl, offset)) in sx150x_gpio_direction_output()
477 return sx150x_gpio_oscio_set(pctl, value); in sx150x_gpio_direction_output()
479 ret = __sx150x_gpio_set(pctl, offset, value); in sx150x_gpio_direction_output()
483 return regmap_write_bits(pctl->regmap, in sx150x_gpio_direction_output()
484 pctl->data->reg_dir, in sx150x_gpio_direction_output()
490 struct sx150x_pinctrl *pctl = in sx150x_irq_mask() local
492 unsigned int n = d->hwirq; in sx150x_irq_mask()
494 pctl->irq.masked |= BIT(n); in sx150x_irq_mask()
499 struct sx150x_pinctrl *pctl = in sx150x_irq_unmask() local
501 unsigned int n = d->hwirq; in sx150x_irq_unmask()
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()
523 struct sx150x_pinctrl *pctl = in sx150x_irq_set_type() local
528 return -EINVAL; in sx150x_irq_set_type()
530 n = d->hwirq; 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()
565 struct sx150x_pinctrl *pctl = in sx150x_irq_bus_lock() local
568 mutex_lock(&pctl->lock); in sx150x_irq_bus_lock()
573 struct sx150x_pinctrl *pctl = 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()
584 struct sx150x_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in sx150x_pinconf_get() local
590 if (sx150x_pin_is_oscio(pctl, pin)) { in sx150x_pinconf_get()
594 ret = regmap_read(pctl->regmap, in sx150x_pinconf_get()
595 pctl->data->pri.x789.reg_clock, in sx150x_pinconf_get()
608 return -EINVAL; in sx150x_pinconf_get()
613 return -ENOTSUPP; in sx150x_pinconf_get()
621 ret = regmap_read(pctl->regmap, in sx150x_pinconf_get()
622 pctl->data->reg_pulldn, in sx150x_pinconf_get()
630 return -EINVAL; in sx150x_pinconf_get()
636 ret = regmap_read(pctl->regmap, in sx150x_pinconf_get()
637 pctl->data->reg_pullup, in sx150x_pinconf_get()
645 return -EINVAL; in sx150x_pinconf_get()
651 if (pctl->data->model != SX150X_789) in sx150x_pinconf_get()
652 return -ENOTSUPP; in sx150x_pinconf_get()
654 ret = regmap_read(pctl->regmap, in sx150x_pinconf_get()
655 pctl->data->pri.x789.reg_drain, in sx150x_pinconf_get()
663 return -EINVAL; in sx150x_pinconf_get()
669 if (pctl->data->model != SX150X_789) in sx150x_pinconf_get()
672 ret = regmap_read(pctl->regmap, in sx150x_pinconf_get()
673 pctl->data->pri.x789.reg_drain, in sx150x_pinconf_get()
681 return -EINVAL; in sx150x_pinconf_get()
688 ret = sx150x_gpio_get_direction(&pctl->gpio, pin); in sx150x_pinconf_get()
693 return -EINVAL; in sx150x_pinconf_get()
695 ret = sx150x_gpio_get(&pctl->gpio, pin); in sx150x_pinconf_get()
703 return -ENOTSUPP; in sx150x_pinconf_get()
715 struct sx150x_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); in sx150x_pinconf_set() local
725 if (sx150x_pin_is_oscio(pctl, pin)) { in sx150x_pinconf_set()
727 ret = sx150x_gpio_direction_output(&pctl->gpio, in sx150x_pinconf_set()
734 return -ENOTSUPP; in sx150x_pinconf_set()
740 ret = regmap_write_bits(pctl->regmap, in sx150x_pinconf_set()
741 pctl->data->reg_pulldn, in sx150x_pinconf_set()
746 ret = regmap_write_bits(pctl->regmap, in sx150x_pinconf_set()
747 pctl->data->reg_pullup, in sx150x_pinconf_set()
755 ret = regmap_write_bits(pctl->regmap, in sx150x_pinconf_set()
756 pctl->data->reg_pullup, in sx150x_pinconf_set()
764 ret = regmap_write_bits(pctl->regmap, in sx150x_pinconf_set()
765 pctl->data->reg_pulldn, in sx150x_pinconf_set()
773 if (pctl->data->model != SX150X_789 || in sx150x_pinconf_set()
774 sx150x_pin_is_oscio(pctl, pin)) in sx150x_pinconf_set()
775 return -ENOTSUPP; in sx150x_pinconf_set()
777 ret = regmap_write_bits(pctl->regmap, in sx150x_pinconf_set()
778 pctl->data->pri.x789.reg_drain, in sx150x_pinconf_set()
786 if (pctl->data->model != SX150X_789 || in sx150x_pinconf_set()
787 sx150x_pin_is_oscio(pctl, pin)) in sx150x_pinconf_set()
790 ret = regmap_write_bits(pctl->regmap, in sx150x_pinconf_set()
791 pctl->data->pri.x789.reg_drain, in sx150x_pinconf_set()
799 ret = sx150x_gpio_direction_output(&pctl->gpio, in sx150x_pinconf_set()
807 return -ENOTSUPP; in sx150x_pinconf_set()
846 static int sx150x_reset(struct sx150x_pinctrl *pctl) in sx150x_reset() argument
850 err = i2c_smbus_write_byte_data(pctl->client, in sx150x_reset()
851 pctl->data->pri.x789.reg_reset, in sx150x_reset()
856 err = i2c_smbus_write_byte_data(pctl->client, in sx150x_reset()
857 pctl->data->pri.x789.reg_reset, in sx150x_reset()
862 static int sx150x_init_misc(struct sx150x_pinctrl *pctl) in sx150x_init_misc() argument
866 switch (pctl->data->model) { in sx150x_init_misc()
868 reg = pctl->data->pri.x789.reg_misc; in sx150x_init_misc()
872 reg = pctl->data->pri.x456.reg_advanced; in sx150x_init_misc()
883 reg = pctl->data->pri.x123.reg_advanced; in sx150x_init_misc()
887 WARN(1, "Unknown chip model %d\n", pctl->data->model); in sx150x_init_misc()
888 return -EINVAL; in sx150x_init_misc()
891 return regmap_write(pctl->regmap, reg, value); in sx150x_init_misc()
894 static int sx150x_init_hw(struct sx150x_pinctrl *pctl) in sx150x_init_hw() argument
897 [SX150X_789] = pctl->data->pri.x789.reg_polarity, in sx150x_init_hw()
898 [SX150X_456] = pctl->data->pri.x456.reg_pld_mode, in sx150x_init_hw()
899 [SX150X_123] = pctl->data->pri.x123.reg_pld_mode, in sx150x_init_hw()
903 if (pctl->data->model == SX150X_789 && in sx150x_init_hw()
904 of_property_read_bool(pctl->dev->of_node, "semtech,probe-reset")) { in sx150x_init_hw()
905 err = sx150x_reset(pctl); in sx150x_init_hw()
910 err = sx150x_init_misc(pctl); in sx150x_init_hw()
915 return regmap_write(pctl->regmap, reg[pctl->data->model], 0); in sx150x_init_hw()
918 static int sx150x_regmap_reg_width(struct sx150x_pinctrl *pctl, in sx150x_regmap_reg_width() argument
921 const struct sx150x_device_data *data = pctl->data; in sx150x_regmap_reg_width()
923 if (reg == data->reg_sense) { in sx150x_regmap_reg_width()
929 return 2 * data->ngpios; in sx150x_regmap_reg_width()
930 } else if ((data->model == SX150X_789 && in sx150x_regmap_reg_width()
931 (reg == data->pri.x789.reg_misc || in sx150x_regmap_reg_width()
932 reg == data->pri.x789.reg_clock || in sx150x_regmap_reg_width()
933 reg == data->pri.x789.reg_reset)) in sx150x_regmap_reg_width()
935 (data->model == SX150X_123 && in sx150x_regmap_reg_width()
936 reg == data->pri.x123.reg_advanced) in sx150x_regmap_reg_width()
938 (data->model == SX150X_456 && in sx150x_regmap_reg_width()
939 data->pri.x456.reg_advanced && in sx150x_regmap_reg_width()
940 reg == data->pri.x456.reg_advanced)) { in sx150x_regmap_reg_width()
943 return data->ngpios; in sx150x_regmap_reg_width()
947 static unsigned int sx150x_maybe_swizzle(struct sx150x_pinctrl *pctl, in sx150x_maybe_swizzle() argument
951 const struct sx150x_device_data *data = pctl->data; in sx150x_maybe_swizzle()
969 * inner bytes of a 4-byte result in sx150x_maybe_swizzle()
972 if (reg == data->reg_sense && in sx150x_maybe_swizzle()
973 data->ngpios == 16 && in sx150x_maybe_swizzle()
974 (data->model == SX150X_123 || in sx150x_maybe_swizzle()
975 data->model == SX150X_456)) { in sx150x_maybe_swizzle()
989 * devices we set up a sligthly ficticious regmap that pretends to be
990 * a set of 32-bit (to accommodate RegSenseLow/RegSenseHigh
995 * regmap API, can work assuming that each GPIO pin is represented by
1003 struct sx150x_pinctrl *pctl = context; in sx150x_regmap_reg_read() local
1004 struct i2c_client *i2c = pctl->client; in sx150x_regmap_reg_read()
1005 const int width = sx150x_regmap_reg_width(pctl, reg); in sx150x_regmap_reg_read()
1011 * 1) 8-pin chip, single configuration bit register in sx150x_regmap_reg_read()
1016 * 2) 8-pin chip, double configuration bit register (RegSense) in sx150x_regmap_reg_read()
1022 * 3) 16-pin chip, single configuration bit register in sx150x_regmap_reg_read()
1028 * 4) 16-pin chip, double configuration bit register (RegSense) in sx150x_regmap_reg_read()
1037 for (n = width, val = 0, idx = reg; n > 0; n -= 8, idx++) { in sx150x_regmap_reg_read()
1047 *result = sx150x_maybe_swizzle(pctl, reg, val); in sx150x_regmap_reg_read()
1056 struct sx150x_pinctrl *pctl = context; in sx150x_regmap_reg_write() local
1057 struct i2c_client *i2c = pctl->client; in sx150x_regmap_reg_write()
1058 const int width = sx150x_regmap_reg_width(pctl, reg); in sx150x_regmap_reg_write()
1060 val = sx150x_maybe_swizzle(pctl, reg, val); in sx150x_regmap_reg_write()
1062 n = (width - 1) & ~7; in sx150x_regmap_reg_write()
1071 n -= 8; in sx150x_regmap_reg_write()
1079 struct sx150x_pinctrl *pctl = i2c_get_clientdata(to_i2c_client(dev)); in sx150x_reg_volatile() local
1081 return reg == pctl->data->reg_irq_src || reg == pctl->data->reg_data; in sx150x_reg_volatile()
1102 struct device *dev = &client->dev; in sx150x_probe()
1103 struct sx150x_pinctrl *pctl; in sx150x_probe() local
1106 if (!i2c_check_functionality(client->adapter, i2c_funcs)) in sx150x_probe()
1107 return -ENOSYS; in sx150x_probe()
1109 pctl = devm_kzalloc(dev, sizeof(*pctl), GFP_KERNEL); in sx150x_probe()
1110 if (!pctl) in sx150x_probe()
1111 return -ENOMEM; in sx150x_probe()
1113 i2c_set_clientdata(client, pctl); in sx150x_probe()
1115 pctl->dev = dev; in sx150x_probe()
1116 pctl->client = client; in sx150x_probe()
1118 if (dev->of_node) in sx150x_probe()
1119 pctl->data = of_device_get_match_data(dev); in sx150x_probe()
1121 pctl->data = (struct sx150x_device_data *)id->driver_data; in sx150x_probe()
1123 if (!pctl->data) in sx150x_probe()
1124 return -EINVAL; in sx150x_probe()
1126 pctl->regmap = devm_regmap_init(dev, NULL, pctl, in sx150x_probe()
1128 if (IS_ERR(pctl->regmap)) { in sx150x_probe()
1129 ret = PTR_ERR(pctl->regmap); in sx150x_probe()
1135 mutex_init(&pctl->lock); in sx150x_probe()
1137 ret = sx150x_init_hw(pctl); in sx150x_probe()
1142 pctl->pinctrl_desc.name = "sx150x-pinctrl"; in sx150x_probe()
1143 pctl->pinctrl_desc.pctlops = &sx150x_pinctrl_ops; in sx150x_probe()
1144 pctl->pinctrl_desc.confops = &sx150x_pinconf_ops; in sx150x_probe()
1145 pctl->pinctrl_desc.pins = pctl->data->pins; in sx150x_probe()
1146 pctl->pinctrl_desc.npins = pctl->data->npins; in sx150x_probe()
1147 pctl->pinctrl_desc.owner = THIS_MODULE; in sx150x_probe()
1149 ret = devm_pinctrl_register_and_init(dev, &pctl->pinctrl_desc, in sx150x_probe()
1150 pctl, &pctl->pctldev); in sx150x_probe()
1157 pctl->gpio.base = -1; in sx150x_probe()
1158 pctl->gpio.ngpio = pctl->data->npins; in sx150x_probe()
1159 pctl->gpio.get_direction = sx150x_gpio_get_direction; in sx150x_probe()
1160 pctl->gpio.direction_input = sx150x_gpio_direction_input; in sx150x_probe()
1161 pctl->gpio.direction_output = sx150x_gpio_direction_output; in sx150x_probe()
1162 pctl->gpio.get = sx150x_gpio_get; in sx150x_probe()
1163 pctl->gpio.set = sx150x_gpio_set; in sx150x_probe()
1164 pctl->gpio.set_config = gpiochip_generic_config; in sx150x_probe()
1165 pctl->gpio.parent = dev; in sx150x_probe()
1166 pctl->gpio.can_sleep = true; in sx150x_probe()
1167 pctl->gpio.label = devm_kstrdup(dev, client->name, GFP_KERNEL); in sx150x_probe()
1168 if (!pctl->gpio.label) in sx150x_probe()
1169 return -ENOMEM; in sx150x_probe()
1173 * handled by the same regmap register. The oscio pin (present in sx150x_probe()
1177 if (pctl->data->model != SX150X_789) in sx150x_probe()
1178 pctl->gpio.set_multiple = sx150x_gpio_set_multiple; in sx150x_probe()
1181 if (client->irq > 0) { in sx150x_probe()
1184 pctl->irq_chip.irq_mask = sx150x_irq_mask; in sx150x_probe()
1185 pctl->irq_chip.irq_unmask = sx150x_irq_unmask; in sx150x_probe()
1186 pctl->irq_chip.irq_set_type = sx150x_irq_set_type; in sx150x_probe()
1187 pctl->irq_chip.irq_bus_lock = sx150x_irq_bus_lock; in sx150x_probe()
1188 pctl->irq_chip.irq_bus_sync_unlock = sx150x_irq_bus_sync_unlock; in sx150x_probe()
1189 pctl->irq_chip.name = devm_kstrdup(dev, client->name, in sx150x_probe()
1191 if (!pctl->irq_chip.name) in sx150x_probe()
1192 return -ENOMEM; in sx150x_probe()
1194 pctl->irq.masked = ~0; in sx150x_probe()
1195 pctl->irq.sense = 0; in sx150x_probe()
1208 girq = &pctl->gpio.irq; in sx150x_probe()
1209 girq->chip = &pctl->irq_chip; in sx150x_probe()
1211 girq->parent_handler = NULL; in sx150x_probe()
1212 girq->num_parents = 0; in sx150x_probe()
1213 girq->parents = NULL; in sx150x_probe()
1214 girq->default_type = IRQ_TYPE_NONE; in sx150x_probe()
1215 girq->handler = handle_bad_irq; in sx150x_probe()
1216 girq->threaded = true; in sx150x_probe()
1218 ret = devm_request_threaded_irq(dev, client->irq, NULL, in sx150x_probe()
1222 pctl->irq_chip.name, pctl); in sx150x_probe()
1227 ret = devm_gpiochip_add_data(dev, &pctl->gpio, pctl); in sx150x_probe()
1236 ret = pinctrl_enable(pctl->pctldev); in sx150x_probe()
1242 ret = gpiochip_add_pin_range(&pctl->gpio, dev_name(dev), in sx150x_probe()
1243 0, 0, pctl->data->npins); in sx150x_probe()
1252 .name = "sx150x-pinctrl",