2 * 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 access to this interface for those platforms that can
18 * enumerate the device using PCI.
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/spinlock.h>
24 #include <linux/pci.h>
26 #include <asm/iosf_mbi.h>
28 static DEFINE_SPINLOCK(iosf_mbi_lock
);
30 static inline u32
iosf_mbi_form_mcr(u8 op
, u8 port
, u8 offset
)
32 return (op
<< 24) | (port
<< 16) | (offset
<< 8) | MBI_ENABLE
;
35 static struct pci_dev
*mbi_pdev
; /* one mbi device */
37 static int iosf_mbi_pci_read_mdr(u32 mcrx
, u32 mcr
, u32
*mdr
)
45 result
= pci_write_config_dword(mbi_pdev
, MBI_MCRX_OFFSET
,
51 result
= pci_write_config_dword(mbi_pdev
, MBI_MCR_OFFSET
, mcr
);
55 result
= pci_read_config_dword(mbi_pdev
, MBI_MDR_OFFSET
, mdr
);
62 dev_err(&mbi_pdev
->dev
, "PCI config access failed with %d\n", result
);
66 static int iosf_mbi_pci_write_mdr(u32 mcrx
, u32 mcr
, u32 mdr
)
73 result
= pci_write_config_dword(mbi_pdev
, MBI_MDR_OFFSET
, mdr
);
78 result
= pci_write_config_dword(mbi_pdev
, MBI_MCRX_OFFSET
,
84 result
= pci_write_config_dword(mbi_pdev
, MBI_MCR_OFFSET
, mcr
);
91 dev_err(&mbi_pdev
->dev
, "PCI config access failed with %d\n", result
);
95 int iosf_mbi_read(u8 port
, u8 opcode
, u32 offset
, u32
*mdr
)
101 /*Access to the GFX unit is handled by GPU code */
102 if (port
== BT_MBI_UNIT_GFX
) {
107 mcr
= iosf_mbi_form_mcr(opcode
, port
, offset
& MBI_MASK_LO
);
108 mcrx
= offset
& MBI_MASK_HI
;
110 spin_lock_irqsave(&iosf_mbi_lock
, flags
);
111 ret
= iosf_mbi_pci_read_mdr(mcrx
, mcr
, mdr
);
112 spin_unlock_irqrestore(&iosf_mbi_lock
, flags
);
116 EXPORT_SYMBOL(iosf_mbi_read
);
118 int iosf_mbi_write(u8 port
, u8 opcode
, u32 offset
, u32 mdr
)
124 /*Access to the GFX unit is handled by GPU code */
125 if (port
== BT_MBI_UNIT_GFX
) {
130 mcr
= iosf_mbi_form_mcr(opcode
, port
, offset
& MBI_MASK_LO
);
131 mcrx
= offset
& MBI_MASK_HI
;
133 spin_lock_irqsave(&iosf_mbi_lock
, flags
);
134 ret
= iosf_mbi_pci_write_mdr(mcrx
, mcr
, mdr
);
135 spin_unlock_irqrestore(&iosf_mbi_lock
, flags
);
139 EXPORT_SYMBOL(iosf_mbi_write
);
141 int iosf_mbi_modify(u8 port
, u8 opcode
, u32 offset
, u32 mdr
, u32 mask
)
148 /*Access to the GFX unit is handled by GPU code */
149 if (port
== BT_MBI_UNIT_GFX
) {
154 mcr
= iosf_mbi_form_mcr(opcode
, port
, offset
& MBI_MASK_LO
);
155 mcrx
= offset
& MBI_MASK_HI
;
157 spin_lock_irqsave(&iosf_mbi_lock
, flags
);
159 /* Read current mdr value */
160 ret
= iosf_mbi_pci_read_mdr(mcrx
, mcr
& MBI_RD_MASK
, &value
);
162 spin_unlock_irqrestore(&iosf_mbi_lock
, flags
);
172 ret
= iosf_mbi_pci_write_mdr(mcrx
, mcr
| MBI_WR_MASK
, value
);
174 spin_unlock_irqrestore(&iosf_mbi_lock
, flags
);
178 EXPORT_SYMBOL(iosf_mbi_modify
);
180 static int iosf_mbi_probe(struct pci_dev
*pdev
,
181 const struct pci_device_id
*unused
)
185 ret
= pci_enable_device(pdev
);
187 dev_err(&pdev
->dev
, "error: could not enable device\n");
191 mbi_pdev
= pci_dev_get(pdev
);
195 static DEFINE_PCI_DEVICE_TABLE(iosf_mbi_pci_ids
) = {
196 { PCI_DEVICE(PCI_VENDOR_ID_INTEL
, 0x0F00) },
199 MODULE_DEVICE_TABLE(pci
, iosf_mbi_pci_ids
);
201 static struct pci_driver iosf_mbi_pci_driver
= {
202 .name
= "iosf_mbi_pci",
203 .probe
= iosf_mbi_probe
,
204 .id_table
= iosf_mbi_pci_ids
,
207 static int __init
iosf_mbi_init(void)
209 return pci_register_driver(&iosf_mbi_pci_driver
);
212 static void __exit
iosf_mbi_exit(void)
214 pci_unregister_driver(&iosf_mbi_pci_driver
);
216 pci_dev_put(mbi_pdev
);
221 module_init(iosf_mbi_init
);
222 module_exit(iosf_mbi_exit
);
224 MODULE_AUTHOR("David E. Box <david.e.box@linux.intel.com>");
225 MODULE_DESCRIPTION("IOSF Mailbox Interface accessor");
226 MODULE_LICENSE("GPL v2");