1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 #include <device/mmio.h>
4 #include <console/console.h>
5 #include <soc/ti/am335x/gpio.h>
8 static struct am335x_gpio_regs
*gpio_regs_and_bit(unsigned int gpio
,
11 unsigned int bank
= gpio
/ AM335X_GPIO_BITS_PER_BANK
;
13 if (bank
>= ARRAY_SIZE(am335x_gpio_banks
)) {
14 printk(BIOS_ERR
, "Bad gpio index %d.\n", gpio
);
17 *bit
= 1 << (gpio
% 32);
18 return am335x_gpio_banks
[bank
];
21 void am335x_disable_gpio_irqs(void)
25 for (i
= 0; i
< ARRAY_SIZE(am335x_gpio_banks
); i
++)
26 write32(&am335x_gpio_banks
[i
]->irqstatus_clr_0
, 0xffffffff);
29 int gpio_direction_input(unsigned int gpio
)
32 struct am335x_gpio_regs
*regs
= gpio_regs_and_bit(gpio
, &bit
);
36 setbits32(®s
->oe
, bit
);
40 int gpio_direction_output(unsigned int gpio
, int value
)
43 struct am335x_gpio_regs
*regs
= gpio_regs_and_bit(gpio
, &bit
);
48 write32(®s
->setdataout
, bit
);
50 write32(®s
->cleardataout
, bit
);
51 clrbits32(®s
->oe
, bit
);
55 int gpio_get_value(unsigned int gpio
)
58 struct am335x_gpio_regs
*regs
= gpio_regs_and_bit(gpio
, &bit
);
62 return (read32(®s
->datain
) & bit
) ? 1 : 0;
65 int gpio_set_value(unsigned int gpio
, int value
)
68 struct am335x_gpio_regs
*regs
= gpio_regs_and_bit(gpio
, &bit
);
73 write32(®s
->setdataout
, bit
);
75 write32(®s
->cleardataout
, bit
);