Lines Matching +full:gpio +full:- +full:dir

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * GPIO driver for Fintek and Nuvoton Super-I/O chips
5 * Copyright (C) 2010-2013 LaCie
10 #define DRVNAME "gpio-f7188x"
17 #include <linux/gpio/driver.h>
21 * Super-I/O registers
26 #define SIO_UNLOCK_KEY 0x87 /* Key to enable Super-I/O */
27 #define SIO_LOCK_KEY 0xAA /* Key to disable Super-I/O */
46 #define SIO_LD_GPIO_FINTEK 0x06 /* GPIO logical device */
53 #define SIO_LD_GPIO_NUVOTON 0x07 /* GPIO logical device */
99 * Super-I/O functions.
131 return -EBUSY; in superio_enter()
154 * GPIO chip.
177 .base = -1, \
187 /* Output mode register (0:open drain 1:push-pull). */
194 F7188X_GPIO_BANK(6, 0xF0, DRVNAME "-0"),
195 F7188X_GPIO_BANK(8, 0xE0, DRVNAME "-1"),
196 F7188X_GPIO_BANK(8, 0xD0, DRVNAME "-2"),
197 F7188X_GPIO_BANK(8, 0xC0, DRVNAME "-3"),
198 F7188X_GPIO_BANK(8, 0xB0, DRVNAME "-4"),
199 F7188X_GPIO_BANK(5, 0xA0, DRVNAME "-5"),
200 F7188X_GPIO_BANK(6, 0x90, DRVNAME "-6"),
204 F7188X_GPIO_BANK(6, 0xF0, DRVNAME "-0"),
205 F7188X_GPIO_BANK(8, 0xE0, DRVNAME "-1"),
206 F7188X_GPIO_BANK(8, 0xD0, DRVNAME "-2"),
207 F7188X_GPIO_BANK(8, 0xC0, DRVNAME "-3"),
208 F7188X_GPIO_BANK(8, 0xB0, DRVNAME "-4"),
209 F7188X_GPIO_BANK(5, 0xA0, DRVNAME "-5"),
210 F7188X_GPIO_BANK(8, 0x90, DRVNAME "-6"),
211 F7188X_GPIO_BANK(8, 0x80, DRVNAME "-7"),
215 F7188X_GPIO_BANK(8, 0xF0, DRVNAME "-0"),
216 F7188X_GPIO_BANK(8, 0xE0, DRVNAME "-1"),
217 F7188X_GPIO_BANK(8, 0xD0, DRVNAME "-2"),
218 F7188X_GPIO_BANK(4, 0xC0, DRVNAME "-3"),
219 F7188X_GPIO_BANK(4, 0xB0, DRVNAME "-4"),
223 F7188X_GPIO_BANK(7, 0xF0, DRVNAME "-0"),
224 F7188X_GPIO_BANK(7, 0xE0, DRVNAME "-1"),
225 F7188X_GPIO_BANK(8, 0xD0, DRVNAME "-2"),
226 F7188X_GPIO_BANK(8, 0xC0, DRVNAME "-3"),
227 F7188X_GPIO_BANK(8, 0xB0, DRVNAME "-4"),
228 F7188X_GPIO_BANK(5, 0xA0, DRVNAME "-5"),
229 F7188X_GPIO_BANK(8, 0x90, DRVNAME "-6"),
230 F7188X_GPIO_BANK(8, 0x80, DRVNAME "-7"),
234 F7188X_GPIO_BANK(7, 0xF0, DRVNAME "-0"),
235 F7188X_GPIO_BANK(7, 0xE0, DRVNAME "-1"),
236 F7188X_GPIO_BANK(8, 0xD0, DRVNAME "-2"),
237 F7188X_GPIO_BANK(8, 0xC0, DRVNAME "-3"),
238 F7188X_GPIO_BANK(8, 0xB0, DRVNAME "-4"),
239 F7188X_GPIO_BANK(5, 0xA0, DRVNAME "-5"),
240 F7188X_GPIO_BANK(8, 0x90, DRVNAME "-6"),
241 F7188X_GPIO_BANK(8, 0x80, DRVNAME "-7"),
245 F7188X_GPIO_BANK(8, 0xF0, DRVNAME "-0"),
246 F7188X_GPIO_BANK(8, 0xE0, DRVNAME "-1"),
247 F7188X_GPIO_BANK(8, 0xD0, DRVNAME "-2"),
248 F7188X_GPIO_BANK(8, 0xC0, DRVNAME "-3"),
249 F7188X_GPIO_BANK(8, 0xB0, DRVNAME "-4"),
250 F7188X_GPIO_BANK(8, 0xA0, DRVNAME "-5"),
251 F7188X_GPIO_BANK(8, 0x90, DRVNAME "-6"),
252 F7188X_GPIO_BANK(8, 0x80, DRVNAME "-7"),
253 F7188X_GPIO_BANK(8, 0x88, DRVNAME "-8"),
258 F7188X_GPIO_BANK(8, 0xF0, DRVNAME "-0"),
259 F7188X_GPIO_BANK(8, 0xE0, DRVNAME "-1"),
260 F7188X_GPIO_BANK(8, 0xD0, DRVNAME "-2"),
261 F7188X_GPIO_BANK(8, 0xA0, DRVNAME "-3"),
262 F7188X_GPIO_BANK(8, 0x90, DRVNAME "-4"),
263 F7188X_GPIO_BANK(8, 0x80, DRVNAME "-5"),
264 F7188X_GPIO_BANK(8, 0x98, DRVNAME "-6"),
268 F7188X_GPIO_BANK(8, 0xF0, DRVNAME "-0"),
269 F7188X_GPIO_BANK(8, 0xE0, DRVNAME "-1"),
270 F7188X_GPIO_BANK(8, 0xD0, DRVNAME "-2"),
271 F7188X_GPIO_BANK(8, 0xC0, DRVNAME "-3"),
272 F7188X_GPIO_BANK(8, 0xB0, DRVNAME "-4"),
273 F7188X_GPIO_BANK(8, 0xA0, DRVNAME "-5"),
274 F7188X_GPIO_BANK(5, 0x90, DRVNAME "-6"),
278 F7188X_GPIO_BANK(8, 0xE0, DRVNAME "-0"),
279 F7188X_GPIO_BANK(8, 0xE4, DRVNAME "-1"),
280 F7188X_GPIO_BANK(8, 0xE8, DRVNAME "-2"),
281 F7188X_GPIO_BANK(8, 0xEC, DRVNAME "-3"),
282 F7188X_GPIO_BANK(8, 0xF0, DRVNAME "-4"),
283 F7188X_GPIO_BANK(8, 0xF4, DRVNAME "-5"),
284 F7188X_GPIO_BANK(8, 0xF8, DRVNAME "-6"),
285 F7188X_GPIO_BANK(8, 0xFC, DRVNAME "-7"),
292 struct f7188x_sio *sio = bank->data->sio; in f7188x_gpio_get_direction()
293 u8 dir; in f7188x_gpio_get_direction() local
295 err = superio_enter(sio->addr); in f7188x_gpio_get_direction()
298 superio_select(sio->addr, sio->device); in f7188x_gpio_get_direction()
300 dir = superio_inb(sio->addr, f7188x_gpio_dir(bank->regbase)); in f7188x_gpio_get_direction()
302 superio_exit(sio->addr); in f7188x_gpio_get_direction()
304 if (f7188x_gpio_dir_invert(sio->type)) in f7188x_gpio_get_direction()
305 dir = ~dir; in f7188x_gpio_get_direction()
307 if (dir & BIT(offset)) in f7188x_gpio_get_direction()
317 struct f7188x_sio *sio = bank->data->sio; in f7188x_gpio_direction_in()
318 u8 dir; in f7188x_gpio_direction_in() local
320 err = superio_enter(sio->addr); in f7188x_gpio_direction_in()
323 superio_select(sio->addr, sio->device); in f7188x_gpio_direction_in()
325 dir = superio_inb(sio->addr, f7188x_gpio_dir(bank->regbase)); in f7188x_gpio_direction_in()
327 if (f7188x_gpio_dir_invert(sio->type)) in f7188x_gpio_direction_in()
328 dir |= BIT(offset); in f7188x_gpio_direction_in()
330 dir &= ~BIT(offset); in f7188x_gpio_direction_in()
331 superio_outb(sio->addr, f7188x_gpio_dir(bank->regbase), dir); in f7188x_gpio_direction_in()
333 superio_exit(sio->addr); in f7188x_gpio_direction_in()
342 struct f7188x_sio *sio = bank->data->sio; in f7188x_gpio_get()
343 u8 dir, data; in f7188x_gpio_get() local
345 err = superio_enter(sio->addr); in f7188x_gpio_get()
348 superio_select(sio->addr, sio->device); in f7188x_gpio_get()
350 dir = superio_inb(sio->addr, f7188x_gpio_dir(bank->regbase)); in f7188x_gpio_get()
351 dir = !!(dir & BIT(offset)); in f7188x_gpio_get()
352 if (f7188x_gpio_data_single(sio->type) || dir) in f7188x_gpio_get()
353 data = superio_inb(sio->addr, f7188x_gpio_data_out(bank->regbase)); in f7188x_gpio_get()
355 data = superio_inb(sio->addr, f7188x_gpio_data_in(bank->regbase)); in f7188x_gpio_get()
357 superio_exit(sio->addr); in f7188x_gpio_get()
367 struct f7188x_sio *sio = bank->data->sio; in f7188x_gpio_direction_out()
368 u8 dir, data_out; in f7188x_gpio_direction_out() local
370 err = superio_enter(sio->addr); in f7188x_gpio_direction_out()
373 superio_select(sio->addr, sio->device); in f7188x_gpio_direction_out()
375 data_out = superio_inb(sio->addr, f7188x_gpio_data_out(bank->regbase)); in f7188x_gpio_direction_out()
380 superio_outb(sio->addr, f7188x_gpio_data_out(bank->regbase), data_out); in f7188x_gpio_direction_out()
382 dir = superio_inb(sio->addr, f7188x_gpio_dir(bank->regbase)); in f7188x_gpio_direction_out()
383 if (f7188x_gpio_dir_invert(sio->type)) in f7188x_gpio_direction_out()
384 dir &= ~BIT(offset); in f7188x_gpio_direction_out()
386 dir |= BIT(offset); in f7188x_gpio_direction_out()
387 superio_outb(sio->addr, f7188x_gpio_dir(bank->regbase), dir); in f7188x_gpio_direction_out()
389 superio_exit(sio->addr); in f7188x_gpio_direction_out()
398 struct f7188x_sio *sio = bank->data->sio; in f7188x_gpio_set()
401 err = superio_enter(sio->addr); in f7188x_gpio_set()
404 superio_select(sio->addr, sio->device); in f7188x_gpio_set()
406 data_out = superio_inb(sio->addr, f7188x_gpio_data_out(bank->regbase)); in f7188x_gpio_set()
411 superio_outb(sio->addr, f7188x_gpio_data_out(bank->regbase), data_out); in f7188x_gpio_set()
413 superio_exit(sio->addr); in f7188x_gpio_set()
422 struct f7188x_sio *sio = bank->data->sio; in f7188x_gpio_set_config()
427 return -ENOTSUPP; in f7188x_gpio_set_config()
429 err = superio_enter(sio->addr); in f7188x_gpio_set_config()
432 superio_select(sio->addr, sio->device); in f7188x_gpio_set_config()
434 data = superio_inb(sio->addr, f7188x_gpio_out_mode(bank->regbase)); in f7188x_gpio_set_config()
439 superio_outb(sio->addr, f7188x_gpio_out_mode(bank->regbase), data); in f7188x_gpio_set_config()
441 superio_exit(sio->addr); in f7188x_gpio_set_config()
453 struct f7188x_sio *sio = dev_get_platdata(&pdev->dev); in f7188x_gpio_probe()
456 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); in f7188x_gpio_probe()
458 return -ENOMEM; in f7188x_gpio_probe()
460 switch (sio->type) { in f7188x_gpio_probe()
462 data->nr_bank = ARRAY_SIZE(f71869_gpio_bank); in f7188x_gpio_probe()
463 data->bank = f71869_gpio_bank; in f7188x_gpio_probe()
466 data->nr_bank = ARRAY_SIZE(f71869a_gpio_bank); in f7188x_gpio_probe()
467 data->bank = f71869a_gpio_bank; in f7188x_gpio_probe()
470 data->nr_bank = ARRAY_SIZE(f71882_gpio_bank); in f7188x_gpio_probe()
471 data->bank = f71882_gpio_bank; in f7188x_gpio_probe()
474 data->nr_bank = ARRAY_SIZE(f71889a_gpio_bank); in f7188x_gpio_probe()
475 data->bank = f71889a_gpio_bank; in f7188x_gpio_probe()
478 data->nr_bank = ARRAY_SIZE(f71889_gpio_bank); in f7188x_gpio_probe()
479 data->bank = f71889_gpio_bank; in f7188x_gpio_probe()
482 data->nr_bank = ARRAY_SIZE(f81866_gpio_bank); in f7188x_gpio_probe()
483 data->bank = f81866_gpio_bank; in f7188x_gpio_probe()
486 data->nr_bank = ARRAY_SIZE(f81804_gpio_bank); in f7188x_gpio_probe()
487 data->bank = f81804_gpio_bank; in f7188x_gpio_probe()
490 data->nr_bank = ARRAY_SIZE(f81865_gpio_bank); in f7188x_gpio_probe()
491 data->bank = f81865_gpio_bank; in f7188x_gpio_probe()
494 data->nr_bank = ARRAY_SIZE(nct6126d_gpio_bank); in f7188x_gpio_probe()
495 data->bank = nct6126d_gpio_bank; in f7188x_gpio_probe()
498 return -ENODEV; in f7188x_gpio_probe()
500 data->sio = sio; in f7188x_gpio_probe()
504 /* For each GPIO bank, register a GPIO chip. */ in f7188x_gpio_probe()
505 for (i = 0; i < data->nr_bank; i++) { in f7188x_gpio_probe()
506 struct f7188x_gpio_bank *bank = &data->bank[i]; in f7188x_gpio_probe()
508 bank->chip.parent = &pdev->dev; in f7188x_gpio_probe()
509 bank->data = data; in f7188x_gpio_probe()
511 err = devm_gpiochip_add_data(&pdev->dev, &bank->chip, bank); in f7188x_gpio_probe()
513 dev_err(&pdev->dev, in f7188x_gpio_probe()
533 err = -ENODEV; in f7188x_find()
535 sio->device = SIO_LD_GPIO_FINTEK; in f7188x_find()
539 sio->type = f71869; in f7188x_find()
542 sio->type = f71869a; in f7188x_find()
545 sio->type = f71882fg; in f7188x_find()
548 sio->type = f71889a; in f7188x_find()
551 sio->type = f71889f; in f7188x_find()
554 sio->type = f81866; in f7188x_find()
557 sio->type = f81804; in f7188x_find()
560 sio->type = f81865; in f7188x_find()
563 sio->device = SIO_LD_GPIO_NUVOTON; in f7188x_find()
564 sio->type = nct6126d; in f7188x_find()
572 if (sio->type != nct6126d) { in f7188x_find()
580 sio->addr = addr; in f7188x_find()
583 pr_info("Found %s at %#x\n", f7188x_names[sio->type], (unsigned int)addr); in f7188x_find()
584 if (sio->type != nct6126d) in f7188x_find()
599 f7188x_gpio_pdev = platform_device_alloc(DRVNAME, -1); in f7188x_gpio_device_add()
601 return -ENOMEM; in f7188x_gpio_device_add()
625 * Try to match a supported Fintek device by reading the (hard-wired)
644 return -ENODEV; in f7188x_gpio_init()
664 MODULE_DESCRIPTION("GPIO driver for Super-I/O chips F71869, F71869A, F71882FG, F71889A, F71889F and…