Lines Matching +full:device +full:- +full:id +full:- +full:base

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"
21 * Super-I/O registers
23 #define SIO_LDSEL 0x07 /* Logical device select */
24 #define SIO_DEVID 0x20 /* Device ID (2 bytes) */
26 #define SIO_UNLOCK_KEY 0x87 /* Key to enable Super-I/O */
27 #define SIO_LOCK_KEY 0xAA /* Key to disable Super-I/O */
32 #define SIO_FINTEK_DEVREV 0x22 /* Fintek Device revision */
33 #define SIO_FINTEK_MANID 0x23 /* Fintek ID (2 bytes) */
35 #define SIO_FINTEK_ID 0x1934 /* Manufacturer ID */
37 #define SIO_F71869_ID 0x0814 /* F71869 chipset ID */
38 #define SIO_F71869A_ID 0x1007 /* F71869A chipset ID */
39 #define SIO_F71882_ID 0x0541 /* F71882 chipset ID */
40 #define SIO_F71889_ID 0x0909 /* F71889 chipset ID */
41 #define SIO_F71889A_ID 0x1005 /* F71889A chipset ID */
42 #define SIO_F81866_ID 0x1010 /* F81866 chipset ID */
43 #define SIO_F81804_ID 0x1502 /* F81804 chipset ID, same for F81966 */
44 #define SIO_F81865_ID 0x0704 /* F81865 chipset ID */
46 #define SIO_LD_GPIO_FINTEK 0x06 /* GPIO logical device */
51 #define SIO_NCT6126D_ID 0xD283 /* NCT6126D chipset ID */
53 #define SIO_LD_GPIO_NUVOTON 0x07 /* GPIO logical device */
82 int device; member
99 * Super-I/O functions.
102 static inline int superio_inb(int base, int reg) in superio_inb() argument
104 outb(reg, base); in superio_inb()
105 return inb(base + 1); in superio_inb()
108 static int superio_inw(int base, int reg) in superio_inw() argument
112 outb(reg++, base); in superio_inw()
113 val = inb(base + 1) << 8; in superio_inw()
114 outb(reg, base); in superio_inw()
115 val |= inb(base + 1); in superio_inw()
120 static inline void superio_outb(int base, int reg, int val) in superio_outb() argument
122 outb(reg, base); in superio_outb()
123 outb(val, base + 1); in superio_outb()
126 static inline int superio_enter(int base) in superio_enter() argument
129 if (!request_muxed_region(base, 2, DRVNAME)) { in superio_enter()
130 pr_err("I/O address 0x%04x already in use\n", base); in superio_enter()
131 return -EBUSY; in superio_enter()
135 outb(SIO_UNLOCK_KEY, base); in superio_enter()
136 outb(SIO_UNLOCK_KEY, base); in superio_enter()
141 static inline void superio_select(int base, int ld) in superio_select() argument
143 outb(SIO_LDSEL, base); in superio_select()
144 outb(ld, base + 1); in superio_select()
147 static inline void superio_exit(int base) in superio_exit() argument
149 outb(SIO_LOCK_KEY, base); in superio_exit()
150 release_region(base, 2); in superio_exit()
178 .base = -1, \
185 #define f7188x_gpio_dir(base) ((base) + 0) argument
186 #define f7188x_gpio_data_out(base) ((base) + 1) argument
187 #define f7188x_gpio_data_in(base) ((base) + 2) argument
188 /* Output mode register (0:open drain 1:push-pull). */
189 #define f7188x_gpio_out_mode(base) ((base) + 3) argument
195 F7188X_GPIO_BANK(6, 0xF0, DRVNAME "-0"),
196 F7188X_GPIO_BANK(8, 0xE0, DRVNAME "-1"),
197 F7188X_GPIO_BANK(8, 0xD0, DRVNAME "-2"),
198 F7188X_GPIO_BANK(8, 0xC0, DRVNAME "-3"),
199 F7188X_GPIO_BANK(8, 0xB0, DRVNAME "-4"),
200 F7188X_GPIO_BANK(5, 0xA0, DRVNAME "-5"),
201 F7188X_GPIO_BANK(6, 0x90, DRVNAME "-6"),
205 F7188X_GPIO_BANK(6, 0xF0, DRVNAME "-0"),
206 F7188X_GPIO_BANK(8, 0xE0, DRVNAME "-1"),
207 F7188X_GPIO_BANK(8, 0xD0, DRVNAME "-2"),
208 F7188X_GPIO_BANK(8, 0xC0, DRVNAME "-3"),
209 F7188X_GPIO_BANK(8, 0xB0, DRVNAME "-4"),
210 F7188X_GPIO_BANK(5, 0xA0, DRVNAME "-5"),
211 F7188X_GPIO_BANK(8, 0x90, DRVNAME "-6"),
212 F7188X_GPIO_BANK(8, 0x80, DRVNAME "-7"),
216 F7188X_GPIO_BANK(8, 0xF0, DRVNAME "-0"),
217 F7188X_GPIO_BANK(8, 0xE0, DRVNAME "-1"),
218 F7188X_GPIO_BANK(8, 0xD0, DRVNAME "-2"),
219 F7188X_GPIO_BANK(4, 0xC0, DRVNAME "-3"),
220 F7188X_GPIO_BANK(4, 0xB0, DRVNAME "-4"),
224 F7188X_GPIO_BANK(7, 0xF0, DRVNAME "-0"),
225 F7188X_GPIO_BANK(7, 0xE0, DRVNAME "-1"),
226 F7188X_GPIO_BANK(8, 0xD0, DRVNAME "-2"),
227 F7188X_GPIO_BANK(8, 0xC0, DRVNAME "-3"),
228 F7188X_GPIO_BANK(8, 0xB0, DRVNAME "-4"),
229 F7188X_GPIO_BANK(5, 0xA0, DRVNAME "-5"),
230 F7188X_GPIO_BANK(8, 0x90, DRVNAME "-6"),
231 F7188X_GPIO_BANK(8, 0x80, DRVNAME "-7"),
235 F7188X_GPIO_BANK(7, 0xF0, DRVNAME "-0"),
236 F7188X_GPIO_BANK(7, 0xE0, DRVNAME "-1"),
237 F7188X_GPIO_BANK(8, 0xD0, DRVNAME "-2"),
238 F7188X_GPIO_BANK(8, 0xC0, DRVNAME "-3"),
239 F7188X_GPIO_BANK(8, 0xB0, DRVNAME "-4"),
240 F7188X_GPIO_BANK(5, 0xA0, DRVNAME "-5"),
241 F7188X_GPIO_BANK(8, 0x90, DRVNAME "-6"),
242 F7188X_GPIO_BANK(8, 0x80, DRVNAME "-7"),
246 F7188X_GPIO_BANK(8, 0xF0, DRVNAME "-0"),
247 F7188X_GPIO_BANK(8, 0xE0, DRVNAME "-1"),
248 F7188X_GPIO_BANK(8, 0xD0, DRVNAME "-2"),
249 F7188X_GPIO_BANK(8, 0xC0, DRVNAME "-3"),
250 F7188X_GPIO_BANK(8, 0xB0, DRVNAME "-4"),
251 F7188X_GPIO_BANK(8, 0xA0, DRVNAME "-5"),
252 F7188X_GPIO_BANK(8, 0x90, DRVNAME "-6"),
253 F7188X_GPIO_BANK(8, 0x80, DRVNAME "-7"),
254 F7188X_GPIO_BANK(8, 0x88, DRVNAME "-8"),
259 F7188X_GPIO_BANK(8, 0xF0, DRVNAME "-0"),
260 F7188X_GPIO_BANK(8, 0xE0, DRVNAME "-1"),
261 F7188X_GPIO_BANK(8, 0xD0, DRVNAME "-2"),
262 F7188X_GPIO_BANK(8, 0xA0, DRVNAME "-3"),
263 F7188X_GPIO_BANK(8, 0x90, DRVNAME "-4"),
264 F7188X_GPIO_BANK(8, 0x80, DRVNAME "-5"),
265 F7188X_GPIO_BANK(8, 0x98, DRVNAME "-6"),
269 F7188X_GPIO_BANK(8, 0xF0, DRVNAME "-0"),
270 F7188X_GPIO_BANK(8, 0xE0, DRVNAME "-1"),
271 F7188X_GPIO_BANK(8, 0xD0, DRVNAME "-2"),
272 F7188X_GPIO_BANK(8, 0xC0, DRVNAME "-3"),
273 F7188X_GPIO_BANK(8, 0xB0, DRVNAME "-4"),
274 F7188X_GPIO_BANK(8, 0xA0, DRVNAME "-5"),
275 F7188X_GPIO_BANK(5, 0x90, DRVNAME "-6"),
279 F7188X_GPIO_BANK(8, 0xE0, DRVNAME "-0"),
280 F7188X_GPIO_BANK(8, 0xE4, DRVNAME "-1"),
281 F7188X_GPIO_BANK(8, 0xE8, DRVNAME "-2"),
282 F7188X_GPIO_BANK(8, 0xEC, DRVNAME "-3"),
283 F7188X_GPIO_BANK(8, 0xF0, DRVNAME "-4"),
284 F7188X_GPIO_BANK(8, 0xF4, DRVNAME "-5"),
285 F7188X_GPIO_BANK(8, 0xF8, DRVNAME "-6"),
286 F7188X_GPIO_BANK(8, 0xFC, DRVNAME "-7"),
293 struct f7188x_sio *sio = bank->data->sio; in f7188x_gpio_get_direction()
296 err = superio_enter(sio->addr); in f7188x_gpio_get_direction()
299 superio_select(sio->addr, sio->device); in f7188x_gpio_get_direction()
301 dir = superio_inb(sio->addr, f7188x_gpio_dir(bank->regbase)); in f7188x_gpio_get_direction()
303 superio_exit(sio->addr); in f7188x_gpio_get_direction()
305 if (f7188x_gpio_dir_invert(sio->type)) in f7188x_gpio_get_direction()
318 struct f7188x_sio *sio = bank->data->sio; in f7188x_gpio_direction_in()
321 err = superio_enter(sio->addr); in f7188x_gpio_direction_in()
324 superio_select(sio->addr, sio->device); in f7188x_gpio_direction_in()
326 dir = superio_inb(sio->addr, f7188x_gpio_dir(bank->regbase)); in f7188x_gpio_direction_in()
328 if (f7188x_gpio_dir_invert(sio->type)) in f7188x_gpio_direction_in()
332 superio_outb(sio->addr, f7188x_gpio_dir(bank->regbase), dir); in f7188x_gpio_direction_in()
334 superio_exit(sio->addr); in f7188x_gpio_direction_in()
343 struct f7188x_sio *sio = bank->data->sio; in f7188x_gpio_get()
346 err = superio_enter(sio->addr); in f7188x_gpio_get()
349 superio_select(sio->addr, sio->device); in f7188x_gpio_get()
351 dir = superio_inb(sio->addr, f7188x_gpio_dir(bank->regbase)); in f7188x_gpio_get()
353 if (f7188x_gpio_data_single(sio->type) || dir) in f7188x_gpio_get()
354 data = superio_inb(sio->addr, f7188x_gpio_data_out(bank->regbase)); in f7188x_gpio_get()
356 data = superio_inb(sio->addr, f7188x_gpio_data_in(bank->regbase)); in f7188x_gpio_get()
358 superio_exit(sio->addr); in f7188x_gpio_get()
368 struct f7188x_sio *sio = bank->data->sio; in f7188x_gpio_direction_out()
371 err = superio_enter(sio->addr); in f7188x_gpio_direction_out()
374 superio_select(sio->addr, sio->device); in f7188x_gpio_direction_out()
376 data_out = superio_inb(sio->addr, f7188x_gpio_data_out(bank->regbase)); in f7188x_gpio_direction_out()
381 superio_outb(sio->addr, f7188x_gpio_data_out(bank->regbase), data_out); in f7188x_gpio_direction_out()
383 dir = superio_inb(sio->addr, f7188x_gpio_dir(bank->regbase)); in f7188x_gpio_direction_out()
384 if (f7188x_gpio_dir_invert(sio->type)) in f7188x_gpio_direction_out()
388 superio_outb(sio->addr, f7188x_gpio_dir(bank->regbase), dir); in f7188x_gpio_direction_out()
390 superio_exit(sio->addr); in f7188x_gpio_direction_out()
400 struct f7188x_sio *sio = bank->data->sio; in f7188x_gpio_set()
403 err = superio_enter(sio->addr); in f7188x_gpio_set()
407 superio_select(sio->addr, sio->device); in f7188x_gpio_set()
409 data_out = superio_inb(sio->addr, f7188x_gpio_data_out(bank->regbase)); in f7188x_gpio_set()
414 superio_outb(sio->addr, f7188x_gpio_data_out(bank->regbase), data_out); in f7188x_gpio_set()
416 superio_exit(sio->addr); in f7188x_gpio_set()
427 struct f7188x_sio *sio = bank->data->sio; in f7188x_gpio_set_config()
432 return -ENOTSUPP; in f7188x_gpio_set_config()
434 err = superio_enter(sio->addr); in f7188x_gpio_set_config()
437 superio_select(sio->addr, sio->device); in f7188x_gpio_set_config()
439 data = superio_inb(sio->addr, f7188x_gpio_out_mode(bank->regbase)); in f7188x_gpio_set_config()
444 superio_outb(sio->addr, f7188x_gpio_out_mode(bank->regbase), data); in f7188x_gpio_set_config()
446 superio_exit(sio->addr); in f7188x_gpio_set_config()
451 * Platform device and driver.
458 struct f7188x_sio *sio = dev_get_platdata(&pdev->dev); in f7188x_gpio_probe()
461 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); in f7188x_gpio_probe()
463 return -ENOMEM; in f7188x_gpio_probe()
465 switch (sio->type) { in f7188x_gpio_probe()
467 data->nr_bank = ARRAY_SIZE(f71869_gpio_bank); in f7188x_gpio_probe()
468 data->bank = f71869_gpio_bank; in f7188x_gpio_probe()
471 data->nr_bank = ARRAY_SIZE(f71869a_gpio_bank); in f7188x_gpio_probe()
472 data->bank = f71869a_gpio_bank; in f7188x_gpio_probe()
475 data->nr_bank = ARRAY_SIZE(f71882_gpio_bank); in f7188x_gpio_probe()
476 data->bank = f71882_gpio_bank; in f7188x_gpio_probe()
479 data->nr_bank = ARRAY_SIZE(f71889a_gpio_bank); in f7188x_gpio_probe()
480 data->bank = f71889a_gpio_bank; in f7188x_gpio_probe()
483 data->nr_bank = ARRAY_SIZE(f71889_gpio_bank); in f7188x_gpio_probe()
484 data->bank = f71889_gpio_bank; in f7188x_gpio_probe()
487 data->nr_bank = ARRAY_SIZE(f81866_gpio_bank); in f7188x_gpio_probe()
488 data->bank = f81866_gpio_bank; in f7188x_gpio_probe()
491 data->nr_bank = ARRAY_SIZE(f81804_gpio_bank); in f7188x_gpio_probe()
492 data->bank = f81804_gpio_bank; in f7188x_gpio_probe()
495 data->nr_bank = ARRAY_SIZE(f81865_gpio_bank); in f7188x_gpio_probe()
496 data->bank = f81865_gpio_bank; in f7188x_gpio_probe()
499 data->nr_bank = ARRAY_SIZE(nct6126d_gpio_bank); in f7188x_gpio_probe()
500 data->bank = nct6126d_gpio_bank; in f7188x_gpio_probe()
503 return -ENODEV; in f7188x_gpio_probe()
505 data->sio = sio; in f7188x_gpio_probe()
510 for (i = 0; i < data->nr_bank; i++) { in f7188x_gpio_probe()
511 struct f7188x_gpio_bank *bank = &data->bank[i]; in f7188x_gpio_probe()
513 bank->chip.parent = &pdev->dev; in f7188x_gpio_probe()
514 bank->data = data; in f7188x_gpio_probe()
516 err = devm_gpiochip_add_data(&pdev->dev, &bank->chip, bank); in f7188x_gpio_probe()
518 dev_err(&pdev->dev, in f7188x_gpio_probe()
538 err = -ENODEV; in f7188x_find()
540 sio->device = SIO_LD_GPIO_FINTEK; in f7188x_find()
544 sio->type = f71869; in f7188x_find()
547 sio->type = f71869a; in f7188x_find()
550 sio->type = f71882fg; in f7188x_find()
553 sio->type = f71889a; in f7188x_find()
556 sio->type = f71889f; in f7188x_find()
559 sio->type = f81866; in f7188x_find()
562 sio->type = f81804; in f7188x_find()
565 sio->type = f81865; in f7188x_find()
568 sio->device = SIO_LD_GPIO_NUVOTON; in f7188x_find()
569 sio->type = nct6126d; in f7188x_find()
572 pr_info("Unsupported Fintek device 0x%04x\n", devid); in f7188x_find()
577 if (sio->type != nct6126d) { in f7188x_find()
580 pr_debug("Not a Fintek device at 0x%08x\n", addr); in f7188x_find()
585 sio->addr = addr; in f7188x_find()
588 pr_info("Found %s at %#x\n", f7188x_names[sio->type], (unsigned int)addr); in f7188x_find()
589 if (sio->type != nct6126d) in f7188x_find()
604 f7188x_gpio_pdev = platform_device_alloc(DRVNAME, -1); in f7188x_gpio_device_add()
606 return -ENOMEM; in f7188x_gpio_device_add()
617 pr_err("Device addition failed\n"); in f7188x_gpio_device_add()
630 * Try to match a supported Fintek device by reading the (hard-wired)
632 * device and driver to support the GPIOs.
649 return -ENODEV; in f7188x_gpio_init()
669 MODULE_DESCRIPTION("GPIO driver for Super-I/O chips F71869, F71869A, F71882FG, F71889A, F71889F and…