Angel Pons | 6bc1374 | 2020-04-05 15:46:38 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | ff8bce0 | 2016-06-27 10:57:13 -0700 | [diff] [blame] | 2 | |
Duncan Laurie | ff8bce0 | 2016-06-27 10:57:13 -0700 | [diff] [blame] | 3 | #include <device/device.h> |
Duncan Laurie | ff8bce0 | 2016-06-27 10:57:13 -0700 | [diff] [blame] | 4 | #include <device/pci_def.h> |
Chris Ching | b8dc63b | 2017-12-06 14:26:15 -0700 | [diff] [blame] | 5 | #include <drivers/i2c/designware/dw_i2c.h> |
Duncan Laurie | ff8bce0 | 2016-06-27 10:57:13 -0700 | [diff] [blame] | 6 | #include <soc/pci_devs.h> |
Duncan Laurie | ff8bce0 | 2016-06-27 10:57:13 -0700 | [diff] [blame] | 7 | |
Rizwan Qureshi | ae6a4b6 | 2017-04-26 21:06:35 +0530 | [diff] [blame] | 8 | /* Convert I2C bus number to PCI device and function */ |
Aaron Durbin | 9aee819 | 2018-01-22 20:29:25 -0700 | [diff] [blame] | 9 | int dw_i2c_soc_bus_to_devfn(unsigned int bus) |
Duncan Laurie | ff8bce0 | 2016-06-27 10:57:13 -0700 | [diff] [blame] | 10 | { |
Rizwan Qureshi | 7f72c64 | 2017-10-04 18:53:19 +0530 | [diff] [blame] | 11 | if (bus <= 3) |
Rizwan Qureshi | ae6a4b6 | 2017-04-26 21:06:35 +0530 | [diff] [blame] | 12 | 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 Laurie | ff8bce0 | 2016-06-27 10:57:13 -0700 | [diff] [blame] | 17 | } |
| 18 | |
Rizwan Qureshi | ae6a4b6 | 2017-04-26 21:06:35 +0530 | [diff] [blame] | 19 | /* Convert PCI device and function to I2C bus number */ |
Aaron Durbin | 9aee819 | 2018-01-22 20:29:25 -0700 | [diff] [blame] | 20 | int dw_i2c_soc_devfn_to_bus(unsigned int devfn) |
Duncan Laurie | ff8bce0 | 2016-06-27 10:57:13 -0700 | [diff] [blame] | 21 | { |
Rizwan Qureshi | ae6a4b6 | 2017-04-26 21:06:35 +0530 | [diff] [blame] | 22 | 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 Laurie | ff8bce0 | 2016-06-27 10:57:13 -0700 | [diff] [blame] | 28 | } |