Blame view

drivers/gpio/gpio-f7188x.c 12.6 KB
6c17aa013   Simon Guinot   gpio: add GPIO su...
1
  /*
1920906f5   Peter Hung   gpio-f7188x: Add ...
2
   * GPIO driver for Fintek Super-I/O F71869, F71869A, F71882, F71889 and F81866
6c17aa013   Simon Guinot   gpio: add GPIO su...
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
   *
   * Copyright (C) 2010-2013 LaCie
   *
   * Author: Simon Guinot <simon.guinot@sequanux.org>
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation; either version 2 of the License, or
   * (at your option) any later version.
   */
  
  #include <linux/module.h>
  #include <linux/init.h>
  #include <linux/platform_device.h>
  #include <linux/io.h>
148c86426   Linus Walleij   gpio: f7188x: use...
18
19
  #include <linux/gpio/driver.h>
  #include <linux/bitops.h>
6c17aa013   Simon Guinot   gpio: add GPIO su...
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  
  #define DRVNAME "gpio-f7188x"
  
  /*
   * Super-I/O registers
   */
  #define SIO_LDSEL		0x07	/* Logical device select */
  #define SIO_DEVID		0x20	/* Device ID (2 bytes) */
  #define SIO_DEVREV		0x22	/* Device revision */
  #define SIO_MANID		0x23	/* Fintek ID (2 bytes) */
  
  #define SIO_LD_GPIO		0x06	/* GPIO logical device */
  #define SIO_UNLOCK_KEY		0x87	/* Key to enable Super-I/O */
  #define SIO_LOCK_KEY		0xAA	/* Key to disable Super-I/O */
  
  #define SIO_FINTEK_ID		0x1934	/* Manufacturer ID */
24ccef359   Andreas Bofjall   gpio: f7188x: add...
36
  #define SIO_F71869_ID		0x0814	/* F71869 chipset ID */
7e9603638   Andreas Bofjall   gpio: f7188x: add...
37
  #define SIO_F71869A_ID		0x1007	/* F71869A chipset ID */
6c17aa013   Simon Guinot   gpio: add GPIO su...
38
39
  #define SIO_F71882_ID		0x0541	/* F71882 chipset ID */
  #define SIO_F71889_ID		0x0909	/* F71889 chipset ID */
1920906f5   Peter Hung   gpio-f7188x: Add ...
40
  #define SIO_F81866_ID		0x1010	/* F81866 chipset ID */
6c17aa013   Simon Guinot   gpio: add GPIO su...
41

1920906f5   Peter Hung   gpio-f7188x: Add ...
42
  enum chips { f71869, f71869a, f71882fg, f71889f, f81866 };
