Skip to content

Commit 0588504

Browse files
aborzeszBartosz Golaszewski
authored andcommitted
gpio: graniterapids: Determine if GPIO pad can be used by driver
Add check of HOSTSW_MODE bit to determine if GPIO pad can be used by the driver. Cc: [email protected] Signed-off-by: Alan Borzeszkowski <[email protected]> Signed-off-by: Mika Westerberg <[email protected]> Acked-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 15636b0 commit 0588504

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

drivers/gpio/gpio-graniterapids.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#define GNR_GPI_STATUS_OFFSET 0x14
3838
#define GNR_GPI_ENABLE_OFFSET 0x24
3939

40+
#define GNR_CFG_DW_HOSTSW_MODE BIT(27)
4041
#define GNR_CFG_DW_RX_MASK GENMASK(23, 22)
4142
#define GNR_CFG_DW_RX_DISABLE FIELD_PREP(GNR_CFG_DW_RX_MASK, 2)
4243
#define GNR_CFG_DW_RX_EDGE FIELD_PREP(GNR_CFG_DW_RX_MASK, 1)
@@ -90,6 +91,20 @@ static int gnr_gpio_configure_line(struct gpio_chip *gc, unsigned int gpio,
9091
return 0;
9192
}
9293

94+
static int gnr_gpio_request(struct gpio_chip *gc, unsigned int gpio)
95+
{
96+
struct gnr_gpio *priv = gpiochip_get_data(gc);
97+
u32 dw;
98+
99+
dw = readl(gnr_gpio_get_padcfg_addr(priv, gpio));
100+
if (!(dw & GNR_CFG_DW_HOSTSW_MODE)) {
101+
dev_warn(gc->parent, "GPIO %u is not owned by host", gpio);
102+
return -EBUSY;
103+
}
104+
105+
return 0;
106+
}
107+
93108
static int gnr_gpio_get(struct gpio_chip *gc, unsigned int gpio)
94109
{
95110
const struct gnr_gpio *priv = gpiochip_get_data(gc);
@@ -141,6 +156,7 @@ static int gnr_gpio_direction_output(struct gpio_chip *gc, unsigned int gpio, in
141156

142157
static const struct gpio_chip gnr_gpio_chip = {
143158
.owner = THIS_MODULE,
159+
.request = gnr_gpio_request,
144160
.get = gnr_gpio_get,
145161
.set = gnr_gpio_set,
146162
.get_direction = gnr_gpio_get_direction,

0 commit comments

Comments
 (0)