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 | |
| 17 | #include <kconfig.h> |
| 18 | #include <console/console.h> |
| 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
| 21 | #include <device/pci_ids.h> |
| 22 | #include <arch/io.h> |
| 23 | #include "chip.h" |
| 24 | |
| 25 | static void rce822_enable(struct device *dev) |
| 26 | { |
| 27 | struct drivers_ricoh_rce822_config *config = dev->chip_info; |
| 28 | |
| 29 | pci_write_config8(dev, 0xca, 0x57); |
| 30 | pci_write_config8(dev, 0xcb, config->disable_mask); |
| 31 | pci_write_config8(dev, 0xca, 0x00); |
| 32 | } |
| 33 | |
| 34 | static void rce822_init(struct device *dev) |
| 35 | { |
| 36 | struct drivers_ricoh_rce822_config *config = dev->chip_info; |
| 37 | |
| 38 | pci_write_config8(dev, 0xf9, 0xfc); |
| 39 | pci_write_config8(dev, 0xfb, config->sdwppol << 1); |
| 40 | pci_write_config8(dev, 0xf9, 0x00); |
| 41 | } |
| 42 | |
| 43 | static void rce822_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 44 | { |
Vladimir Serbinenko | 795f96e | 2014-10-27 02:45:22 +0100 | [diff] [blame] | 45 | if (!vendor || !device) { |
| 46 | pci_write_config32(dev, 0xac, |
| 47 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 48 | } else { |
| 49 | pci_write_config32(dev, 0xac, |
| 50 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | static struct pci_operations lops_pci = { |
| 55 | .set_subsystem = &rce822_set_subsystem, |
| 56 | }; |
| 57 | |
Vladimir Serbinenko | 633e827 | 2015-05-15 11:10:08 +0200 | [diff] [blame] | 58 | static struct device_operations rce822_ops = { |
Vladimir Serbinenko | 795f96e | 2014-10-27 02:45:22 +0100 | [diff] [blame] | 59 | .read_resources = pci_dev_read_resources, |
| 60 | .set_resources = pci_dev_set_resources, |
| 61 | .enable_resources = pci_dev_enable_resources, |
| 62 | .init = rce822_init, |
| 63 | .enable = rce822_enable, |
| 64 | .scan_bus = 0, |
| 65 | .ops_pci = &lops_pci, |
| 66 | }; |
| 67 | |
| 68 | static const unsigned short pci_device_ids[] = { 0xe822, 0xe823, 0 }; |
| 69 | |
Vladimir Serbinenko | 633e827 | 2015-05-15 11:10:08 +0200 | [diff] [blame] | 70 | static const struct pci_driver rce822 __pci_driver = { |
| 71 | .ops = &rce822_ops, |
Vladimir Serbinenko | 795f96e | 2014-10-27 02:45:22 +0100 | [diff] [blame] | 72 | .vendor = PCI_VENDOR_ID_RICOH, |
| 73 | .devices = pci_device_ids, |
| 74 | }; |