staticvoid xgpio_write_ch(struct xgpio_instance *chip, int reg, int bit, unsignedlong *a)
{ void __iomem *addr = chip->regs + reg + xgpio_regoffset(chip, bit / 32); unsignedlong value = bitmap_read(a, round_down(bit, 32), 32);
xgpio_writereg(addr, value);
}
staticvoid xgpio_read_ch_all(struct xgpio_instance *chip, int reg, unsignedlong *a)
{ unsignedlong lastbit = find_nth_bit(chip->map, 64, chip->gc.ngpio - 1); int bit;
for (bit = 0; bit <= lastbit ; bit += 32)
xgpio_read_ch(chip, reg, bit, a);
}
staticvoid xgpio_write_ch_all(struct xgpio_instance *chip, int reg, unsignedlong *a)
{ unsignedlong lastbit = find_nth_bit(chip->map, 64, chip->gc.ngpio - 1); int bit;
for (bit = 0; bit <= lastbit ; bit += 32)
xgpio_write_ch(chip, reg, bit, a);
}
/** * xgpio_get - Read the specified signal of the GPIO device. * @gc: Pointer to gpio_chip device structure. * @gpio: GPIO signal number. * * This function reads the specified signal of the GPIO device. * * Return: * 0 if direction of GPIO signals is set as input otherwise it * returns negative error value.
*/ staticint xgpio_get(struct gpio_chip *gc, unsignedint gpio)
{ struct xgpio_instance *chip = gpiochip_get_data(gc); unsignedlong bit = find_nth_bit(chip->map, 64, gpio);
DECLARE_BITMAP(state, 64);
/** * xgpio_set - Write the specified signal of the GPIO device. * @gc: Pointer to gpio_chip device structure. * @gpio: GPIO signal number. * @val: Value to be written to specified signal. * * This function writes the specified value in to the specified signal of the * GPIO device.
*/ staticint xgpio_set(struct gpio_chip *gc, unsignedint gpio, int val)
{ unsignedlong flags; struct xgpio_instance *chip = gpiochip_get_data(gc); unsignedlong bit = find_nth_bit(chip->map, 64, gpio);
raw_spin_lock_irqsave(&chip->gpio_lock, flags);
/* Write to GPIO signal and set its direction to output */
__assign_bit(bit, chip->state, val);
/** * xgpio_set_multiple - Write the specified signals of the GPIO device. * @gc: Pointer to gpio_chip device structure. * @mask: Mask of the GPIOS to modify. * @bits: Value to be wrote on each GPIO * * This function writes the specified values into the specified signals of the * GPIO devices.
*/ staticint xgpio_set_multiple(struct gpio_chip *gc, unsignedlong *mask, unsignedlong *bits)
{
DECLARE_BITMAP(hw_mask, 64);
DECLARE_BITMAP(hw_bits, 64);
DECLARE_BITMAP(state, 64); unsignedlong flags; struct xgpio_instance *chip = gpiochip_get_data(gc);
/** * xgpio_dir_in - Set the direction of the specified GPIO signal as input. * @gc: Pointer to gpio_chip device structure. * @gpio: GPIO signal number. * * Return: * 0 - if direction of GPIO signals is set as input * otherwise it returns negative error value.
*/ staticint xgpio_dir_in(struct gpio_chip *gc, unsignedint gpio)
{ unsignedlong flags; struct xgpio_instance *chip = gpiochip_get_data(gc); unsignedlong bit = find_nth_bit(chip->map, 64, gpio);
raw_spin_lock_irqsave(&chip->gpio_lock, flags);
/* Set the GPIO bit in shadow register and set direction as input */
__set_bit(bit, chip->dir);
xgpio_write_ch(chip, XGPIO_TRI_OFFSET, bit, chip->dir);
/** * xgpio_dir_out - Set the direction of the specified GPIO signal as output. * @gc: Pointer to gpio_chip device structure. * @gpio: GPIO signal number. * @val: Value to be written to specified signal. * * This function sets the direction of specified GPIO signal as output. * * Return: * If all GPIO signals of GPIO chip is configured as input then it returns * error otherwise it returns 0.
*/ staticint xgpio_dir_out(struct gpio_chip *gc, unsignedint gpio, int val)
{ unsignedlong flags; struct xgpio_instance *chip = gpiochip_get_data(gc); unsignedlong bit = find_nth_bit(chip->map, 64, gpio);
raw_spin_lock_irqsave(&chip->gpio_lock, flags);
/* Write state of GPIO signal */
__assign_bit(bit, chip->state, val);
xgpio_write_ch(chip, XGPIO_DATA_OFFSET, bit, chip->state);
/* Clear the GPIO bit in shadow register and set direction as output */
__clear_bit(bit, chip->dir);
xgpio_write_ch(chip, XGPIO_TRI_OFFSET, bit, chip->dir);
/** * xgpio_save_regs - Set initial values of GPIO pins * @chip: Pointer to GPIO instance
*/ staticvoid xgpio_save_regs(struct xgpio_instance *chip)
{
xgpio_write_ch_all(chip, XGPIO_DATA_OFFSET, chip->state);
xgpio_write_ch_all(chip, XGPIO_TRI_OFFSET, chip->dir);
}
staticint xgpio_request(struct gpio_chip *chip, unsignedint offset)
{ int ret;
ret = pm_runtime_get_sync(chip->parent); /* * If the device is already active pm_runtime_get() will return 1 on * success, but gpio_request still needs to return 0.
*/ return ret < 0 ? ret : 0;
}
if (!data) {
dev_dbg(dev, "IRQ not connected\n"); return pm_runtime_force_suspend(dev);
}
if (!irqd_is_wakeup_set(data)) return pm_runtime_force_suspend(dev);
return 0;
}
/** * xgpio_remove - Remove method for the GPIO device. * @pdev: pointer to the platform device * * This function remove gpiochips and frees all the allocated resources. * * Return: 0 always
*/ staticvoid xgpio_remove(struct platform_device *pdev)
{
pm_runtime_get_sync(&pdev->dev);
pm_runtime_put_noidle(&pdev->dev);
pm_runtime_disable(&pdev->dev);
}
/** * xgpio_irq_ack - Acknowledge a child GPIO interrupt. * @irq_data: per IRQ and chip data passed down to chip functions * This currently does nothing, but irq_ack is unconditionally called by * handle_edge_irq and therefore must be defined.
*/ staticvoid xgpio_irq_ack(struct irq_data *irq_data)
{
}
/** * xgpio_irq_mask - Write the specified signal of the GPIO device. * @irq_data: per IRQ and chip data passed down to chip functions
*/ staticvoid xgpio_irq_mask(struct irq_data *irq_data)
{ unsignedlong flags; struct xgpio_instance *chip = irq_data_get_irq_chip_data(irq_data); int irq_offset = irqd_to_hwirq(irq_data); unsignedlong bit = find_nth_bit(chip->map, 64, irq_offset), enable;
u32 mask = BIT(bit / 32), temp;
/** * xgpio_irq_unmask - Write the specified signal of the GPIO device. * @irq_data: per IRQ and chip data passed down to chip functions
*/ staticvoid xgpio_irq_unmask(struct irq_data *irq_data)
{ unsignedlong flags; struct xgpio_instance *chip = irq_data_get_irq_chip_data(irq_data); int irq_offset = irqd_to_hwirq(irq_data); unsignedlong bit = find_nth_bit(chip->map, 64, irq_offset), enable;
u32 mask = BIT(bit / 32), val;
gpiochip_enable_irq(&chip->gc, irq_offset);
raw_spin_lock_irqsave(&chip->gpio_lock, flags);
enable = bitmap_read(chip->enable, round_down(bit, 32), 32); if (enable == 0) { /* Clear any existing per-channel interrupts */
val = xgpio_readreg(chip->regs + XGPIO_IPISR_OFFSET);
val &= mask;
xgpio_writereg(chip->regs + XGPIO_IPISR_OFFSET, val);
/* Update GPIO IRQ read data before enabling interrupt*/
xgpio_read_ch(chip, XGPIO_DATA_OFFSET, bit, chip->last_irq_read);
/* Enable per channel interrupt */
val = xgpio_readreg(chip->regs + XGPIO_IPIER_OFFSET);
val |= mask;
xgpio_writereg(chip->regs + XGPIO_IPIER_OFFSET, val);
}
/** * xgpio_set_irq_type - Write the specified signal of the GPIO device. * @irq_data: Per IRQ and chip data passed down to chip functions * @type: Interrupt type that is to be set for the gpio pin * * Return: * 0 if interrupt type is supported otherwise -EINVAL
*/ staticint xgpio_set_irq_type(struct irq_data *irq_data, unsignedint type)
{ struct xgpio_instance *chip = irq_data_get_irq_chip_data(irq_data); int irq_offset = irqd_to_hwirq(irq_data); unsignedlong bit = find_nth_bit(chip->map, 64, irq_offset);
/* * The Xilinx GPIO hardware provides a single interrupt status * indication for any state change in a given GPIO channel (bank). * Therefore, only rising edge or falling edge triggers are * supported.
*/ switch (type & IRQ_TYPE_SENSE_MASK) { case IRQ_TYPE_EDGE_BOTH:
__set_bit(bit, chip->rising_edge);
__set_bit(bit, chip->falling_edge); break; case IRQ_TYPE_EDGE_RISING:
__set_bit(bit, chip->rising_edge);
__clear_bit(bit, chip->falling_edge); break; case IRQ_TYPE_EDGE_FALLING:
__clear_bit(bit, chip->rising_edge);
__set_bit(bit, chip->falling_edge); break; default: return -EINVAL;
}
/** * xgpio_probe - Probe method for the GPIO device. * @pdev: pointer to the platform device * * Return: * It returns 0, if the driver is bound to the GPIO device, or * a negative value if there is an error.
*/ staticint xgpio_probe(struct platform_device *pdev)
{ struct device *dev = &pdev->dev; struct xgpio_instance *chip; int status = 0;
u32 is_dual = 0;
u32 width[2];
u32 state[2];
u32 dir[2]; struct gpio_irq_chip *girq;
u32 temp;
chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); if (!chip) return -ENOMEM;
platform_set_drvdata(pdev, chip);
/* First, check if the device is dual-channel */
device_property_read_u32(dev, "xlnx,is-dual", &is_dual);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.