blob: d5767629895e75d305ad976bee5162d728aab19e [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 <device/device.h>
18#include <device/pci.h>
19#include <device/pci_ids.h>
20#include <arch/io.h>
21#include "chip.h"
22
23static 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
32static 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 HAOUAS88030b72018-09-20 17:26:10 +020041static void rce822_set_subsystem(struct device *dev, unsigned int vendor,
42 unsigned int 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 = {
Elyes HAOUAS2aa3b162018-11-27 17:02:10 +010054 .set_subsystem = rce822_set_subsystem,
Vladimir Serbinenko795f96e2014-10-27 02:45:22 +010055};
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};