blob: 110117beae08bc5c0b5d3678936d675badae2706 [file] [log] [blame]
Angel Pons6bc13742020-04-05 15:46:38 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Duncan Laurieff8bce02016-06-27 10:57:13 -07002
Duncan Laurieff8bce02016-06-27 10:57:13 -07003#include <device/device.h>
Duncan Laurieff8bce02016-06-27 10:57:13 -07004#include <device/pci_def.h>
Chris Chingb8dc63b2017-12-06 14:26:15 -07005#include <drivers/i2c/designware/dw_i2c.h>
Duncan Laurieff8bce02016-06-27 10:57:13 -07006#include <soc/pci_devs.h>
Duncan Laurieff8bce02016-06-27 10:57:13 -07007
Rizwan Qureshiae6a4b62017-04-26 21:06:35 +05308/* Convert I2C bus number to PCI device and function */
Aaron Durbin9aee8192018-01-22 20:29:25 -07009int dw_i2c_soc_bus_to_devfn(unsigned int bus)
Duncan Laurieff8bce02016-06-27 10:57:13 -070010{
Rizwan Qureshi7f72c642017-10-04 18:53:19 +053011 if (bus <= 3)
Rizwan Qureshiae6a4b62017-04-26 21:06:35 +053012 return PCI_DEVFN(PCH_DEV_SLOT_SIO1, bus);
13 else if (bus >= 4 && bus <= 7)
14 return PCI_DEVFN(PCH_DEV_SLOT_SIO2, (bus - 4));
15 else
16 return -1;
Duncan Laurieff8bce02016-06-27 10:57:13 -070017}
18
Rizwan Qureshiae6a4b62017-04-26 21:06:35 +053019/* Convert PCI device and function to I2C bus number */
Aaron Durbin9aee8192018-01-22 20:29:25 -070020int dw_i2c_soc_devfn_to_bus(unsigned int devfn)
Duncan Laurieff8bce02016-06-27 10:57:13 -070021{
Rizwan Qureshiae6a4b62017-04-26 21:06:35 +053022 if (PCI_SLOT(devfn) == PCH_DEV_SLOT_SIO1)
23 return PCI_FUNC(devfn);
24 else if (PCI_SLOT(devfn) == PCH_DEV_SLOT_SIO2)
25 return PCI_FUNC(devfn) + 4;
26 else
27 return -1;
Duncan Laurieff8bce02016-06-27 10:57:13 -070028}