Lines Matching +full:pin +full:- +full:val

1 // SPDX-License-Identifier: GPL-2.0
53 * sama5d2_piobu_setup_pin() - prepares a pin for set_direction call
55 * Do not consider pin for tamper detection (normal and backup modes)
56 * Do not consider pin as tamper wakeup interrupt source
58 static int sama5d2_piobu_setup_pin(struct gpio_chip *chip, unsigned int pin) in sama5d2_piobu_setup_pin() argument
63 unsigned int mask = BIT(PIOBU_DET_OFFSET + pin); in sama5d2_piobu_setup_pin()
65 ret = regmap_update_bits(piobu->regmap, PIOBU_BMPR, mask, 0); in sama5d2_piobu_setup_pin()
69 ret = regmap_update_bits(piobu->regmap, PIOBU_NMPR, mask, 0); in sama5d2_piobu_setup_pin()
73 return regmap_update_bits(piobu->regmap, PIOBU_WKPR, mask, 0); in sama5d2_piobu_setup_pin()
77 * sama5d2_piobu_write_value() - writes value & mask at the pin's PIOBU register
79 static int sama5d2_piobu_write_value(struct gpio_chip *chip, unsigned int pin, in sama5d2_piobu_write_value() argument
86 reg = PIOBU_BASE + pin * PIOBU_REG_SIZE; in sama5d2_piobu_write_value()
88 return regmap_update_bits(piobu->regmap, reg, mask, value); in sama5d2_piobu_write_value()
92 * sama5d2_piobu_read_value() - read the value with masking from the pin's PIOBU
95 static int sama5d2_piobu_read_value(struct gpio_chip *chip, unsigned int pin, in sama5d2_piobu_read_value() argument
100 unsigned int val, reg; in sama5d2_piobu_read_value() local
103 reg = PIOBU_BASE + pin * PIOBU_REG_SIZE; in sama5d2_piobu_read_value()
104 ret = regmap_read(piobu->regmap, reg, &val); in sama5d2_piobu_read_value()
108 return val & mask; in sama5d2_piobu_read_value()
112 * sama5d2_piobu_get_direction() - gpiochip get_direction
115 unsigned int pin) in sama5d2_piobu_get_direction() argument
117 int ret = sama5d2_piobu_read_value(chip, pin, PIOBU_DIRECTION); in sama5d2_piobu_get_direction()
127 * sama5d2_piobu_direction_input() - gpiochip direction_input
130 unsigned int pin) in sama5d2_piobu_direction_input() argument
132 return sama5d2_piobu_write_value(chip, pin, PIOBU_DIRECTION, PIOBU_IN); in sama5d2_piobu_direction_input()
136 * sama5d2_piobu_direction_output() - gpiochip direction_output
139 unsigned int pin, int value) in sama5d2_piobu_direction_output() argument
141 unsigned int val = PIOBU_OUT; in sama5d2_piobu_direction_output() local
144 val |= PIOBU_HIGH; in sama5d2_piobu_direction_output()
146 return sama5d2_piobu_write_value(chip, pin, PIOBU_DIRECTION | PIOBU_SOD, in sama5d2_piobu_direction_output()
147 val); in sama5d2_piobu_direction_output()
151 * sama5d2_piobu_get() - gpiochip get
153 static int sama5d2_piobu_get(struct gpio_chip *chip, unsigned int pin) in sama5d2_piobu_get() argument
155 /* if pin is input, read value from PDS else read from SOD */ in sama5d2_piobu_get()
156 int ret = sama5d2_piobu_get_direction(chip, pin); in sama5d2_piobu_get()
159 ret = sama5d2_piobu_read_value(chip, pin, PIOBU_PDS); in sama5d2_piobu_get()
161 ret = sama5d2_piobu_read_value(chip, pin, PIOBU_SOD); in sama5d2_piobu_get()
170 * sama5d2_piobu_set() - gpiochip set
172 static void sama5d2_piobu_set(struct gpio_chip *chip, unsigned int pin, in sama5d2_piobu_set() argument
180 sama5d2_piobu_write_value(chip, pin, PIOBU_SOD, value); in sama5d2_piobu_set()
188 piobu = devm_kzalloc(&pdev->dev, sizeof(*piobu), GFP_KERNEL); in sama5d2_piobu_probe()
190 return -ENOMEM; in sama5d2_piobu_probe()
193 piobu->chip.label = pdev->name; in sama5d2_piobu_probe()
194 piobu->chip.parent = &pdev->dev; in sama5d2_piobu_probe()
195 piobu->chip.owner = THIS_MODULE, in sama5d2_piobu_probe()
196 piobu->chip.get_direction = sama5d2_piobu_get_direction, in sama5d2_piobu_probe()
197 piobu->chip.direction_input = sama5d2_piobu_direction_input, in sama5d2_piobu_probe()
198 piobu->chip.direction_output = sama5d2_piobu_direction_output, in sama5d2_piobu_probe()
199 piobu->chip.get = sama5d2_piobu_get, in sama5d2_piobu_probe()
200 piobu->chip.set = sama5d2_piobu_set, in sama5d2_piobu_probe()
201 piobu->chip.base = -1, in sama5d2_piobu_probe()
202 piobu->chip.ngpio = PIOBU_NUM, in sama5d2_piobu_probe()
203 piobu->chip.can_sleep = 0, in sama5d2_piobu_probe()
205 piobu->regmap = syscon_node_to_regmap(pdev->dev.of_node); in sama5d2_piobu_probe()
206 if (IS_ERR(piobu->regmap)) { in sama5d2_piobu_probe()
207 dev_err(&pdev->dev, "Failed to get syscon regmap %ld\n", in sama5d2_piobu_probe()
208 PTR_ERR(piobu->regmap)); in sama5d2_piobu_probe()
209 return PTR_ERR(piobu->regmap); in sama5d2_piobu_probe()
212 ret = devm_gpiochip_add_data(&pdev->dev, &piobu->chip, piobu); in sama5d2_piobu_probe()
214 dev_err(&pdev->dev, "Failed to add gpiochip %d\n", ret); in sama5d2_piobu_probe()
219 ret = sama5d2_piobu_setup_pin(&piobu->chip, i); in sama5d2_piobu_probe()
221 dev_err(&pdev->dev, "Failed to setup pin: %d %d\n", in sama5d2_piobu_probe()
231 { .compatible = "atmel,sama5d2-secumod" },
238 .name = "sama5d2-piobu",