2 * Copyright (C) 2015 Linaro
3 * Peter Griffin <peter.griffin@linaro.org>
5 * SPDX-License-Identifier: GPL-2.0+
14 static int hi6220_gpio_direction_input(struct udevice
*dev
, unsigned int gpio
)
16 struct gpio_bank
*bank
= dev_get_priv(dev
);
19 data
= readb(bank
->base
+ HI6220_GPIO_DIR
);
21 writeb(data
, bank
->base
+ HI6220_GPIO_DIR
);
26 static int hi6220_gpio_set_value(struct udevice
*dev
, unsigned gpio
,
29 struct gpio_bank
*bank
= dev_get_priv(dev
);
31 writeb(!!value
<< gpio
, bank
->base
+ (BIT(gpio
+ 2)));
35 static int hi6220_gpio_direction_output(struct udevice
*dev
, unsigned gpio
,
38 struct gpio_bank
*bank
= dev_get_priv(dev
);
41 data
= readb(bank
->base
+ HI6220_GPIO_DIR
);
43 writeb(data
, bank
->base
+ HI6220_GPIO_DIR
);
45 hi6220_gpio_set_value(dev
, gpio
, value
);
50 static int hi6220_gpio_get_value(struct udevice
*dev
, unsigned gpio
)
52 struct gpio_bank
*bank
= dev_get_priv(dev
);
54 return !!readb(bank
->base
+ (BIT(gpio
+ 2)));
59 static const struct dm_gpio_ops gpio_hi6220_ops
= {
60 .direction_input
= hi6220_gpio_direction_input
,
61 .direction_output
= hi6220_gpio_direction_output
,
62 .get_value
= hi6220_gpio_get_value
,
63 .set_value
= hi6220_gpio_set_value
,
66 static int hi6220_gpio_probe(struct udevice
*dev
)
68 struct gpio_bank
*bank
= dev_get_priv(dev
);
69 struct hikey_gpio_platdata
*plat
= dev_get_platdata(dev
);
70 struct gpio_dev_priv
*uc_priv
= dev
->uclass_priv
;
73 sprintf(name
, "GPIO%d_", plat
->bank_index
);
79 uc_priv
->bank_name
= str
;
80 uc_priv
->gpio_count
= HI6220_GPIO_PER_BANK
;
82 bank
->base
= (u8
*)plat
->base
;
87 U_BOOT_DRIVER(gpio_hi6220
) = {
88 .name
= "gpio_hi6220",
90 .ops
= &gpio_hi6220_ops
,
91 .probe
= hi6220_gpio_probe
,
92 .priv_auto_alloc_size
= sizeof(struct gpio_bank
),