Lines Matching +full:off +full:- +full:chip

1 // SPDX-License-Identifier: GPL-2.0-or-later
23 static int adp5520_gpio_get_value(struct gpio_chip *chip, unsigned off) in adp5520_gpio_get_value() argument
28 dev = gpiochip_get_data(chip); in adp5520_gpio_get_value()
35 if (test_bit(off, &dev->output)) in adp5520_gpio_get_value()
36 adp5520_read(dev->master, ADP5520_GPIO_OUT, &reg_val); in adp5520_gpio_get_value()
38 adp5520_read(dev->master, ADP5520_GPIO_IN, &reg_val); in adp5520_gpio_get_value()
40 return !!(reg_val & dev->lut[off]); in adp5520_gpio_get_value()
43 static int adp5520_gpio_set_value(struct gpio_chip *chip, in adp5520_gpio_set_value() argument
44 unsigned int off, int val) in adp5520_gpio_set_value() argument
47 dev = gpiochip_get_data(chip); in adp5520_gpio_set_value()
50 return adp5520_set_bits(dev->master, ADP5520_GPIO_OUT, in adp5520_gpio_set_value()
51 dev->lut[off]); in adp5520_gpio_set_value()
53 return adp5520_clr_bits(dev->master, ADP5520_GPIO_OUT, in adp5520_gpio_set_value()
54 dev->lut[off]); in adp5520_gpio_set_value()
57 static int adp5520_gpio_direction_input(struct gpio_chip *chip, unsigned off) in adp5520_gpio_direction_input() argument
60 dev = gpiochip_get_data(chip); in adp5520_gpio_direction_input()
62 clear_bit(off, &dev->output); in adp5520_gpio_direction_input()
64 return adp5520_clr_bits(dev->master, ADP5520_GPIO_CFG_2, in adp5520_gpio_direction_input()
65 dev->lut[off]); in adp5520_gpio_direction_input()
68 static int adp5520_gpio_direction_output(struct gpio_chip *chip, in adp5520_gpio_direction_output() argument
69 unsigned off, int val) in adp5520_gpio_direction_output() argument
73 dev = gpiochip_get_data(chip); in adp5520_gpio_direction_output()
75 set_bit(off, &dev->output); in adp5520_gpio_direction_output()
78 ret |= adp5520_set_bits(dev->master, ADP5520_GPIO_OUT, in adp5520_gpio_direction_output()
79 dev->lut[off]); in adp5520_gpio_direction_output()
81 ret |= adp5520_clr_bits(dev->master, ADP5520_GPIO_OUT, in adp5520_gpio_direction_output()
82 dev->lut[off]); in adp5520_gpio_direction_output()
84 ret |= adp5520_set_bits(dev->master, ADP5520_GPIO_CFG_2, in adp5520_gpio_direction_output()
85 dev->lut[off]); in adp5520_gpio_direction_output()
92 struct adp5520_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev); in adp5520_gpio_probe()
99 dev_err(&pdev->dev, "missing platform data\n"); in adp5520_gpio_probe()
100 return -ENODEV; in adp5520_gpio_probe()
103 if (pdev->id != ID_ADP5520) { in adp5520_gpio_probe()
104 dev_err(&pdev->dev, "only ADP5520 supports GPIO\n"); in adp5520_gpio_probe()
105 return -ENODEV; in adp5520_gpio_probe()
108 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); in adp5520_gpio_probe()
110 return -ENOMEM; in adp5520_gpio_probe()
112 dev->master = pdev->dev.parent; in adp5520_gpio_probe()
115 if (pdata->gpio_en_mask & (1 << i)) in adp5520_gpio_probe()
116 dev->lut[gpios++] = 1 << i; in adp5520_gpio_probe()
119 return -EINVAL; in adp5520_gpio_probe()
121 gc = &dev->gpio_chip; in adp5520_gpio_probe()
122 gc->direction_input = adp5520_gpio_direction_input; in adp5520_gpio_probe()
123 gc->direction_output = adp5520_gpio_direction_output; in adp5520_gpio_probe()
124 gc->get = adp5520_gpio_get_value; in adp5520_gpio_probe()
125 gc->set_rv = adp5520_gpio_set_value; in adp5520_gpio_probe()
126 gc->can_sleep = true; in adp5520_gpio_probe()
128 gc->base = pdata->gpio_start; in adp5520_gpio_probe()
129 gc->ngpio = gpios; in adp5520_gpio_probe()
130 gc->label = pdev->name; in adp5520_gpio_probe()
131 gc->owner = THIS_MODULE; in adp5520_gpio_probe()
133 ret = adp5520_clr_bits(dev->master, ADP5520_GPIO_CFG_1, in adp5520_gpio_probe()
134 pdata->gpio_en_mask); in adp5520_gpio_probe()
136 if (pdata->gpio_en_mask & ADP5520_GPIO_C3) in adp5520_gpio_probe()
139 if (pdata->gpio_en_mask & ADP5520_GPIO_R3) in adp5520_gpio_probe()
143 ret = adp5520_set_bits(dev->master, ADP5520_LED_CONTROL, in adp5520_gpio_probe()
146 ret |= adp5520_set_bits(dev->master, ADP5520_GPIO_PULLUP, in adp5520_gpio_probe()
147 pdata->gpio_pullup_mask); in adp5520_gpio_probe()
150 dev_err(&pdev->dev, "failed to write\n"); in adp5520_gpio_probe()
154 return devm_gpiochip_add_data(&pdev->dev, &dev->gpio_chip, dev); in adp5520_gpio_probe()
159 .name = "adp5520-gpio",
169 MODULE_ALIAS("platform:adp5520-gpio");