Lines Matching +full:dual +full:- +full:direction

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright 2008 - 2013 Xilinx, Inc.
20 #define XGPIO_TRI_OFFSET (0x4) /* I/O direction register */
34 * struct xgpio_instance - Stores information about GPIO device
39 * @gpio_dir: GPIO direction shadow register
53 if (gpio >= chip->gpio_width[0]) in xgpio_index()
70 return gpio - chip->gpio_width[0]; in xgpio_offset()
76 * xgpio_get - Read the specified signal of the GPIO device.
83 * 0 if direction of GPIO signals is set as input otherwise it
91 val = xgpio_readreg(chip->regs + XGPIO_DATA_OFFSET + in xgpio_get()
98 * xgpio_set - Write the specified signal of the GPIO device.
113 spin_lock_irqsave(&chip->gpio_lock[index], flags); in xgpio_set()
115 /* Write to GPIO signal and set its direction to output */ in xgpio_set()
117 chip->gpio_state[index] |= BIT(offset); in xgpio_set()
119 chip->gpio_state[index] &= ~BIT(offset); in xgpio_set()
121 xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + in xgpio_set()
122 xgpio_regoffset(chip, gpio), chip->gpio_state[index]); in xgpio_set()
124 spin_unlock_irqrestore(&chip->gpio_lock[index], flags); in xgpio_set()
128 * xgpio_set_multiple - Write the specified signals of the GPIO device.
144 spin_lock_irqsave(&chip->gpio_lock[index], flags); in xgpio_set_multiple()
147 for (i = 0; i < gc->ngpio; i++) { in xgpio_set_multiple()
152 xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + in xgpio_set_multiple()
154 chip->gpio_state[index]); in xgpio_set_multiple()
155 spin_unlock_irqrestore(&chip->gpio_lock[index], flags); in xgpio_set_multiple()
157 spin_lock_irqsave(&chip->gpio_lock[index], flags); in xgpio_set_multiple()
162 chip->gpio_state[index] |= BIT(offset); in xgpio_set_multiple()
164 chip->gpio_state[index] &= ~BIT(offset); in xgpio_set_multiple()
168 xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + in xgpio_set_multiple()
169 index * XGPIO_CHANNEL_OFFSET, chip->gpio_state[index]); in xgpio_set_multiple()
171 spin_unlock_irqrestore(&chip->gpio_lock[index], flags); in xgpio_set_multiple()
175 * xgpio_dir_in - Set the direction of the specified GPIO signal as input.
180 * 0 - if direction of GPIO signals is set as input
190 spin_lock_irqsave(&chip->gpio_lock[index], flags); in xgpio_dir_in()
192 /* Set the GPIO bit in shadow register and set direction as input */ in xgpio_dir_in()
193 chip->gpio_dir[index] |= BIT(offset); in xgpio_dir_in()
194 xgpio_writereg(chip->regs + XGPIO_TRI_OFFSET + in xgpio_dir_in()
195 xgpio_regoffset(chip, gpio), chip->gpio_dir[index]); in xgpio_dir_in()
197 spin_unlock_irqrestore(&chip->gpio_lock[index], flags); in xgpio_dir_in()
203 * xgpio_dir_out - Set the direction of the specified GPIO signal as output.
208 * This function sets the direction of specified GPIO signal as output.
221 spin_lock_irqsave(&chip->gpio_lock[index], flags); in xgpio_dir_out()
225 chip->gpio_state[index] |= BIT(offset); in xgpio_dir_out()
227 chip->gpio_state[index] &= ~BIT(offset); in xgpio_dir_out()
228 xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + in xgpio_dir_out()
229 xgpio_regoffset(chip, gpio), chip->gpio_state[index]); in xgpio_dir_out()
231 /* Clear the GPIO bit in shadow register and set direction as output */ in xgpio_dir_out()
232 chip->gpio_dir[index] &= ~BIT(offset); in xgpio_dir_out()
233 xgpio_writereg(chip->regs + XGPIO_TRI_OFFSET + in xgpio_dir_out()
234 xgpio_regoffset(chip, gpio), chip->gpio_dir[index]); in xgpio_dir_out()
236 spin_unlock_irqrestore(&chip->gpio_lock[index], flags); in xgpio_dir_out()
242 * xgpio_save_regs - Set initial values of GPIO pins
247 xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET, chip->gpio_state[0]); in xgpio_save_regs()
248 xgpio_writereg(chip->regs + XGPIO_TRI_OFFSET, chip->gpio_dir[0]); in xgpio_save_regs()
250 if (!chip->gpio_width[1]) in xgpio_save_regs()
253 xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + XGPIO_CHANNEL_OFFSET, in xgpio_save_regs()
254 chip->gpio_state[1]); in xgpio_save_regs()
255 xgpio_writereg(chip->regs + XGPIO_TRI_OFFSET + XGPIO_CHANNEL_OFFSET, in xgpio_save_regs()
256 chip->gpio_dir[1]); in xgpio_save_regs()
260 * xgpio_of_probe - Probe method for the GPIO device.
271 struct device_node *np = pdev->dev.of_node; in xgpio_probe()
274 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL); in xgpio_probe()
276 return -ENOMEM; in xgpio_probe()
281 of_property_read_u32(np, "xlnx,dout-default", &chip->gpio_state[0]); in xgpio_probe()
283 /* Update GPIO direction shadow register with default value */ in xgpio_probe()
284 if (of_property_read_u32(np, "xlnx,tri-default", &chip->gpio_dir[0])) in xgpio_probe()
285 chip->gpio_dir[0] = 0xFFFFFFFF; in xgpio_probe()
291 if (of_property_read_u32(np, "xlnx,gpio-width", &chip->gpio_width[0])) in xgpio_probe()
292 chip->gpio_width[0] = 32; in xgpio_probe()
294 spin_lock_init(&chip->gpio_lock[0]); in xgpio_probe()
296 if (of_property_read_u32(np, "xlnx,is-dual", &is_dual)) in xgpio_probe()
301 of_property_read_u32(np, "xlnx,dout-default-2", in xgpio_probe()
302 &chip->gpio_state[1]); in xgpio_probe()
304 /* Update GPIO direction shadow register with default value */ in xgpio_probe()
305 if (of_property_read_u32(np, "xlnx,tri-default-2", in xgpio_probe()
306 &chip->gpio_dir[1])) in xgpio_probe()
307 chip->gpio_dir[1] = 0xFFFFFFFF; in xgpio_probe()
313 if (of_property_read_u32(np, "xlnx,gpio2-width", in xgpio_probe()
314 &chip->gpio_width[1])) in xgpio_probe()
315 chip->gpio_width[1] = 32; in xgpio_probe()
317 spin_lock_init(&chip->gpio_lock[1]); in xgpio_probe()
320 chip->gc.base = -1; in xgpio_probe()
321 chip->gc.ngpio = chip->gpio_width[0] + chip->gpio_width[1]; in xgpio_probe()
322 chip->gc.parent = &pdev->dev; in xgpio_probe()
323 chip->gc.direction_input = xgpio_dir_in; in xgpio_probe()
324 chip->gc.direction_output = xgpio_dir_out; in xgpio_probe()
325 chip->gc.get = xgpio_get; in xgpio_probe()
326 chip->gc.set = xgpio_set; in xgpio_probe()
327 chip->gc.set_multiple = xgpio_set_multiple; in xgpio_probe()
329 chip->gc.label = dev_name(&pdev->dev); in xgpio_probe()
331 chip->regs = devm_platform_ioremap_resource(pdev, 0); in xgpio_probe()
332 if (IS_ERR(chip->regs)) { in xgpio_probe()
333 dev_err(&pdev->dev, "failed to ioremap memory resource\n"); in xgpio_probe()
334 return PTR_ERR(chip->regs); in xgpio_probe()
339 status = devm_gpiochip_add_data(&pdev->dev, &chip->gc, chip); in xgpio_probe()
341 dev_err(&pdev->dev, "failed to add GPIO chip\n"); in xgpio_probe()
349 { .compatible = "xlnx,xps-gpio-1.00.a", },
358 .name = "gpio-xilinx",