-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathi2c-amd-mp2-pci.c
717 lines (585 loc) · 17.6 KB
/
i2c-amd-mp2-pci.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
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
498
499
500
501
502
503
504
505
506
507
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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
/*
* AMD MP2 PCIe communication driver
*
* Authors: Shyam Sundar S K <[email protected]>
* Elie Morisse <[email protected]>
*/
#include <linux/debugfs.h>
#include <linux/dma-mapping.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include "i2c-amd-mp2.h"
#define DRIVER_NAME "i2c_amd_mp2"
#define DRIVER_DESC "AMD(R) PCI-E MP2 I2C Controller Driver"
#define DRIVER_VER "1.0"
static inline void write64(u64 val, void __iomem *mmio)
{
writel(val, mmio);
writel(val >> 32, mmio + sizeof(u32));
}
static inline u64 read64(void __iomem *mmio)
{
u64 low, high;
low = readl(mmio);
high = readl(mmio + sizeof(u32));
return low | (high << 32);
}
static void amd_mp2_c2p_mutex_lock(struct amd_i2c_common *i2c_common)
{
struct amd_mp2_dev *privdata = i2c_common->mp2_dev;
/* there is only one data mailbox for two i2c adapters */
mutex_lock(&privdata->c2p_lock);
privdata->c2p_lock_busid = i2c_common->bus_id;
}
static void amd_mp2_c2p_mutex_unlock(struct amd_i2c_common *i2c_common)
{
struct amd_mp2_dev *privdata = i2c_common->mp2_dev;
if (unlikely(privdata->c2p_lock_busid != i2c_common->bus_id)) {
dev_warn(ndev_dev(privdata),
"bus %d attempting to unlock C2P locked by bus %d\n",
i2c_common->bus_id, privdata->c2p_lock_busid);
return;
}
mutex_unlock(&privdata->c2p_lock);
}
static int amd_mp2_cmd(struct amd_i2c_common *i2c_common,
union i2c_cmd_base i2c_cmd_base)
{
struct amd_mp2_dev *privdata = i2c_common->mp2_dev;
void __iomem *reg;
i2c_common->reqcmd = i2c_cmd_base.s.i2c_cmd;
reg = privdata->mmio + ((i2c_cmd_base.s.bus_id == 1) ?
AMD_C2P_MSG1 : AMD_C2P_MSG0);
writel(i2c_cmd_base.ul, reg);
return 0;
}
int amd_mp2_bus_enable_set(struct amd_i2c_common *i2c_common, bool enable)
{
struct amd_mp2_dev *privdata = i2c_common->mp2_dev;
union i2c_cmd_base i2c_cmd_base;
dev_dbg(ndev_dev(privdata), "%s id: %d\n", __func__,
i2c_common->bus_id);
i2c_cmd_base.ul = 0;
i2c_cmd_base.s.i2c_cmd = enable ? i2c_enable : i2c_disable;
i2c_cmd_base.s.bus_id = i2c_common->bus_id;
i2c_cmd_base.s.i2c_speed = i2c_common->i2c_speed;
amd_mp2_c2p_mutex_lock(i2c_common);
return amd_mp2_cmd(i2c_common, i2c_cmd_base);
}
static void amd_mp2_cmd_rw_fill(struct amd_i2c_common *i2c_common,
union i2c_cmd_base *i2c_cmd_base,
enum i2c_cmd reqcmd)
{
i2c_cmd_base->s.i2c_cmd = reqcmd;
i2c_cmd_base->s.bus_id = i2c_common->bus_id;
i2c_cmd_base->s.i2c_speed = i2c_common->i2c_speed;
i2c_cmd_base->s.slave_addr = i2c_common->msg->addr;
i2c_cmd_base->s.length = i2c_common->msg->len;
}
#ifndef i2c_get_dma_safe_msg_buf
// DKMS only, for kernels older than 4.16, assume msg->buf to be DMA safe since
// I2C_M_DMA_SAFE wasn't introduced either
u8 *i2c_get_dma_safe_msg_buf(struct i2c_msg *msg, unsigned int threshold)
{
/* ... */
/* if (msg->flags & I2C_M_DMA_SAFE) */
return msg->buf;
/* ... */
}
#endif
static int amd_mp2_dma_map(struct amd_mp2_dev *privdata,
struct amd_i2c_common *i2c_common)
{
enum dma_data_direction dma_direction =
i2c_common->msg->flags & I2C_M_RD ?
DMA_FROM_DEVICE : DMA_TO_DEVICE;
i2c_common->dma_buf = i2c_get_dma_safe_msg_buf(i2c_common->msg, 0);
i2c_common->dma_addr = dma_map_single(&privdata->pci_dev->dev,
i2c_common->dma_buf,
i2c_common->msg->len,
dma_direction);
if (dma_mapping_error(&privdata->pci_dev->dev,
i2c_common->dma_addr)) {
dev_err(ndev_dev(privdata),
"Error while mapping dma buffer %p\n",
i2c_common->dma_buf);
return -EIO;
}
return 0;
}
#ifndef i2c_put_dma_safe_msg_buf
// DKMS only, for kernels older than 4.19
void i2c_put_dma_safe_msg_buf(u8 *buf, struct i2c_msg *msg, bool xferred)
{
if (!buf || buf == msg->buf)
return;
if (xferred && msg->flags & I2C_M_RD)
memcpy(msg->buf, buf, msg->len);
kfree(buf);
}
#endif
static void amd_mp2_dma_unmap(struct amd_mp2_dev *privdata,
struct amd_i2c_common *i2c_common)
{
enum dma_data_direction dma_direction =
i2c_common->msg->flags & I2C_M_RD ?
DMA_FROM_DEVICE : DMA_TO_DEVICE;
dma_unmap_single(&privdata->pci_dev->dev,
i2c_common->dma_addr,
i2c_common->msg->len,
dma_direction);
i2c_put_dma_safe_msg_buf(i2c_common->dma_buf, i2c_common->msg, true);
}
static int amd_mp2_rw(struct amd_i2c_common *i2c_common, enum i2c_cmd reqcmd)
{
struct amd_mp2_dev *privdata = i2c_common->mp2_dev;
union i2c_cmd_base i2c_cmd_base;
amd_mp2_cmd_rw_fill(i2c_common, &i2c_cmd_base, reqcmd);
amd_mp2_c2p_mutex_lock(i2c_common);
if (i2c_common->msg->len <= 32) {
i2c_cmd_base.s.mem_type = use_c2pmsg;
if (reqcmd == i2c_write)
memcpy_toio(privdata->mmio + AMD_C2P_MSG2,
i2c_common->msg->buf,
i2c_common->msg->len);
} else {
i2c_cmd_base.s.mem_type = use_dram;
if (amd_mp2_dma_map(privdata, i2c_common))
return -EIO;
write64((u64)i2c_common->dma_addr,
privdata->mmio + AMD_C2P_MSG2);
}
return amd_mp2_cmd(i2c_common, i2c_cmd_base);
}
int amd_mp2_read(struct amd_i2c_common *i2c_common)
{
struct amd_mp2_dev *privdata = i2c_common->mp2_dev;
dev_dbg(ndev_dev(privdata), "%s addr: %x id: %d\n", __func__,
i2c_common->msg->addr, i2c_common->bus_id);
return amd_mp2_rw(i2c_common, i2c_read);
}
int amd_mp2_write(struct amd_i2c_common *i2c_common)
{
struct amd_mp2_dev *privdata = i2c_common->mp2_dev;
dev_dbg(ndev_dev(privdata), "%s addr: %x id: %d\n", __func__,
i2c_common->msg->addr, i2c_common->bus_id);
return amd_mp2_rw(i2c_common, i2c_write);
}
static void amd_mp2_pci_check_rw_event(struct amd_i2c_common *i2c_common)
{
struct amd_mp2_dev *privdata = i2c_common->mp2_dev;
int len = i2c_common->eventval.r.length;
u32 slave_addr = i2c_common->eventval.r.slave_addr;
bool err = false;
if (unlikely(len != i2c_common->msg->len)) {
dev_err(ndev_dev(privdata),
"length %d in event doesn't match buffer length %d!\n",
len, i2c_common->msg->len);
err = true;
}
if (unlikely(slave_addr != i2c_common->msg->addr)) {
dev_err(ndev_dev(privdata),
"unexpected slave address %x (expected: %x)!\n",
slave_addr, i2c_common->msg->addr);
err = true;
}
if (!err)
i2c_common->cmd_success = true;
}
static void __amd_mp2_process_event(struct amd_i2c_common *i2c_common)
{
struct amd_mp2_dev *privdata = i2c_common->mp2_dev;
enum status_type sts = i2c_common->eventval.r.status;
enum response_type res = i2c_common->eventval.r.response;
int len = i2c_common->eventval.r.length;
if ((i2c_common->reqcmd == i2c_read ||
i2c_common->reqcmd == i2c_write) &&
i2c_common->msg->len > 32)
amd_mp2_dma_unmap(privdata, i2c_common);
if (res != command_success) {
if (res == command_failed)
dev_err(ndev_dev(privdata), "i2c command failed!\n");
else
dev_err(ndev_dev(privdata), "invalid response to i2c command!\n");
return;
}
switch (i2c_common->reqcmd) {
case i2c_read:
if (sts == i2c_readcomplete_event) {
amd_mp2_pci_check_rw_event(i2c_common);
if (len <= 32)
memcpy_fromio(i2c_common->msg->buf,
privdata->mmio + AMD_C2P_MSG2,
i2c_common->msg->len);
} else if (sts == i2c_readfail_event) {
dev_err(ndev_dev(privdata), "i2c read failed!\n");
} else {
dev_err(ndev_dev(privdata),
"invalid i2c status after read (%d)!\n", sts);
}
break;
case i2c_write:
if (sts == i2c_writecomplete_event)
amd_mp2_pci_check_rw_event(i2c_common);
else if (sts == i2c_writefail_event)
dev_err(ndev_dev(privdata), "i2c write failed!\n");
else
dev_err(ndev_dev(privdata),
"invalid i2c status after write (%d)!\n", sts);
break;
case i2c_enable:
if (sts == i2c_busenable_failed)
dev_err(ndev_dev(privdata), "i2c bus enable failed!\n");
else if (sts != i2c_busenable_complete)
dev_err(ndev_dev(privdata),
"invalid i2c status after bus enable (%d)!\n",
sts);
else
i2c_common->cmd_success = true;
break;
case i2c_disable:
if (sts == i2c_busdisable_failed)
dev_err(ndev_dev(privdata), "i2c bus disable failed!\n");
else if (sts != i2c_busdisable_complete)
dev_err(ndev_dev(privdata),
"invalid i2c status after bus disable (%d)!\n",
sts);
else
i2c_common->cmd_success = true;
break;
default:
break;
}
}
void amd_mp2_process_event(struct amd_i2c_common *i2c_common)
{
struct amd_mp2_dev *privdata = i2c_common->mp2_dev;
if (unlikely(i2c_common->reqcmd == i2c_none)) {
dev_warn(ndev_dev(privdata),
"received msg but no cmd was sent (bus = %d)!\n",
i2c_common->bus_id);
return;
}
__amd_mp2_process_event(i2c_common);
i2c_common->reqcmd = i2c_none;
amd_mp2_c2p_mutex_unlock(i2c_common);
}
static irqreturn_t amd_mp2_irq_isr(int irq, void *dev)
{
struct amd_mp2_dev *privdata = dev;
struct amd_i2c_common *i2c_common;
u32 val;
unsigned int bus_id;
void __iomem *reg;
enum irqreturn ret = IRQ_NONE;
for (bus_id = 0; bus_id < 2; bus_id++) {
i2c_common = privdata->busses[bus_id];
if (!i2c_common)
continue;
reg = privdata->mmio + ((bus_id == 0) ?
AMD_P2C_MSG1 : AMD_P2C_MSG2);
val = readl(reg);
if (val != 0) {
writel(0, reg);
writel(0, privdata->mmio + AMD_P2C_MSG_INTEN);
i2c_common->eventval.ul = val;
i2c_amd_cmd_completion(i2c_common);
ret = IRQ_HANDLED;
}
}
if (ret != IRQ_HANDLED) {
val = readl(privdata->mmio + AMD_P2C_MSG_INTEN);
if (unlikely(val != 0)) {
writel(0, privdata->mmio + AMD_P2C_MSG_INTEN);
dev_warn(ndev_dev(privdata),
"received irq without message\n");
ret = IRQ_HANDLED;
}
}
return ret;
}
void amd_mp2_rw_timeout(struct amd_i2c_common *i2c_common)
{
i2c_common->reqcmd = i2c_none;
amd_mp2_c2p_mutex_unlock(i2c_common);
}
int amd_mp2_register_cb(struct amd_i2c_common *i2c_common)
{
struct amd_mp2_dev *privdata = i2c_common->mp2_dev;
if (i2c_common->bus_id > 1)
return -EINVAL;
if (privdata->busses[i2c_common->bus_id]) {
dev_err(ndev_dev(privdata),
"Bus %d already taken!\n", i2c_common->bus_id);
return -EINVAL;
}
privdata->busses[i2c_common->bus_id] = i2c_common;
return 0;
}
int amd_mp2_unregister_cb(struct amd_i2c_common *i2c_common)
{
struct amd_mp2_dev *privdata = i2c_common->mp2_dev;
privdata->busses[i2c_common->bus_id] = NULL;
return 0;
}
#ifdef CONFIG_DEBUG_FS
static const struct file_operations amd_mp2_debugfs_info;
static struct dentry *debugfs_root_dir;
static ssize_t amd_mp2_debugfs_read(struct file *filp, char __user *ubuf,
size_t count, loff_t *offp)
{
struct amd_mp2_dev *privdata = filp->private_data;
size_t buf_size = min_t(size_t, count, 0x800);
u8 *buf;
ssize_t ret, off = 0;
u32 v32;
int i;
buf = kmalloc(buf_size, GFP_KERNEL);
if (!buf)
return -ENOMEM;
off += scnprintf(buf + off, buf_size - off,
"MP2 Device Information:\n"
"========================\n"
"\tMP2 C2P Message Register Dump:\n\n");
for (i = 0; i < 10; i++) {
v32 = readl(privdata->mmio + AMD_C2P_MSG0 + i * 4);
off += scnprintf(buf + off, buf_size - off,
"AMD_C2P_MSG%d -\t\t\t%#06x\n", i, v32);
}
off += scnprintf(buf + off, buf_size - off,
"\n\tMP2 P2C Message Register Dump:\n\n");
for (i = 0; i < 3; i++) {
v32 = readl(privdata->mmio + AMD_P2C_MSG1 + i * 4);
off += scnprintf(buf + off, buf_size - off,
"AMD_P2C_MSG%d -\t\t\t%#06x\n", i + 1, v32);
}
v32 = readl(privdata->mmio + AMD_P2C_MSG_INTEN);
off += scnprintf(buf + off, buf_size - off,
"AMD_P2C_MSG_INTEN -\t\t%#06x\n", v32);
v32 = readl(privdata->mmio + AMD_P2C_MSG_INTSTS);
off += scnprintf(buf + off, buf_size - off,
"AMD_P2C_MSG_INTSTS -\t\t%#06x\n", v32);
ret = simple_read_from_buffer(ubuf, count, offp, buf, off);
kfree(buf);
return ret;
}
static const struct file_operations amd_mp2_debugfs_info = {
.owner = THIS_MODULE,
.open = simple_open,
.read = amd_mp2_debugfs_read,
};
static void amd_mp2_init_debugfs(struct amd_mp2_dev *privdata)
{
if (!debugfs_root_dir)
return;
privdata->debugfs_dir = debugfs_create_dir(ndev_name(privdata),
debugfs_root_dir);
if (!privdata->debugfs_dir) {
privdata->debugfs_info = NULL;
} else {
privdata->debugfs_info = debugfs_create_file
("info", 0400, privdata->debugfs_dir,
privdata, &amd_mp2_debugfs_info);
}
}
#endif /* CONFIG_DEBUG_FS */
static void amd_mp2_clear_reg(struct amd_mp2_dev *privdata)
{
int reg;
for (reg = AMD_C2P_MSG0; reg <= AMD_C2P_MSG9; reg += 4)
writel(0, privdata->mmio + reg);
for (reg = AMD_P2C_MSG1; reg <= AMD_P2C_MSG2; reg += 4)
writel(0, privdata->mmio + reg);
}
static int amd_mp2_pci_init(struct amd_mp2_dev *privdata,
struct pci_dev *pci_dev)
{
int rc;
pci_set_drvdata(pci_dev, privdata);
rc = pcim_enable_device(pci_dev);
if (rc) {
dev_err(ndev_dev(privdata), "Failed to enable MP2 PCI device\n");
goto err_pci_enable;
}
rc = pcim_iomap_regions(pci_dev, 1 << 2, pci_name(pci_dev));
if (rc) {
dev_err(ndev_dev(privdata), "I/O memory remapping failed\n");
goto err_pci_enable;
}
privdata->mmio = pcim_iomap_table(pci_dev)[2];
pci_set_master(pci_dev);
rc = pci_set_dma_mask(pci_dev, DMA_BIT_MASK(64));
if (rc) {
rc = pci_set_dma_mask(pci_dev, DMA_BIT_MASK(32));
if (rc)
goto err_dma_mask;
}
/* Set up intx irq */
writel(0, privdata->mmio + AMD_P2C_MSG_INTEN);
pci_intx(pci_dev, 1);
rc = devm_request_irq(&pci_dev->dev, pci_dev->irq, amd_mp2_irq_isr,
IRQF_SHARED, dev_name(&pci_dev->dev), privdata);
if (rc)
dev_err(&pci_dev->dev, "Failure requesting irq %i: %d\n",
pci_dev->irq, rc);
return rc;
err_dma_mask:
pci_clear_master(pci_dev);
err_pci_enable:
pci_set_drvdata(pci_dev, NULL);
return rc;
}
static int amd_mp2_pci_probe(struct pci_dev *pci_dev,
const struct pci_device_id *id)
{
struct amd_mp2_dev *privdata;
int rc;
static bool first_probe = true;
if (first_probe) {
pr_info("%s: %s Version: %s\n", DRIVER_NAME,
DRIVER_DESC, DRIVER_VER);
first_probe = false;
}
dev_info(&pci_dev->dev, "MP2 device found [%04x:%04x] (rev %x)\n",
pci_dev->vendor, pci_dev->device, pci_dev->revision);
privdata = devm_kzalloc(&pci_dev->dev, sizeof(*privdata), GFP_KERNEL);
if (!privdata)
return -ENOMEM;
rc = amd_mp2_pci_init(privdata, pci_dev);
if (rc)
return rc;
mutex_init(&privdata->c2p_lock);
privdata->pci_dev = pci_dev;
pm_runtime_set_autosuspend_delay(&pci_dev->dev, 1000);
pm_runtime_use_autosuspend(&pci_dev->dev);
pm_runtime_put_autosuspend(&pci_dev->dev);
pm_runtime_allow(&pci_dev->dev);
amd_mp2_init_debugfs(privdata);
dev_info(&pci_dev->dev, "MP2 device registered.\n");
return 0;
}
static bool amd_mp2_pci_is_probed(struct pci_dev *pci_dev)
{
struct amd_mp2_dev *privdata = pci_get_drvdata(pci_dev);
if (!privdata)
return false;
return privdata->pci_dev != NULL;
}
static void amd_mp2_pci_remove(struct pci_dev *pci_dev)
{
struct amd_mp2_dev *privdata = pci_get_drvdata(pci_dev);
pm_runtime_forbid(&pci_dev->dev);
pm_runtime_get_noresume(&pci_dev->dev);
#ifdef CONFIG_DEBUG_FS
debugfs_remove_recursive(privdata->debugfs_dir);
#endif /* CONFIG_DEBUG_FS */
pci_intx(pci_dev, 0);
pci_clear_master(pci_dev);
amd_mp2_clear_reg(privdata);
}
#ifdef CONFIG_PM
static int amd_mp2_pci_suspend(struct device *dev)
{
struct pci_dev *pci_dev = to_pci_dev(dev);
struct amd_mp2_dev *privdata = pci_get_drvdata(pci_dev);
unsigned int bus_id;
int ret = 0;
for (bus_id = 0; bus_id < 2; bus_id++)
if (privdata->busses[bus_id])
i2c_amd_suspend(privdata->busses[bus_id]);
ret = pci_save_state(pci_dev);
if (ret) {
dev_err(ndev_dev(privdata),
"pci_save_state failed = %d\n", ret);
return ret;
}
pci_disable_device(pci_dev);
return ret;
}
static int amd_mp2_pci_resume(struct device *dev)
{
struct pci_dev *pci_dev = to_pci_dev(dev);
struct amd_mp2_dev *privdata = pci_get_drvdata(pci_dev);
unsigned int bus_id;
int ret = 0;
pci_restore_state(pci_dev);
ret = pci_enable_device(pci_dev);
if (ret < 0) {
dev_err(ndev_dev(privdata),
"pci_enable_device failed = %d\n", ret);
return ret;
}
for (bus_id = 0; bus_id < 2; bus_id++)
if (privdata->busses[bus_id]) {
ret = i2c_amd_resume(privdata->busses[bus_id]);
if (ret < 0)
return ret;
}
return ret;
}
static UNIVERSAL_DEV_PM_OPS(amd_mp2_pci_pm_ops, amd_mp2_pci_suspend,
amd_mp2_pci_resume, NULL);
#endif /* CONFIG_PM */
static const struct pci_device_id amd_mp2_pci_tbl[] = {
{PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_MP2)},
{0}
};
MODULE_DEVICE_TABLE(pci, amd_mp2_pci_tbl);
static struct pci_driver amd_mp2_pci_driver = {
.name = DRIVER_NAME,
.id_table = amd_mp2_pci_tbl,
.probe = amd_mp2_pci_probe,
.remove = amd_mp2_pci_remove,
#ifdef CONFIG_PM
.driver = {
.pm = &amd_mp2_pci_pm_ops,
},
#endif
};
static int amd_mp2_device_match(struct device *dev, void *data)
{
return 1;
}
struct amd_mp2_dev *amd_mp2_find_device(void)
{
struct device *dev;
struct pci_dev *pci_dev;
dev = driver_find_device(&amd_mp2_pci_driver.driver, NULL, NULL,
amd_mp2_device_match);
if (!dev)
return NULL;
pci_dev = to_pci_dev(dev);
if (!amd_mp2_pci_is_probed(pci_dev))
return NULL;
return (struct amd_mp2_dev *)pci_get_drvdata(pci_dev);
}
static int __init amd_mp2_drv_init(void)
{
int rc;
#ifdef CONFIG_DEBUG_FS
debugfs_root_dir = debugfs_create_dir(KBUILD_MODNAME, NULL);
#endif /* CONFIG_DEBUG_FS */
rc = pci_register_driver(&amd_mp2_pci_driver);
if (rc)
return rc;
return i2c_amd_register_driver();
}
module_init(amd_mp2_drv_init);
static void __exit amd_mp2_drv_exit(void)
{
i2c_amd_unregister_driver();
pci_unregister_driver(&amd_mp2_pci_driver);
#ifdef CONFIG_DEBUG_FS
debugfs_remove_recursive(debugfs_root_dir);
#endif /* CONFIG_DEBUG_FS */
}
module_exit(amd_mp2_drv_exit);
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_VERSION(DRIVER_VER);
MODULE_AUTHOR("Shyam Sundar S K <[email protected]>");
MODULE_AUTHOR("Nehal Shah <[email protected]>");
MODULE_AUTHOR("Elie Morisse <[email protected]>");
MODULE_LICENSE("Dual BSD/GPL");