2 * Copyright (c) 2016, BayLibre, SAS. All rights reserved.
3 * Author: Neil Armstrong <narmstrong@baylibre.com>
5 * Copyright (c) 2010, Code Aurora Forum. All rights reserved.
7 * Driver for Semtech SX150X I2C GPIO Expanders
9 * Author: Gregory Bean <gbean@codeaurora.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 and
13 * only version 2 as published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include <linux/i2c.h>
22 #include <linux/init.h>
23 #include <linux/interrupt.h>
24 #include <linux/irq.h>
25 #include <linux/mutex.h>
26 #include <linux/slab.h>
28 #include <linux/of_device.h>
29 #include <linux/gpio.h>
30 #include <linux/pinctrl/machine.h>
31 #include <linux/pinctrl/pinconf.h>
32 #include <linux/pinctrl/pinctrl.h>
33 #include <linux/pinctrl/pinmux.h>
34 #include <linux/pinctrl/pinconf-generic.h>
38 #include "pinctrl-utils.h"
40 /* The chip models of sx150x */
47 struct sx150x_123_pri {
57 struct sx150x_456_pri {
67 struct sx150x_789_pri {
76 struct sx150x_device_data {
87 struct sx150x_123_pri x123;
88 struct sx150x_456_pri x456;
89 struct sx150x_789_pri x789;
91 const struct pinctrl_pin_desc *pins;
95 struct sx150x_pinctrl {
97 struct i2c_client *client;
98 struct pinctrl_dev *pctldev;
99 struct pinctrl_desc pinctrl_desc;
100 struct gpio_chip gpio;
101 struct irq_chip irq_chip;
110 const struct sx150x_device_data *data;
113 static const struct pinctrl_pin_desc sx150x_8_pins[] = {
114 PINCTRL_PIN(0, "gpio0"),
115 PINCTRL_PIN(1, "gpio1"),
116 PINCTRL_PIN(2, "gpio2"),
117 PINCTRL_PIN(3, "gpio3"),
118 PINCTRL_PIN(4, "gpio4"),
119 PINCTRL_PIN(5, "gpio5"),
120 PINCTRL_PIN(6, "gpio6"),
121 PINCTRL_PIN(7, "gpio7"),
122 PINCTRL_PIN(8, "oscio"),
125 static const struct pinctrl_pin_desc sx150x_16_pins[] = {
126 PINCTRL_PIN(0, "gpio0"),
127 PINCTRL_PIN(1, "gpio1"),
128 PINCTRL_PIN(2, "gpio2"),
129 PINCTRL_PIN(3, "gpio3"),
130 PINCTRL_PIN(4, "gpio4"),
131 PINCTRL_PIN(5, "gpio5"),
132 PINCTRL_PIN(6, "gpio6"),
133 PINCTRL_PIN(7, "gpio7"),
134 PINCTRL_PIN(8, "gpio8"),
135 PINCTRL_PIN(9, "gpio9"),
136 PINCTRL_PIN(10, "gpio10"),
137 PINCTRL_PIN(11, "gpio11"),
138 PINCTRL_PIN(12, "gpio12"),
139 PINCTRL_PIN(13, "gpio13"),
140 PINCTRL_PIN(14, "gpio14"),
141 PINCTRL_PIN(15, "gpio15"),
142 PINCTRL_PIN(16, "oscio"),
145 static const struct sx150x_device_data sx1508q_device_data = {
151 .reg_irq_mask = 0x09,
156 .reg_polarity = 0x06,
162 .pins = sx150x_8_pins,
163 .npins = ARRAY_SIZE(sx150x_8_pins),
166 static const struct sx150x_device_data sx1509q_device_data = {
172 .reg_irq_mask = 0x13,
177 .reg_polarity = 0x0d,
183 .pins = sx150x_16_pins,
184 .npins = ARRAY_SIZE(sx150x_16_pins),
187 static const struct sx150x_device_data sx1506q_device_data = {
193 .reg_irq_mask = 0x09,
197 .reg_pld_mode = 0x21,
198 .reg_pld_table0 = 0x23,
199 .reg_pld_table1 = 0x25,
200 .reg_pld_table2 = 0x27,
201 .reg_pld_table3 = 0x29,
202 .reg_pld_table4 = 0x2b,
206 .pins = sx150x_16_pins,
207 .npins = 16, /* oscio not available */
210 static const struct sx150x_device_data sx1502q_device_data = {
216 .reg_irq_mask = 0x05,
220 .reg_pld_mode = 0x10,
221 .reg_pld_table0 = 0x11,
222 .reg_pld_table1 = 0x12,
223 .reg_pld_table2 = 0x13,
224 .reg_pld_table3 = 0x14,
225 .reg_pld_table4 = 0x15,
229 .pins = sx150x_8_pins,
230 .npins = 8, /* oscio not available */
233 static s32 sx150x_i2c_write(struct i2c_client *client, u8 reg, u8 val)
235 s32 err = i2c_smbus_write_byte_data(client, reg, val);
238 dev_warn(&client->dev,
239 "i2c write fail: can't write %02x to %02x: %d\n",
244 static s32 sx150x_i2c_read(struct i2c_client *client, u8 reg, u8 *val)
246 s32 err = i2c_smbus_read_byte_data(client, reg);
251 dev_warn(&client->dev,
252 "i2c read fail: can't read from %02x: %d\n",
258 * These utility functions solve the common problem of locating and setting
259 * configuration bits. Configuration bits are grouped into registers
260 * whose indexes increase downwards. For example, with eight-bit registers,
261 * sixteen gpios would have their config bits grouped in the following order:
262 * REGISTER N-1 [ f e d c b a 9 8 ]
263 * N [ 7 6 5 4 3 2 1 0 ]
265 * For multi-bit configurations, the pattern gets wider:
266 * REGISTER N-3 [ f f e e d d c c ]
267 * N-2 [ b b a a 9 9 8 8 ]
268 * N-1 [ 7 7 6 6 5 5 4 4 ]
269 * N [ 3 3 2 2 1 1 0 0 ]
271 * Given the address of the starting register 'N', the index of the gpio
272 * whose configuration we seek to change, and the width in bits of that
273 * configuration, these functions allow us to locate the correct
274 * register and mask the correct bits.
276 static inline void sx150x_find_cfg(u8 offset, u8 width,
277 u8 *reg, u8 *mask, u8 *shift)
279 *reg -= offset * width / 8;
280 *mask = (1 << width) - 1;
281 *shift = (offset * width) % 8;
285 static int sx150x_write_cfg(struct i2c_client *client,
286 u8 offset, u8 width, u8 reg, u8 val)
293 sx150x_find_cfg(offset, width, ®, &mask, &shift);
294 err = sx150x_i2c_read(client, reg, &data);
299 data |= (val << shift) & mask;
300 return sx150x_i2c_write(client, reg, data);
303 static int sx150x_read_cfg(struct i2c_client *client,
304 u8 offset, u8 width, u8 reg)
311 sx150x_find_cfg(offset, width, ®, &mask, &shift);
312 err = sx150x_i2c_read(client, reg, &data);
316 return (data & mask);
319 static int sx150x_pinctrl_get_groups_count(struct pinctrl_dev *pctldev)
324 static const char *sx150x_pinctrl_get_group_name(struct pinctrl_dev *pctldev,
330 static int sx150x_pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
332 const unsigned int **pins,
333 unsigned int *num_pins)
338 static const struct pinctrl_ops sx150x_pinctrl_ops = {
339 .get_groups_count = sx150x_pinctrl_get_groups_count,
340 .get_group_name = sx150x_pinctrl_get_group_name,
341 .get_group_pins = sx150x_pinctrl_get_group_pins,
343 .dt_node_to_map = pinconf_generic_dt_node_to_map_pin,
344 .dt_free_map = pinctrl_utils_free_map,
348 static bool sx150x_pin_is_oscio(struct sx150x_pinctrl *pctl, unsigned int pin)
350 if (pin >= pctl->data->npins)
353 /* OSCIO pin is only present in 789 devices */
354 if (pctl->data->model != SX150X_789)
357 return !strcmp(pctl->data->pins[pin].name, "oscio");
360 static int sx150x_gpio_get_direction(struct gpio_chip *chip,
363 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
366 if (sx150x_pin_is_oscio(pctl, offset))
369 status = sx150x_read_cfg(pctl->client, offset, 1, pctl->data->reg_dir);
376 static int sx150x_gpio_get(struct gpio_chip *chip, unsigned int offset)
378 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
381 if (sx150x_pin_is_oscio(pctl, offset))
384 status = sx150x_read_cfg(pctl->client, offset, 1, pctl->data->reg_data);
391 static int sx150x_gpio_set_single_ended(struct gpio_chip *chip,
393 enum single_ended_mode mode)
395 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
399 case LINE_MODE_PUSH_PULL:
400 if (pctl->data->model != SX150X_789 ||
401 sx150x_pin_is_oscio(pctl, offset))
404 mutex_lock(&pctl->lock);
405 ret = sx150x_write_cfg(pctl->client, offset, 1,
406 pctl->data->pri.x789.reg_drain,
408 mutex_unlock(&pctl->lock);
413 case LINE_MODE_OPEN_DRAIN:
414 if (pctl->data->model != SX150X_789 ||
415 sx150x_pin_is_oscio(pctl, offset))
418 mutex_lock(&pctl->lock);
419 ret = sx150x_write_cfg(pctl->client, offset, 1,
420 pctl->data->pri.x789.reg_drain,
422 mutex_unlock(&pctl->lock);
434 static void sx150x_gpio_set(struct gpio_chip *chip, unsigned int offset,
437 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
439 if (sx150x_pin_is_oscio(pctl, offset)) {
441 mutex_lock(&pctl->lock);
442 sx150x_i2c_write(pctl->client,
443 pctl->data->pri.x789.reg_clock,
444 (value ? 0x1f : 0x10));
445 mutex_unlock(&pctl->lock);
447 mutex_lock(&pctl->lock);
448 sx150x_write_cfg(pctl->client, offset, 1,
449 pctl->data->reg_data,
451 mutex_unlock(&pctl->lock);
455 static int sx150x_gpio_direction_input(struct gpio_chip *chip,
458 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
461 if (sx150x_pin_is_oscio(pctl, offset))
464 mutex_lock(&pctl->lock);
465 ret = sx150x_write_cfg(pctl->client, offset, 1,
466 pctl->data->reg_dir, 1);
467 mutex_unlock(&pctl->lock);
472 static int sx150x_gpio_direction_output(struct gpio_chip *chip,
473 unsigned int offset, int value)
475 struct sx150x_pinctrl *pctl = gpiochip_get_data(chip);
478 if (sx150x_pin_is_oscio(pctl, offset)) {
479 sx150x_gpio_set(chip, offset, value);
483 mutex_lock(&pctl->lock);
484 status = sx150x_write_cfg(pctl->client, offset, 1,
485 pctl->data->reg_data,
488 status = sx150x_write_cfg(pctl->client, offset, 1,
489 pctl->data->reg_dir, 0);
490 mutex_unlock(&pctl->lock);
495 static void sx150x_irq_mask(struct irq_data *d)
497 struct sx150x_pinctrl *pctl =
498 gpiochip_get_data(irq_data_get_irq_chip_data(d));
499 unsigned int n = d->hwirq;
501 pctl->irq.masked |= (1 << n);
502 pctl->irq.update = n;
505 static void sx150x_irq_unmask(struct irq_data *d)
507 struct sx150x_pinctrl *pctl =
508 gpiochip_get_data(irq_data_get_irq_chip_data(d));
509 unsigned int n = d->hwirq;
511 pctl->irq.masked &= ~(1 << n);
512 pctl->irq.update = n;
515 static int sx150x_irq_set_type(struct irq_data *d, unsigned int flow_type)
517 struct sx150x_pinctrl *pctl =
518 gpiochip_get_data(irq_data_get_irq_chip_data(d));
519 unsigned int n, val = 0;
521 if (flow_type & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW))
526 if (flow_type & IRQ_TYPE_EDGE_RISING)
528 if (flow_type & IRQ_TYPE_EDGE_FALLING)
531 pctl->irq.sense &= ~(3UL << (n * 2));
532 pctl->irq.sense |= val << (n * 2);
533 pctl->irq.update = n;
537 static irqreturn_t sx150x_irq_thread_fn(int irq, void *dev_id)
539 struct sx150x_pinctrl *pctl = (struct sx150x_pinctrl *)dev_id;
540 unsigned int nhandled = 0;
541 unsigned int sub_irq;
547 for (i = (pctl->data->ngpios / 8) - 1; i >= 0; --i) {
548 err = sx150x_i2c_read(pctl->client,
549 pctl->data->reg_irq_src - i,
554 err = sx150x_i2c_write(pctl->client,
555 pctl->data->reg_irq_src - i,
560 for (n = 0; n < 8; ++n) {
561 if (val & (1 << n)) {
562 sub_irq = irq_find_mapping(
563 pctl->gpio.irqdomain,
565 handle_nested_irq(sub_irq);
571 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
574 static void sx150x_irq_bus_lock(struct irq_data *d)
576 struct sx150x_pinctrl *pctl =
577 gpiochip_get_data(irq_data_get_irq_chip_data(d));
579 mutex_lock(&pctl->lock);
582 static void sx150x_irq_bus_sync_unlock(struct irq_data *d)
584 struct sx150x_pinctrl *pctl =
585 gpiochip_get_data(irq_data_get_irq_chip_data(d));
588 if (pctl->irq.update < 0)
591 n = pctl->irq.update;
592 pctl->irq.update = -1;
594 /* Avoid updates if nothing changed */
595 if (pctl->irq.dev_sense == pctl->irq.sense &&
596 pctl->irq.dev_masked == pctl->irq.masked)
599 pctl->irq.dev_sense = pctl->irq.sense;
600 pctl->irq.dev_masked = pctl->irq.masked;
602 if (pctl->irq.masked & (1 << n)) {
603 sx150x_write_cfg(pctl->client, n, 1,
604 pctl->data->reg_irq_mask, 1);
605 sx150x_write_cfg(pctl->client, n, 2,
606 pctl->data->reg_sense, 0);
608 sx150x_write_cfg(pctl->client, n, 1,
609 pctl->data->reg_irq_mask, 0);
610 sx150x_write_cfg(pctl->client, n, 2,
611 pctl->data->reg_sense,
612 pctl->irq.sense >> (n * 2));
615 mutex_unlock(&pctl->lock);
618 static int sx150x_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
619 unsigned long *config)
621 struct sx150x_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
622 unsigned int param = pinconf_to_config_param(*config);
626 if (sx150x_pin_is_oscio(pctl, pin)) {
630 case PIN_CONFIG_DRIVE_PUSH_PULL:
631 case PIN_CONFIG_OUTPUT:
632 mutex_lock(&pctl->lock);
633 ret = sx150x_i2c_read(pctl->client,
634 pctl->data->pri.x789.reg_clock,
636 mutex_unlock(&pctl->lock);
641 if (param == PIN_CONFIG_DRIVE_PUSH_PULL)
642 arg = (data & 0x1f) ? 1 : 0;
644 if ((data & 0x1f) == 0x1f)
646 else if ((data & 0x1f) == 0x10)
661 case PIN_CONFIG_BIAS_PULL_DOWN:
662 mutex_lock(&pctl->lock);
663 ret = sx150x_read_cfg(pctl->client, pin, 1,
664 pctl->data->reg_pulldn);
665 mutex_unlock(&pctl->lock);
676 case PIN_CONFIG_BIAS_PULL_UP:
677 mutex_lock(&pctl->lock);
678 ret = sx150x_read_cfg(pctl->client, pin, 1,
679 pctl->data->reg_pullup);
680 mutex_unlock(&pctl->lock);
691 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
692 if (pctl->data->model != SX150X_789)
695 mutex_lock(&pctl->lock);
696 ret = sx150x_read_cfg(pctl->client, pin, 1,
697 pctl->data->pri.x789.reg_drain);
698 mutex_unlock(&pctl->lock);
709 case PIN_CONFIG_DRIVE_PUSH_PULL:
710 if (pctl->data->model != SX150X_789)
713 mutex_lock(&pctl->lock);
714 ret = sx150x_read_cfg(pctl->client, pin, 1,
715 pctl->data->pri.x789.reg_drain);
716 mutex_unlock(&pctl->lock);
728 case PIN_CONFIG_OUTPUT:
729 ret = sx150x_gpio_get_direction(&pctl->gpio, pin);
736 ret = sx150x_gpio_get(&pctl->gpio, pin);
748 *config = pinconf_to_config_packed(param, arg);
753 static int sx150x_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
754 unsigned long *configs, unsigned int num_configs)
756 struct sx150x_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev);
757 enum pin_config_param param;
762 for (i = 0; i < num_configs; i++) {
763 param = pinconf_to_config_param(configs[i]);
764 arg = pinconf_to_config_argument(configs[i]);
766 if (sx150x_pin_is_oscio(pctl, pin)) {
767 if (param == PIN_CONFIG_OUTPUT) {
768 ret = sx150x_gpio_direction_output(&pctl->gpio,
779 case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT:
780 case PIN_CONFIG_BIAS_DISABLE:
781 mutex_lock(&pctl->lock);
782 ret = sx150x_write_cfg(pctl->client, pin, 1,
783 pctl->data->reg_pulldn, 0);
784 mutex_unlock(&pctl->lock);
788 mutex_lock(&pctl->lock);
789 ret = sx150x_write_cfg(pctl->client, pin, 1,
790 pctl->data->reg_pullup, 0);
791 mutex_unlock(&pctl->lock);
797 case PIN_CONFIG_BIAS_PULL_UP:
798 mutex_lock(&pctl->lock);
799 ret = sx150x_write_cfg(pctl->client, pin, 1,
800 pctl->data->reg_pullup,
802 mutex_unlock(&pctl->lock);
808 case PIN_CONFIG_BIAS_PULL_DOWN:
809 mutex_lock(&pctl->lock);
810 ret = sx150x_write_cfg(pctl->client, pin, 1,
811 pctl->data->reg_pulldn,
813 mutex_unlock(&pctl->lock);
819 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
820 ret = sx150x_gpio_set_single_ended(&pctl->gpio,
821 pin, LINE_MODE_OPEN_DRAIN);
827 case PIN_CONFIG_DRIVE_PUSH_PULL:
828 ret = sx150x_gpio_set_single_ended(&pctl->gpio,
829 pin, LINE_MODE_PUSH_PULL);
835 case PIN_CONFIG_OUTPUT:
836 ret = sx150x_gpio_direction_output(&pctl->gpio,
846 } /* for each config */
851 static const struct pinconf_ops sx150x_pinconf_ops = {
852 .pin_config_get = sx150x_pinconf_get,
853 .pin_config_set = sx150x_pinconf_set,
857 static const struct i2c_device_id sx150x_id[] = {
858 {"sx1508q", (kernel_ulong_t) &sx1508q_device_data },
859 {"sx1509q", (kernel_ulong_t) &sx1509q_device_data },
860 {"sx1506q", (kernel_ulong_t) &sx1506q_device_data },
861 {"sx1502q", (kernel_ulong_t) &sx1502q_device_data },
865 static const struct of_device_id sx150x_of_match[] = {
866 { .compatible = "semtech,sx1508q", .data = &sx1508q_device_data },
867 { .compatible = "semtech,sx1509q", .data = &sx1509q_device_data },
868 { .compatible = "semtech,sx1506q", .data = &sx1506q_device_data },
869 { .compatible = "semtech,sx1502q", .data = &sx1502q_device_data },
873 static int sx150x_init_io(struct sx150x_pinctrl *pctl, u8 base, u16 cfg)
878 for (n = 0; err >= 0 && n < (pctl->data->ngpios / 8); ++n)
879 err = sx150x_i2c_write(pctl->client, base - n, cfg >> (n * 8));
883 static int sx150x_reset(struct sx150x_pinctrl *pctl)
887 err = i2c_smbus_write_byte_data(pctl->client,
888 pctl->data->pri.x789.reg_reset,
893 err = i2c_smbus_write_byte_data(pctl->client,
894 pctl->data->pri.x789.reg_reset,
899 static int sx150x_init_hw(struct sx150x_pinctrl *pctl)
903 if (pctl->data->model == SX150X_789 &&
904 of_property_read_bool(pctl->dev->of_node, "semtech,probe-reset")) {
905 err = sx150x_reset(pctl);
910 if (pctl->data->model == SX150X_789)
911 err = sx150x_i2c_write(pctl->client,
912 pctl->data->pri.x789.reg_misc,
914 else if (pctl->data->model == SX150X_456)
915 err = sx150x_i2c_write(pctl->client,
916 pctl->data->pri.x456.reg_advance,
919 err = sx150x_i2c_write(pctl->client,
920 pctl->data->pri.x123.reg_advance,
925 /* Set all pins to work in normal mode */
926 if (pctl->data->model == SX150X_789) {
927 err = sx150x_init_io(pctl,
928 pctl->data->pri.x789.reg_polarity,
932 } else if (pctl->data->model == SX150X_456) {
933 /* Set all pins to work in normal mode */
934 err = sx150x_init_io(pctl,
935 pctl->data->pri.x456.reg_pld_mode,
940 /* Set all pins to work in normal mode */
941 err = sx150x_init_io(pctl,
942 pctl->data->pri.x123.reg_pld_mode,
951 static int sx150x_probe(struct i2c_client *client,
952 const struct i2c_device_id *id)
954 static const u32 i2c_funcs = I2C_FUNC_SMBUS_BYTE_DATA |
955 I2C_FUNC_SMBUS_WRITE_WORD_DATA;
956 struct device *dev = &client->dev;
957 struct sx150x_pinctrl *pctl;
960 if (!i2c_check_functionality(client->adapter, i2c_funcs))
963 pctl = devm_kzalloc(dev, sizeof(*pctl), GFP_KERNEL);
968 pctl->client = client;
971 pctl->data = of_device_get_match_data(dev);
973 pctl->data = (struct sx150x_device_data *)id->driver_data;
978 mutex_init(&pctl->lock);
980 ret = sx150x_init_hw(pctl);
984 /* Register GPIO controller */
985 pctl->gpio.label = devm_kstrdup(dev, client->name, GFP_KERNEL);
986 pctl->gpio.base = -1;
987 pctl->gpio.ngpio = pctl->data->npins;
988 pctl->gpio.get_direction = sx150x_gpio_get_direction;
989 pctl->gpio.direction_input = sx150x_gpio_direction_input;
990 pctl->gpio.direction_output = sx150x_gpio_direction_output;
991 pctl->gpio.get = sx150x_gpio_get;
992 pctl->gpio.set = sx150x_gpio_set;
993 pctl->gpio.set_single_ended = sx150x_gpio_set_single_ended;
994 pctl->gpio.parent = dev;
995 #ifdef CONFIG_OF_GPIO
996 pctl->gpio.of_node = dev->of_node;
998 pctl->gpio.can_sleep = true;
1000 ret = devm_gpiochip_add_data(dev, &pctl->gpio, pctl);
1004 /* Add Interrupt support if an irq is specified */
1005 if (client->irq > 0) {
1006 pctl->irq_chip.name = devm_kstrdup(dev, client->name,
1008 pctl->irq_chip.irq_mask = sx150x_irq_mask;
1009 pctl->irq_chip.irq_unmask = sx150x_irq_unmask;
1010 pctl->irq_chip.irq_set_type = sx150x_irq_set_type;
1011 pctl->irq_chip.irq_bus_lock = sx150x_irq_bus_lock;
1012 pctl->irq_chip.irq_bus_sync_unlock = sx150x_irq_bus_sync_unlock;
1014 pctl->irq.masked = ~0;
1015 pctl->irq.sense = 0;
1016 pctl->irq.dev_masked = ~0;
1017 pctl->irq.dev_sense = 0;
1018 pctl->irq.update = -1;
1020 ret = gpiochip_irqchip_add(&pctl->gpio,
1022 handle_edge_irq, IRQ_TYPE_NONE);
1024 dev_err(dev, "could not connect irqchip to gpiochip\n");
1028 ret = devm_request_threaded_irq(dev, client->irq, NULL,
1029 sx150x_irq_thread_fn,
1030 IRQF_ONESHOT | IRQF_SHARED |
1031 IRQF_TRIGGER_FALLING,
1032 pctl->irq_chip.name, pctl);
1038 pctl->pinctrl_desc.name = "sx150x-pinctrl";
1039 pctl->pinctrl_desc.pctlops = &sx150x_pinctrl_ops;
1040 pctl->pinctrl_desc.confops = &sx150x_pinconf_ops;
1041 pctl->pinctrl_desc.pins = pctl->data->pins;
1042 pctl->pinctrl_desc.npins = pctl->data->npins;
1043 pctl->pinctrl_desc.owner = THIS_MODULE;
1045 pctl->pctldev = pinctrl_register(&pctl->pinctrl_desc, dev, pctl);
1046 if (IS_ERR(pctl->pctldev)) {
1047 dev_err(dev, "Failed to register pinctrl device\n");
1048 return PTR_ERR(pctl->pctldev);
1054 static struct i2c_driver sx150x_driver = {
1056 .name = "sx150x-pinctrl",
1057 .of_match_table = of_match_ptr(sx150x_of_match),
1059 .probe = sx150x_probe,
1060 .id_table = sx150x_id,
1063 static int __init sx150x_init(void)
1065 return i2c_add_driver(&sx150x_driver);
1067 subsys_initcall(sx150x_init);