6c17aa013   Simon Guinot   gpio: add GPIO su...
43
44
  
  static const char * const f7188x_names[] = {
24ccef359   Andreas Bofjall   gpio: f7188x: add...
45
  	"f71869",
7e9603638   Andreas Bofjall   gpio: f7188x: add...
46
  	"f71869a",
6c17aa013   Simon Guinot   gpio: add GPIO su...
47
48
  	"f71882fg",
  	"f71889f",
1920906f5   Peter Hung   gpio-f7188x: Add ...
49
  	"f81866",
6c17aa013   Simon Guinot   gpio: add GPIO su...
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
  };
  
  struct f7188x_sio {
  	int addr;
  	enum chips type;
  };
  
  struct f7188x_gpio_bank {
  	struct gpio_chip chip;
  	unsigned int regbase;
  	struct f7188x_gpio_data *data;
  };
  
  struct f7188x_gpio_data {
  	struct f7188x_sio *sio;
  	int nr_bank;
  	struct f7188x_gpio_bank *bank;
  };
  
  /*
   * Super-I/O functions.
   */
  
  static inline int superio_inb(int base, int reg)
  {
  	outb(reg, base);
  	return inb(base + 1);
  }
  
  static int superio_inw(int base, int reg)
  {
  	int val;
  
  	outb(reg++, base);
  	val = inb(base + 1) << 8;
  	outb(reg, base);
  	val |= inb(base + 1);
  
  	return val;
  }
  
  static inline void superio_outb(int base, int reg, int val)
  {
  	outb(reg, base);
  	outb(val, base + 1);
  }
  
  static inline int superio_enter(int base)
  {
  	/* Don't step on other drivers' I/O space by accident. */
  	if (!request_muxed_region(base, 2, DRVNAME)) {
  		pr_err(DRVNAME "I/O address 0x%04x already in use
  ", base);
  		return -EBUSY;
  	}
  
  	/* According to the datasheet the key must be send twice. */
  	outb(SIO_UNLOCK_KEY, base);
  	outb(SIO_UNLOCK_KEY, base);
  
  	return 0;
  }
  
  static inline void superio_select(int base, int ld)
  {
  	outb(SIO_LDSEL, base);
  	outb(ld, base + 1);
  }
  
  static inline void superio_exit(int base)
  {
  	outb(SIO_LOCK_KEY, base);
  	release_region(base, 2);
  }
  
  /*
   * GPIO chip.
   */
107cdd2d6   plr.vincent@gmail.com   gpio: f7188x: Imp...
128
  static int f7188x_gpio_get_direction(struct gpio_chip *chip, unsigned offset);
6c17aa013   Simon Guinot   gpio: add GPIO su...
129
130
131
132
133
  static int f7188x_gpio_direction_in(struct gpio_chip *chip, unsigned offset);
  static int f7188x_gpio_get(struct gpio_chip *chip, unsigned offset);
  static int f7188x_gpio_direction_out(struct gpio_chip *chip,
  				     unsigned offset, int value);
  static void f7188x_gpio_set(struct gpio_chip *chip, unsigned offset, int value);
f90c6bdb6   Linus Walleij   gpio: f7188x: use...
134
135
136
  static int f7188x_gpio_set_single_ended(struct gpio_chip *gc,
  					unsigned offset,
  					enum single_ended_mode mode);
6c17aa013   Simon Guinot   gpio: add GPIO su...
137
138
139
140
141
142
  
  #define F7188X_GPIO_BANK(_base, _ngpio, _regbase)			\
  	{								\
  		.chip = {						\
  			.label            = DRVNAME,			\
  			.owner            = THIS_MODULE,		\
107cdd2d6   plr.vincent@gmail.com   gpio: f7188x: Imp...
143
  			.get_direction    = f7188x_gpio_get_direction,	\
6c17aa013   Simon Guinot   gpio: add GPIO su...
144
145
146
147
  			.direction_input  = f7188x_gpio_direction_in,	\
  			.get              = f7188x_gpio_get,		\
  			.direction_output = f7188x_gpio_direction_out,	\
  			.set              = f7188x_gpio_set,		\
f90c6bdb6   Linus Walleij   gpio: f7188x: use...
148
  			.set_single_ended = f7188x_gpio_set_single_ended, \
6c17aa013   Simon Guinot   gpio: add GPIO su...
149
150
  			.base             = _base,			\
  			.ngpio            = _ngpio,			\
aeccc1b4a   Simon Guinot   gpio: f7188x: set...
151
  			.can_sleep        = true,			\
6c17aa013   Simon Guinot   gpio: add GPIO su...
152
153
154
155
156
157
158
159
160
  		},							\
  		.regbase = _regbase,					\
  	}
  
  #define gpio_dir(base) (base + 0)
  #define gpio_data_out(base) (base + 1)
  #define gpio_data_in(base) (base + 2)
  /* Output mode register (0:open drain 1:push-pull). */
  #define gpio_out_mode(base) (base + 3)
24ccef359   Andreas Bofjall   gpio: f7188x: add...
161
162
163
164
165
166
167
168
169
  static struct f7188x_gpio_bank f71869_gpio_bank[] = {
  	F7188X_GPIO_BANK(0, 6, 0xF0),
  	F7188X_GPIO_BANK(10, 8, 0xE0),
  	F7188X_GPIO_BANK(20, 8, 0xD0),
  	F7188X_GPIO_BANK(30, 8, 0xC0),
  	F7188X_GPIO_BANK(40, 8, 0xB0),
  	F7188X_GPIO_BANK(50, 5, 0xA0),
  	F7188X_GPIO_BANK(60, 6, 0x90),
  };
7e9603638   Andreas Bofjall   gpio: f7188x: add...
170
171
172
173
174
175
176
177
178
179
  static struct f7188x_gpio_bank f71869a_gpio_bank[] = {
  	F7188X_GPIO_BANK(0, 6, 0xF0),
  	F7188X_GPIO_BANK(10, 8, 0xE0),
  	F7188X_GPIO_BANK(20, 8, 0xD0),
  	F7188X_GPIO_BANK(30, 8, 0xC0),
  	F7188X_GPIO_BANK(40, 8, 0xB0),
  	F7188X_GPIO_BANK(50, 5, 0xA0),
  	F7188X_GPIO_BANK(60, 8, 0x90),
  	F7188X_GPIO_BANK(70, 8, 0x80),
  };
6c17aa013   Simon Guinot   gpio: add GPIO su...
180
  static struct f7188x_gpio_bank f71882_gpio_bank[] = {
38e003f4b   Daniel Lockyer   gpio: Fix checkpa...
181
  	F7188X_GPIO_BANK(0, 8, 0xF0),
6c17aa013   Simon Guinot   gpio: add GPIO su...
182
183
184
185
186
187
188
  	F7188X_GPIO_BANK(10, 8, 0xE0),
  	F7188X_GPIO_BANK(20, 8, 0xD0),
  	F7188X_GPIO_BANK(30, 4, 0xC0),
  	F7188X_GPIO_BANK(40, 4, 0xB0),
  };
  
  static struct f7188x_gpio_bank f71889_gpio_bank[] = {
38e003f4b   Daniel Lockyer   gpio: Fix checkpa...
189
  	F7188X_GPIO_BANK(0, 7, 0xF0),
6c17aa013   Simon Guinot   gpio: add GPIO su...
190
191
192
193
194
195
196
197
  	F7188X_GPIO_BANK(10, 7, 0xE0),
  	F7188X_GPIO_BANK(20, 8, 0xD0),
  	F7188X_GPIO_BANK(30, 8, 0xC0),
  	F7188X_GPIO_BANK(40, 8, 0xB0),
  	F7188X_GPIO_BANK(50, 5, 0xA0),
  	F7188X_GPIO_BANK(60, 8, 0x90),
  	F7188X_GPIO_BANK(70, 8, 0x80),
  };
1920906f5   Peter Hung   gpio-f7188x: Add ...
198
199
200
201
202
203
204
205
206
207
208
  static struct f7188x_gpio_bank f81866_gpio_bank[] = {
  	F7188X_GPIO_BANK(0, 8, 0xF0),
  	F7188X_GPIO_BANK(10, 8, 0xE0),
  	F7188X_GPIO_BANK(20, 8, 0xD0),
  	F7188X_GPIO_BANK(30, 8, 0xC0),
  	F7188X_GPIO_BANK(40, 8, 0xB0),
  	F7188X_GPIO_BANK(50, 8, 0xA0),
  	F7188X_GPIO_BANK(60, 8, 0x90),
  	F7188X_GPIO_BANK(70, 8, 0x80),
  	F7188X_GPIO_BANK(80, 8, 0x88),
  };
107cdd2d6   plr.vincent@gmail.com   gpio: f7188x: Imp...
209
210
211
  static int f7188x_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
  {
  	int err;
35a26144a   Amitesh Singh   gpio: f7188x: use...
212
  	struct f7188x_gpio_bank *bank = gpiochip_get_data(chip);
107cdd2d6   plr.vincent@gmail.com   gpio: f7188x: Imp...
213
214
215
216
217
218
219
220
221
222
223
224
225
226
  	struct f7188x_sio *sio = bank->data->sio;
  	u8 dir;
  
  	err = superio_enter(sio->addr);
  	if (err)
  		return err;
  	superio_select(sio->addr, SIO_LD_GPIO);
  
  	dir = superio_inb(sio->addr, gpio_dir(bank->regbase));
  
  	superio_exit(sio->addr);
  
  	return !(dir & 1 << offset);
  }
6c17aa013   Simon Guinot   gpio: add GPIO su...
227
228
229
  static int f7188x_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
  {
  	int err;
f372d5f59   Linus Walleij   gpio: f7188: use ...
230
  	struct f7188x_gpio_bank *bank = gpiochip_get_data(chip);
6c17aa013   Simon Guinot   gpio: add GPIO su...
231
232
233
234
235
236
237
238
239
  	struct f7188x_sio *sio = bank->data->sio;
  	u8 dir;
  
  	err = superio_enter(sio->addr);
  	if (err)
  		return err;
  	superio_select(sio->addr, SIO_LD_GPIO);
  
  	dir = superio_inb(sio->addr, gpio_dir(bank->regbase));
148c86426   Linus Walleij   gpio: f7188x: use...
240
  	dir &= ~BIT(offset);
6c17aa013   Simon Guinot   gpio: add GPIO su...
241
242
243
244
245
246
247
248
249
250
  	superio_outb(sio->addr, gpio_dir(bank->regbase), dir);
  
  	superio_exit(sio->addr);
  
  	return 0;
  }
  
  static int f7188x_gpio_get(struct gpio_chip *chip, unsigned offset)
  {
  	int err;
f372d5f59   Linus Walleij   gpio: f7188: use ...
251
  	struct f7188x_gpio_bank *bank = gpiochip_get_data(chip);
6c17aa013   Simon Guinot   gpio: add GPIO su...
252
253
254
255
256
257
258
259
260
  	struct f7188x_sio *sio = bank->data->sio;
  	u8 dir, data;
  
  	err = superio_enter(sio->addr);
  	if (err)
  		return err;
  	superio_select(sio->addr, SIO_LD_GPIO);
  
  	dir = superio_inb(sio->addr, gpio_dir(bank->regbase));
148c86426   Linus Walleij   gpio: f7188x: use...
261
  	dir = !!(dir & BIT(offset));
6c17aa013   Simon Guinot   gpio: add GPIO su...
262
263
264
265
266
267
  	if (dir)
  		data = superio_inb(sio->addr, gpio_data_out(bank->regbase));
  	else
  		data = superio_inb(sio->addr, gpio_data_in(bank->regbase));
  
  	superio_exit(sio->addr);
148c86426   Linus Walleij   gpio: f7188x: use...
268
  	return !!(data & BIT(offset));
6c17aa013   Simon Guinot   gpio: add GPIO su...
269
270
271
272
273
274
  }
  
  static int f7188x_gpio_direction_out(struct gpio_chip *chip,
  				     unsigned offset, int value)
  {
  	int err;
f372d5f59   Linus Walleij   gpio: f7188: use ...
275
  	struct f7188x_gpio_bank *bank = gpiochip_get_data(chip);
6c17aa013   Simon Guinot   gpio: add GPIO su...
276
277
278
279
280
281
282
283
284
285
  	struct f7188x_sio *sio = bank->data->sio;
  	u8 dir, data_out;
  
  	err = superio_enter(sio->addr);
  	if (err)
  		return err;
  	superio_select(sio->addr, SIO_LD_GPIO);
  
  	data_out = superio_inb(sio->addr, gpio_data_out(bank->regbase));
  	if (value)
148c86426   Linus Walleij   gpio: f7188x: use...
286
  		data_out |= BIT(offset);
6c17aa013   Simon Guinot   gpio: add GPIO su...
287
  	else
148c86426   Linus Walleij   gpio: f7188x: use...
288
  		data_out &= ~BIT(offset);
6c17aa013   Simon Guinot   gpio: add GPIO su...
289
290
291
  	superio_outb(sio->addr, gpio_data_out(bank->regbase), data_out);
  
  	dir = superio_inb(sio->addr, gpio_dir(bank->regbase));
148c86426   Linus Walleij   gpio: f7188x: use...
292
  	dir |= BIT(offset);
6c17aa013   Simon Guinot   gpio: add GPIO su...
293
294
295
296
297
298
299
300
301
302
  	superio_outb(sio->addr, gpio_dir(bank->regbase), dir);
  
  	superio_exit(sio->addr);
  
  	return 0;
  }
  
  static void f7188x_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
  {
  	int err;
f372d5f59   Linus Walleij   gpio: f7188: use ...
303
  	struct f7188x_gpio_bank *bank = gpiochip_get_data(chip);
6c17aa013   Simon Guinot   gpio: add GPIO su...
304
305
306
307
308
309
310
311
312
313
  	struct f7188x_sio *sio = bank->data->sio;
  	u8 data_out;
  
  	err = superio_enter(sio->addr);
  	if (err)
  		return;
  	superio_select(sio->addr, SIO_LD_GPIO);
  
  	data_out = superio_inb(sio->addr, gpio_data_out(bank->regbase));
  	if (value)
148c86426   Linus Walleij   gpio: f7188x: use...
314
  		data_out |= BIT(offset);
6c17aa013   Simon Guinot   gpio: add GPIO su...
315
  	else
148c86426   Linus Walleij   gpio: f7188x: use...
316
  		data_out &= ~BIT(offset);
6c17aa013   Simon Guinot   gpio: add GPIO su...
317
318
319
320
  	superio_outb(sio->addr, gpio_data_out(bank->regbase), data_out);
  
  	superio_exit(sio->addr);
  }
f90c6bdb6   Linus Walleij   gpio: f7188x: use...
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
  static int f7188x_gpio_set_single_ended(struct gpio_chip *chip,
  					unsigned offset,
  					enum single_ended_mode mode)
  {
  	int err;
  	struct f7188x_gpio_bank *bank = gpiochip_get_data(chip);
  	struct f7188x_sio *sio = bank->data->sio;
  	u8 data;
  
  	if (mode != LINE_MODE_OPEN_DRAIN &&
  	    mode != LINE_MODE_PUSH_PULL)
  		return -ENOTSUPP;
  
  	err = superio_enter(sio->addr);
  	if (err)
  		return err;
  	superio_select(sio->addr, SIO_LD_GPIO);
  
  	data = superio_inb(sio->addr, gpio_out_mode(bank->regbase));
  	if (mode == LINE_MODE_OPEN_DRAIN)
  		data &= ~BIT(offset);
  	else
  		data |= BIT(offset);
327819d1e   Linus Walleij   gpio: f7188x: fix...
344
  	superio_outb(sio->addr, gpio_out_mode(bank->regbase), data);
f90c6bdb6   Linus Walleij   gpio: f7188x: use...
345
346
347
348
  
  	superio_exit(sio->addr);
  	return 0;
  }
6c17aa013   Simon Guinot   gpio: add GPIO su...
349
350
351
352
353
354
355
356
  /*
   * Platform device and driver.
   */
  
  static int f7188x_gpio_probe(struct platform_device *pdev)
  {
  	int err;
  	int i;
ab128afce   Nizam Haider   gpio: use dev_get...
357
  	struct f7188x_sio *sio = dev_get_platdata(&pdev->dev);
6c17aa013   Simon Guinot   gpio: add GPIO su...
358
359
360
361
362
363
364
  	struct f7188x_gpio_data *data;
  
  	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
  	if (!data)
  		return -ENOMEM;
  
  	switch (sio->type) {
24ccef359   Andreas Bofjall   gpio: f7188x: add...
365
366
367
368
  	case f71869:
  		data->nr_bank = ARRAY_SIZE(f71869_gpio_bank);
  		data->bank = f71869_gpio_bank;
  		break;
7e9603638   Andreas Bofjall   gpio: f7188x: add...
369
370
371
372
  	case f71869a:
  		data->nr_bank = ARRAY_SIZE(f71869a_gpio_bank);
  		data->bank = f71869a_gpio_bank;
  		break;
6c17aa013   Simon Guinot   gpio: add GPIO su...
373
374
375
376
377
378
379
380
  	case f71882fg:
  		data->nr_bank = ARRAY_SIZE(f71882_gpio_bank);
  		data->bank = f71882_gpio_bank;
  		break;
  	case f71889f:
  		data->nr_bank = ARRAY_SIZE(f71889_gpio_bank);
  		data->bank = f71889_gpio_bank;
  		break;
1920906f5   Peter Hung   gpio-f7188x: Add ...
381
382
383
384
  	case f81866:
  		data->nr_bank = ARRAY_SIZE(f81866_gpio_bank);
  		data->bank = f81866_gpio_bank;
  		break;
6c17aa013   Simon Guinot   gpio: add GPIO su...
385
386
387
388
389
390
391
392
393
394
  	default:
  		return -ENODEV;
  	}
  	data->sio = sio;
  
  	platform_set_drvdata(pdev, data);
  
  	/* For each GPIO bank, register a GPIO chip. */
  	for (i = 0; i < data->nr_bank; i++) {
  		struct f7188x_gpio_bank *bank = &data->bank[i];
58383c784   Linus Walleij   gpio: change memb...
395
  		bank->chip.parent = &pdev->dev;
6c17aa013   Simon Guinot   gpio: add GPIO su...
396
  		bank->data = data;
330f4e561   Laxman Dewangan   gpio: f7188x: Use...
397
  		err = devm_gpiochip_add_data(&pdev->dev, &bank->chip, bank);
6c17aa013   Simon Guinot   gpio: add GPIO su...
398
399
400
401
402
  		if (err) {
  			dev_err(&pdev->dev,
  				"Failed to register gpiochip %d: %d
  ",
  				i, err);
330f4e561   Laxman Dewangan   gpio: f7188x: Use...
403
  			return err;
6c17aa013   Simon Guinot   gpio: add GPIO su...
404
405
406
407
  		}
  	}
  
  	return 0;
6c17aa013   Simon Guinot   gpio: add GPIO su...
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
  }
  
  static int __init f7188x_find(int addr, struct f7188x_sio *sio)
  {
  	int err;
  	u16 devid;
  
  	err = superio_enter(addr);
  	if (err)
  		return err;
  
  	err = -ENODEV;
  	devid = superio_inw(addr, SIO_MANID);
  	if (devid != SIO_FINTEK_ID) {
  		pr_debug(DRVNAME ": Not a Fintek device at 0x%08x
  ", addr);
  		goto err;
  	}
  
  	devid = superio_inw(addr, SIO_DEVID);
  	switch (devid) {
24ccef359   Andreas Bofjall   gpio: f7188x: add...
429
430
431
  	case SIO_F71869_ID:
  		sio->type = f71869;
  		break;
7e9603638   Andreas Bofjall   gpio: f7188x: add...
432
433
434
  	case SIO_F71869A_ID:
  		sio->type = f71869a;
  		break;
6c17aa013   Simon Guinot   gpio: add GPIO su...
435
436
437
438
439
440
  	case SIO_F71882_ID:
  		sio->type = f71882fg;
  		break;
  	case SIO_F71889_ID:
  		sio->type = f71889f;
  		break;
1920906f5   Peter Hung   gpio-f7188x: Add ...
441
442
443
  	case SIO_F81866_ID:
  		sio->type = f81866;
  		break;
6c17aa013   Simon Guinot   gpio: add GPIO su...
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
  	default:
  		pr_info(DRVNAME ": Unsupported Fintek device 0x%04x
  ", devid);
  		goto err;
  	}
  	sio->addr = addr;
  	err = 0;
  
  	pr_info(DRVNAME ": Found %s at %#x, revision %d
  ",
  		f7188x_names[sio->type],
  		(unsigned int) addr,
  		(int) superio_inb(addr, SIO_DEVREV));
  
  err:
  	superio_exit(addr);
  	return err;
  }
  
  static struct platform_device *f7188x_gpio_pdev;
  
  static int __init
  f7188x_gpio_device_add(const struct f7188x_sio *sio)
  {
  	int err;
  
  	f7188x_gpio_pdev = platform_device_alloc(DRVNAME, -1);
  	if (!f7188x_gpio_pdev)
  		return -ENOMEM;
  
  	err = platform_device_add_data(f7188x_gpio_pdev,
  				       sio, sizeof(*sio));
  	if (err) {
  		pr_err(DRVNAME "Platform data allocation failed
  ");
  		goto err;
  	}
  
  	err = platform_device_add(f7188x_gpio_pdev);
  	if (err) {
  		pr_err(DRVNAME "Device addition failed
  ");
  		goto err;
  	}
  
  	return 0;
  
  err:
  	platform_device_put(f7188x_gpio_pdev);
  
  	return err;
  }
  
  /*
3f8f4f19b   Andreas Bofjall   gpio: f7188x: cor...
498
   * Try to match a supported Fintek device by reading the (hard-wired)
6c17aa013   Simon Guinot   gpio: add GPIO su...
499
500
501
502
503
504
   * configuration I/O ports. If available, then register both the platform
   * device and driver to support the GPIOs.
   */
  
  static struct platform_driver f7188x_gpio_driver = {
  	.driver = {
6c17aa013   Simon Guinot   gpio: add GPIO su...
505
506
507
  		.name	= DRVNAME,
  	},
  	.probe		= f7188x_gpio_probe,
6c17aa013   Simon Guinot   gpio: add GPIO su...
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
  };
  
  static int __init f7188x_gpio_init(void)
  {
  	int err;
  	struct f7188x_sio sio;
  
  	if (f7188x_find(0x2e, &sio) &&
  	    f7188x_find(0x4e, &sio))
  		return -ENODEV;
  
  	err = platform_driver_register(&f7188x_gpio_driver);
  	if (!err) {
  		err = f7188x_gpio_device_add(&sio);
  		if (err)
  			platform_driver_unregister(&f7188x_gpio_driver);
  	}
  
  	return err;
  }
  subsys_initcall(f7188x_gpio_init);
  
  static void __exit f7188x_gpio_exit(void)
  {
  	platform_device_unregister(f7188x_gpio_pdev);
  	platform_driver_unregister(&f7188x_gpio_driver);
  }
  module_exit(f7188x_gpio_exit);
1920906f5   Peter Hung   gpio-f7188x: Add ...
536
  MODULE_DESCRIPTION("GPIO driver for Super-I/O chips F71869, F71869A, F71882FG, F71889F and F81866");
6c17aa013   Simon Guinot   gpio: add GPIO su...
537
538
  MODULE_AUTHOR("Simon Guinot <simon.guinot@sequanux.org>");
  MODULE_LICENSE("GPL");