Vladimir Serbinenko | 795f96e | 2014-10-27 02:45:22 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 Vladimir Serbinenko |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Vladimir Serbinenko | 795f96e | 2014-10-27 02:45:22 +0100 | [diff] [blame] | 15 | */ |
| 16 | |
Vladimir Serbinenko | 795f96e | 2014-10-27 02:45:22 +0100 | [diff] [blame] | 17 | #include <device/device.h> |
| 18 | #include <device/pci.h> |
| 19 | #include <device/pci_ids.h> |
| 20 | #include <arch/io.h> |
| 21 | #include "chip.h" |
| 22 | |
| 23 | static void rce822_enable(struct device *dev) |
| 24 | { |
| 25 | struct drivers_ricoh_rce822_config *config = dev->chip_info; |
| 26 | |
| 27 | pci_write_config8(dev, 0xca, 0x57); |
| 28 | pci_write_config8(dev, 0xcb, config->disable_mask); |
| 29 | pci_write_config8(dev, 0xca, 0x00); |
| 30 | } |
| 31 | |
| 32 | static void rce822_init(struct device *dev) |
| 33 | { |
| 34 | struct drivers_ricoh_rce822_config *config = dev->chip_info; |
| 35 | |
| 36 | pci_write_config8(dev, 0xf9, 0xfc); |
| 37 | pci_write_config8(dev, 0xfb, config->sdwppol << 1); |
| 38 | pci_write_config8(dev, 0xf9, 0x00); |
| 39 | } |
| 40 | |
Elyes HAOUAS | 88030b7 | 2018-09-20 17:26:10 +0200 | [diff] [blame] | 41 | static void rce822_set_subsystem(struct device *dev, unsigned int vendor, |
| 42 | unsigned int device) |
Vladimir Serbinenko | 795f96e | 2014-10-27 02:45:22 +0100 | [diff] [blame] | 43 | { |
Vladimir Serbinenko | 795f96e | 2014-10-27 02:45:22 +0100 | [diff] [blame] | 44 | if (!vendor || !device) { |
| 45 | pci_write_config32(dev, 0xac, |
| 46 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 47 | } else { |
| 48 | pci_write_config32(dev, 0xac, |
| 49 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | static struct pci_operations lops_pci = { |
| 54 | .set_subsystem = &rce822_set_subsystem, |
| 55 | }; |
| 56 | |
Vladimir Serbinenko | 633e827 | 2015-05-15 11:10:08 +0200 | [diff] [blame] | 57 | static struct device_operations rce822_ops = { |
Vladimir Serbinenko | 795f96e | 2014-10-27 02:45:22 +0100 | [diff] [blame] | 58 | .read_resources = pci_dev_read_resources, |
| 59 | .set_resources = pci_dev_set_resources, |
| 60 | .enable_resources = pci_dev_enable_resources, |
| 61 | .init = rce822_init, |
| 62 | .enable = rce822_enable, |
| 63 | .scan_bus = 0, |
| 64 | .ops_pci = &lops_pci, |
| 65 | }; |
| 66 | |
| 67 | static const unsigned short pci_device_ids[] = { 0xe822, 0xe823, 0 }; |
| 68 | |
Vladimir Serbinenko | 633e827 | 2015-05-15 11:10:08 +0200 | [diff] [blame] | 69 | static const struct pci_driver rce822 __pci_driver = { |
| 70 | .ops = &rce822_ops, |
Vladimir Serbinenko | 795f96e | 2014-10-27 02:45:22 +0100 | [diff] [blame] | 71 | .vendor = PCI_VENDOR_ID_RICOH, |
| 72 | .devices = pci_device_ids, |
| 73 | }; |