2 * Baytrail IOSF-SB MailBox Interface Driver
3 * Copyright (c) 2013, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * The IOSF-SB is a fabric bus available on Atom based SOC's that uses a
16 * mailbox interface (MBI) to communicate with mutiple devices. This
17 * driver implements BayTrail-specific access to this interface.
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/spinlock.h>
23 #include <linux/pci.h>
25 #include "intel_baytrail.h"
27 static DEFINE_SPINLOCK(iosf_mbi_lock
);
29 static inline u32
iosf_mbi_form_mcr(u8 op
, u8 port
, u8 offset
)
31 return (op
<< 24) | (port
<< 16) | (offset
<< 8) | BT_MBI_ENABLE
;
34 static struct pci_dev
*mbi_pdev
; /* one mbi device */
36 /* Hold lock before calling */
37 static int iosf_mbi_pci_read_mdr(u32 mcrx
, u32 mcr
, u32
*mdr
)
45 result
= pci_write_config_dword(mbi_pdev
,
46 BT_MBI_MCRX_OFFSET
, mcrx
);
48 goto iosf_mbi_read_err
;
51 result
= pci_write_config_dword(mbi_pdev
,
52 BT_MBI_MCR_OFFSET
, mcr
);
54 goto iosf_mbi_read_err
;
56 result
= pci_read_config_dword(mbi_pdev
,
57 BT_MBI_MDR_OFFSET
, mdr
);
59 goto iosf_mbi_read_err
;
64 dev_err(&mbi_pdev
->dev
, "error: PCI config operation returned %d\n",
69 /* Hold lock before calling */
70 static int iosf_mbi_pci_write_mdr(u32 mcrx
, u32 mcr
, u32 mdr
)
77 result
= pci_write_config_dword(mbi_pdev
,
78 BT_MBI_MDR_OFFSET
, mdr
);
80 goto iosf_mbi_write_err
;
83 result
= pci_write_config_dword(mbi_pdev
,
84 BT_MBI_MCRX_OFFSET
, mcrx
);
86 goto iosf_mbi_write_err
;
89 result
= pci_write_config_dword(mbi_pdev
,
90 BT_MBI_MCR_OFFSET
, mcr
);
92 goto iosf_mbi_write_err
;
97 dev_err(&mbi_pdev
->dev
, "error: PCI config operation returned %d\n",
102 int bt_mbi_read(u8 port
, u8 opcode
, u32 offset
, u32
*mdr
)
108 /*Access to the GFX unit is handled by GPU code */
109 BUG_ON(port
== BT_MBI_UNIT_GFX
);
111 mcr
= iosf_mbi_form_mcr(opcode
, port
, offset
& BT_MBI_MASK_LO
);
112 mcrx
= offset
& BT_MBI_MASK_HI
;
114 spin_lock_irqsave(&iosf_mbi_lock
, flags
);
115 ret
= iosf_mbi_pci_read_mdr(mcrx
, mcr
, mdr
);
116 spin_unlock_irqrestore(&iosf_mbi_lock
, flags
);
120 EXPORT_SYMBOL(bt_mbi_read
);
122 int bt_mbi_write(u8 port
, u8 opcode
, u32 offset
, u32 mdr
)
128 /*Access to the GFX unit is handled by GPU code */
129 BUG_ON(port
== BT_MBI_UNIT_GFX
);
131 mcr
= iosf_mbi_form_mcr(opcode
, port
, offset
& BT_MBI_MASK_LO
);
132 mcrx
= offset
& BT_MBI_MASK_HI
;
134 spin_lock_irqsave(&iosf_mbi_lock
, flags
);
135 ret
= iosf_mbi_pci_write_mdr(mcrx
, mcr
, mdr
);
136 spin_unlock_irqrestore(&iosf_mbi_lock
, flags
);
140 EXPORT_SYMBOL(bt_mbi_write
);
142 int bt_mbi_modify(u8 port
, u8 opcode
, u32 offset
, u32 mdr
, u32 mask
)
149 /*Access to the GFX unit is handled by GPU code */
150 BUG_ON(port
== BT_MBI_UNIT_GFX
);
152 mcr
= iosf_mbi_form_mcr(opcode
, port
, offset
& BT_MBI_MASK_LO
);
153 mcrx
= offset
& BT_MBI_MASK_HI
;
155 spin_lock_irqsave(&iosf_mbi_lock
, flags
);
157 /* Read current mdr value */
158 ret
= iosf_mbi_pci_read_mdr(mcrx
, mcr
& BT_MBI_RD_MASK
, &value
);
160 spin_unlock_irqrestore(&iosf_mbi_lock
, flags
);
170 ret
= iosf_mbi_pci_write_mdr(mcrx
, mcr
| BT_MBI_WR_MASK
, value
);
172 spin_unlock_irqrestore(&iosf_mbi_lock
, flags
);
176 EXPORT_SYMBOL(bt_mbi_modify
);
178 static int iosf_mbi_probe(struct pci_dev
*pdev
,
179 const struct pci_device_id
*unused
)
183 ret
= pci_enable_device(pdev
);
185 dev_err(&pdev
->dev
, "error: could not enable device\n");
189 mbi_pdev
= pci_dev_get(pdev
);
193 static DEFINE_PCI_DEVICE_TABLE(iosf_mbi_pci_ids
) = {
194 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x0F00) },
197 MODULE_DEVICE_TABLE(pci
, iosf_mbi_pci_ids
);
199 static struct pci_driver iosf_mbi_pci_driver
= {
200 .name
= "iosf_mbi_pci",
201 .probe
= iosf_mbi_probe
,
202 .id_table
= iosf_mbi_pci_ids
,
205 static int __init
bt_mbi_init(void)
207 return pci_register_driver(&iosf_mbi_pci_driver
);
210 static void __exit
bt_mbi_exit(void)
212 pci_unregister_driver(&iosf_mbi_pci_driver
);
214 pci_dev_put(mbi_pdev
);
219 module_init(bt_mbi_init
);
220 module_exit(bt_mbi_exit
);
222 MODULE_AUTHOR("David E. Box <david.e.box@linux.intel.com>");
223 MODULE_DESCRIPTION("BayTrail Mailbox Interface accessor");
224 MODULE_LICENSE("GPL v2");