18 #include <linux/module.h>
23 #include <linux/bitops.h>
64 #define VT8500_BANK(__en, __dir, __out, __in, __ngpio) \
129 #define to_vt8500(__chip) container_of(__chip, struct vt8500_gpio_chip, chip)
131 static int vt8500_gpio_request(
struct gpio_chip *
chip,
unsigned offset)
141 writel_relaxed(val, vt8500_chip->
base + vt8500_chip->
regs->en);
146 static void vt8500_gpio_free(
struct gpio_chip *
chip,
unsigned offset)
156 writel_relaxed(val, vt8500_chip->
base + vt8500_chip->
regs->en);
159 static int vt8500_gpio_direction_input(
struct gpio_chip *chip,
unsigned offset)
165 writel_relaxed(val, vt8500_chip->
base + vt8500_chip->
regs->dir);
170 static int vt8500_gpio_direction_output(
struct gpio_chip *chip,
unsigned offset,
177 writel_relaxed(val, vt8500_chip->
base + vt8500_chip->
regs->dir);
181 vt8500_chip->
regs->data_out);
183 writel_relaxed(val, vt8500_chip->
base +
184 vt8500_chip->
regs->data_out);
189 static int vt8500_gpio_get_value(
struct gpio_chip *chip,
unsigned offset)
197 static void vt8500_gpio_set_value(
struct gpio_chip *chip,
unsigned offset,
203 vt8500_chip->
regs->data_out);
209 writel_relaxed(val, vt8500_chip->
base + vt8500_chip->
regs->data_out);
212 static int vt8500_of_xlate(
struct gpio_chip *
gc,
217 *flags = gpiospec->
args[2];
219 return gpiospec->
args[1];
226 struct gpio_chip *
chip;
234 pr_err(
"%s: failed to allocate chip memory\n", __func__);
239 vtchip[
i].
base = base;
242 chip = &vtchip[
i].
chip;
244 chip->of_xlate = vt8500_of_xlate;
245 chip->of_gpio_n_cells = 3;
246 chip->of_node = pdev->
dev.of_node;
248 chip->request = vt8500_gpio_request;
249 chip->free = vt8500_gpio_free;
250 chip->direction_input = vt8500_gpio_direction_input;
251 chip->direction_output = vt8500_gpio_direction_output;
252 chip->get = vt8500_gpio_get_value;
253 chip->set = vt8500_gpio_set_value;
255 chip->base = pin_cnt;
256 chip->ngpio = data->
banks[
i].ngpio;
258 pin_cnt += data->
banks[
i].ngpio;
266 { .compatible =
"via,vt8500-gpio", .data = &vt8500_data, },
267 { .compatible =
"wm,wm8505-gpio", .data = &wm8505_data, },
268 { .compatible =
"wm,wm8650-gpio", .data = &wm8650_data, },
280 dev_err(&pdev->
dev,
"Failed to find gpio controller\n");
284 np = pdev->
dev.of_node;
286 dev_err(&pdev->
dev,
"Missing GPIO description in devicetree\n");
292 dev_err(&pdev->
dev,
"Unable to map GPIO registers\n");
297 vt8500_add_chips(pdev, gpio_base, of_id->
data);
303 .probe = vt8500_gpio_probe,
305 .name =
"vt8500-gpio",
307 .of_match_table = vt8500_gpio_dt_ids,