blob: b364946e56008cf6be9b3a2e540ad8b93c8ce9d1 [file] [log] [blame]
Vladimir Serbinenko795f96e2014-10-27 02:45:22 +01001/*
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 Serbinenko795f96e2014-10-27 02:45:22 +010015 */
16
Vladimir Serbinenko795f96e2014-10-27 02:45:22 +010017#include <console/console.h>
18#include <device/device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
21#include <arch/io.h>
22#include "chip.h"
23
24static void rce822_enable(struct device *dev)
25{
26 struct drivers_ricoh_rce822_config *config = dev->chip_info;
27
28 pci_write_config8(dev, 0xca, 0x57);
29 pci_write_config8(dev, 0xcb, config->disable_mask);
30 pci_write_config8(dev, 0xca, 0x00);
31}
32
33static void rce822_init(struct device *dev)
34{
35 struct drivers_ricoh_rce822_config *config = dev->chip_info;
36
37 pci_write_config8(dev, 0xf9, 0xfc);
38 pci_write_config8(dev, 0xfb, config->sdwppol << 1);
39 pci_write_config8(dev, 0xf9, 0x00);
40}
41
Elyes HAOUAS8f6ea302018-05-02 22:05:39 +020042static void rce822_set_subsystem(struct device *dev, unsigned vendor, unsigned device)
Vladimir Serbinenko795f96e2014-10-27 02:45:22 +010043{
Vladimir Serbinenko795f96e2014-10-27 02:45:22 +010044 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
53static struct pci_operations lops_pci = {
54 .set_subsystem = &rce822_set_subsystem,
55};
56
Vladimir Serbinenko633e8272015-05-15 11:10:08 +020057static struct device_operations rce822_ops = {
Vladimir Serbinenko795f96e2014-10-27 02:45:22 +010058 .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
67static const unsigned short pci_device_ids[] = { 0xe822, 0xe823, 0 };
68
Vladimir Serbinenko633e8272015-05-15 11:10:08 +020069static const struct pci_driver rce822 __pci_driver = {
70 .ops = &rce822_ops,
Vladimir Serbinenko795f96e2014-10-27 02:45:22 +010071 .vendor = PCI_VENDOR_ID_RICOH,
72 .devices = pci_device_ids,
73};