blob: 297dd616066653025457c1759413339e64d42bcb [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 HAOUAS88030b72018-09-20 17:26:10 +020042static void rce822_set_subsystem(struct device *dev, unsigned int vendor,
43 unsigned int device)
Vladimir Serbinenko795f96e2014-10-27 02:45:22 +010044{
Vladimir Serbinenko795f96e2014-10-27 02:45:22 +010045 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
54static struct pci_operations lops_pci = {
55 .set_subsystem = &rce822_set_subsystem,
56};
57
Vladimir Serbinenko633e8272015-05-15 11:10:08 +020058static struct device_operations rce822_ops = {
Vladimir Serbinenko795f96e2014-10-27 02:45:22 +010059 .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
68static const unsigned short pci_device_ids[] = { 0xe822, 0xe823, 0 };
69
Vladimir Serbinenko633e8272015-05-15 11:10:08 +020070static const struct pci_driver rce822 __pci_driver = {
71 .ops = &rce822_ops,
Vladimir Serbinenko795f96e2014-10-27 02:45:22 +010072 .vendor = PCI_VENDOR_ID_RICOH,
73 .devices = pci_device_ids,
74};