1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Linaro
4 * Peter Griffin <peter.griffin@linaro.org>
13 static int hi6220_gpio_direction_input(struct udevice
*dev
, unsigned int gpio
)
15 struct gpio_bank
*bank
= dev_get_priv(dev
);
18 data
= readb(bank
->base
+ HI6220_GPIO_DIR
);
20 writeb(data
, bank
->base
+ HI6220_GPIO_DIR
);
25 static int hi6220_gpio_set_value(struct udevice
*dev
, unsigned gpio
,
28 struct gpio_bank
*bank
= dev_get_priv(dev
);
30 writeb(!!value
<< gpio
, bank
->base
+ (BIT(gpio
+ 2)));
34 static int hi6220_gpio_direction_output(struct udevice
*dev
, unsigned gpio
,
37 struct gpio_bank
*bank
= dev_get_priv(dev
);
40 data
= readb(bank
->base
+ HI6220_GPIO_DIR
);
42 writeb(data
, bank
->base
+ HI6220_GPIO_DIR
);
44 hi6220_gpio_set_value(dev
, gpio
, value
);
49 static int hi6220_gpio_get_value(struct udevice
*dev
, unsigned gpio
)
51 struct gpio_bank
*bank
= dev_get_priv(dev
);
53 return !!readb(bank
->base
+ (BIT(gpio
+ 2)));
58 static const struct dm_gpio_ops gpio_hi6220_ops
= {
59 .direction_input
= hi6220_gpio_direction_input
,
60 .direction_output
= hi6220_gpio_direction_output
,
61 .get_value
= hi6220_gpio_get_value
,
62 .set_value
= hi6220_gpio_set_value
,
65 static int hi6220_gpio_probe(struct udevice
*dev
)
67 struct gpio_bank
*bank
= dev_get_priv(dev
);
68 struct hikey_gpio_platdata
*plat
= dev_get_platdata(dev
);
69 struct gpio_dev_priv
*uc_priv
= dev
->uclass_priv
;
72 sprintf(name
, "GPIO%d_", plat
->bank_index
);
78 uc_priv
->bank_name
= str
;
79 uc_priv
->gpio_count
= HI6220_GPIO_PER_BANK
;
81 bank
->base
= (u8
*)plat
->base
;
86 U_BOOT_DRIVER(gpio_hi6220
) = {
87 .name
= "gpio_hi6220",
89 .ops
= &gpio_hi6220_ops
,
90 .probe
= hi6220_gpio_probe
,
91 .priv_auto_alloc_size
= sizeof(struct gpio_bank
),