• Home
  • Raw
  • Download

Lines Matching +full:chip +full:- +full:to +full:- +full:chip

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright 2008 - 2013 Xilinx, Inc.
24 /* Read/Write access to the GPIO registers */
34 * struct xgpio_instance - Stores information about GPIO device
35 * @gc: GPIO chip
51 static inline int xgpio_index(struct xgpio_instance *chip, int gpio) in xgpio_index() argument
53 if (gpio >= chip->gpio_width[0]) in xgpio_index()
59 static inline int xgpio_regoffset(struct xgpio_instance *chip, int gpio) in xgpio_regoffset() argument
61 if (xgpio_index(chip, gpio)) in xgpio_regoffset()
67 static inline int xgpio_offset(struct xgpio_instance *chip, int gpio) in xgpio_offset() argument
69 if (xgpio_index(chip, gpio)) in xgpio_offset()
70 return gpio - chip->gpio_width[0]; in xgpio_offset()
76 * xgpio_get - Read the specified signal of the GPIO device.
77 * @gc: Pointer to gpio_chip device structure.
88 struct xgpio_instance *chip = gpiochip_get_data(gc); in xgpio_get() local
91 val = xgpio_readreg(chip->regs + XGPIO_DATA_OFFSET + in xgpio_get()
92 xgpio_regoffset(chip, gpio)); in xgpio_get()
94 return !!(val & BIT(xgpio_offset(chip, gpio))); in xgpio_get()
98 * xgpio_set - Write the specified signal of the GPIO device.
99 * @gc: Pointer to gpio_chip device structure.
101 * @val: Value to be written to specified signal.
103 * This function writes the specified value in to the specified signal of the
109 struct xgpio_instance *chip = gpiochip_get_data(gc); in xgpio_set() local
110 int index = xgpio_index(chip, gpio); in xgpio_set()
111 int offset = xgpio_offset(chip, gpio); in xgpio_set()
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.
129 * @gc: Pointer to gpio_chip device structure.
130 * @mask: Mask of the GPIOS to modify.
131 * @bits: Value to be wrote on each GPIO
140 struct xgpio_instance *chip = gpiochip_get_data(gc); in xgpio_set_multiple() local
141 int index = xgpio_index(chip, 0); in xgpio_set_multiple()
144 spin_lock_irqsave(&chip->gpio_lock[index], flags); in xgpio_set_multiple()
146 /* Write to GPIO signals */ in xgpio_set_multiple()
147 for (i = 0; i < gc->ngpio; i++) { in xgpio_set_multiple()
150 /* Once finished with an index write it out to the register */ in xgpio_set_multiple()
151 if (index != xgpio_index(chip, 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()
156 index = xgpio_index(chip, i); in xgpio_set_multiple()
157 spin_lock_irqsave(&chip->gpio_lock[index], flags); in xgpio_set_multiple()
160 offset = xgpio_offset(chip, i); 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.
176 * @gc: Pointer to gpio_chip device structure.
180 * 0 - if direction of GPIO signals is set as input
186 struct xgpio_instance *chip = gpiochip_get_data(gc); in xgpio_dir_in() local
187 int index = xgpio_index(chip, gpio); in xgpio_dir_in()
188 int offset = xgpio_offset(chip, gpio); in xgpio_dir_in()
190 spin_lock_irqsave(&chip->gpio_lock[index], flags); 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.
204 * @gc: Pointer to gpio_chip device structure.
206 * @val: Value to be written to specified signal.
211 * If all GPIO signals of GPIO chip is configured as input then it returns
217 struct xgpio_instance *chip = gpiochip_get_data(gc); in xgpio_dir_out() local
218 int index = xgpio_index(chip, gpio); in xgpio_dir_out()
219 int offset = xgpio_offset(chip, gpio); in xgpio_dir_out()
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()
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
243 * @chip: Pointer to GPIO instance
245 static void xgpio_save_regs(struct xgpio_instance *chip) in xgpio_save_regs() argument
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.
261 * @pdev: pointer to the platform device
264 * It returns 0, if the driver is bound to the GPIO device, or
269 struct xgpio_instance *chip; in xgpio_probe() local
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()
275 if (!chip) in xgpio_probe()
276 return -ENOMEM; in xgpio_probe()
278 platform_set_drvdata(pdev, chip); in xgpio_probe()
281 of_property_read_u32(np, "xlnx,dout-default", &chip->gpio_state[0]); 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()
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()
337 xgpio_save_regs(chip); 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",