blob: 6a5c861afd0a259f48fb9dacf8309bfb0e23e45e [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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <kconfig.h>
22#include <console/console.h>
23#include <device/device.h>
24#include <device/pci.h>
25#include <device/pci_ids.h>
26#include <arch/io.h>
27#include "chip.h"
28
29static void rce822_enable(struct device *dev)
30{
31 struct drivers_ricoh_rce822_config *config = dev->chip_info;
32
33 pci_write_config8(dev, 0xca, 0x57);
34 pci_write_config8(dev, 0xcb, config->disable_mask);
35 pci_write_config8(dev, 0xca, 0x00);
36}
37
38static void rce822_init(struct device *dev)
39{
40 struct drivers_ricoh_rce822_config *config = dev->chip_info;
41
42 pci_write_config8(dev, 0xf9, 0xfc);
43 pci_write_config8(dev, 0xfb, config->sdwppol << 1);
44 pci_write_config8(dev, 0xf9, 0x00);
45}
46
47static void rce822_set_subsystem(device_t dev, unsigned vendor, unsigned device)
48{
Vladimir Serbinenko795f96e2014-10-27 02:45:22 +010049 if (!vendor || !device) {
50 pci_write_config32(dev, 0xac,
51 pci_read_config32(dev, PCI_VENDOR_ID));
52 } else {
53 pci_write_config32(dev, 0xac,
54 ((device & 0xffff) << 16) | (vendor & 0xffff));
55 }
56}
57
58static struct pci_operations lops_pci = {
59 .set_subsystem = &rce822_set_subsystem,
60};
61
Vladimir Serbinenko633e8272015-05-15 11:10:08 +020062static struct device_operations rce822_ops = {
Vladimir Serbinenko795f96e2014-10-27 02:45:22 +010063 .read_resources = pci_dev_read_resources,
64 .set_resources = pci_dev_set_resources,
65 .enable_resources = pci_dev_enable_resources,
66 .init = rce822_init,
67 .enable = rce822_enable,
68 .scan_bus = 0,
69 .ops_pci = &lops_pci,
70};
71
72static const unsigned short pci_device_ids[] = { 0xe822, 0xe823, 0 };
73
Vladimir Serbinenko633e8272015-05-15 11:10:08 +020074static const struct pci_driver rce822 __pci_driver = {
75 .ops = &rce822_ops,
Vladimir Serbinenko795f96e2014-10-27 02:45:22 +010076 .vendor = PCI_VENDOR_ID_RICOH,
77 .devices = pci_device_ids,
78};