blob: aa82dca560f1cc1a4825196ab07911293e9e8159 [file] [log] [blame]
Simon Glass53a68b32019-02-16 20:24:50 -07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2018 Google LLC
4 */
5
Simon Glass53a68b32019-02-16 20:24:50 -07006#include <dm.h>
7#include <pch.h>
8
9struct sandbox_pch_priv {
10 bool protect;
11};
12
13int sandbox_get_pch_spi_protect(struct udevice *dev)
14{
15 struct sandbox_pch_priv *priv = dev_get_priv(dev);
16
17 return priv->protect;
18}
19
20static int sandbox_pch_get_spi_base(struct udevice *dev, ulong *sbasep)
21{
22 *sbasep = 0x10;
23
24 return 0;
25}
26
27static int sandbox_pch_set_spi_protect(struct udevice *dev, bool protect)
28{
29 struct sandbox_pch_priv *priv = dev_get_priv(dev);
30
31 priv->protect = protect;
32
33 return 0;
34}
35
36static int sandbox_pch_get_gpio_base(struct udevice *dev, u32 *gbasep)
37{
38 *gbasep = 0x20;
39
40 return 0;
41}
42
43static int sandbox_pch_get_io_base(struct udevice *dev, u32 *iobasep)
44{
45 *iobasep = 0x30;
46
47 return 0;
48}
49
Simon Glassdbadbb72019-02-16 20:24:51 -070050int sandbox_pch_ioctl(struct udevice *dev, enum pch_req_t req, void *data,
51 int size)
52{
53 switch (req) {
54 case PCH_REQ_TEST1:
55 return -ENOSYS;
56 case PCH_REQ_TEST2:
57 return *(char *)data;
58 case PCH_REQ_TEST3:
59 *(char *)data = 'x';
60 return 1;
61 default:
62 return -ENOSYS;
63 }
64}
65
Simon Glass53a68b32019-02-16 20:24:50 -070066static const struct pch_ops sandbox_pch_ops = {
67 .get_spi_base = sandbox_pch_get_spi_base,
68 .set_spi_protect = sandbox_pch_set_spi_protect,
69 .get_gpio_base = sandbox_pch_get_gpio_base,
70 .get_io_base = sandbox_pch_get_io_base,
Simon Glassdbadbb72019-02-16 20:24:51 -070071 .ioctl = sandbox_pch_ioctl,
Simon Glass53a68b32019-02-16 20:24:50 -070072};
73
74static const struct udevice_id sandbox_pch_ids[] = {
75 { .compatible = "sandbox,pch" },
76 { }
77};
78
79U_BOOT_DRIVER(sandbox_pch_drv) = {
80 .name = "sandbox-pch",
81 .id = UCLASS_PCH,
82 .of_match = sandbox_pch_ids,
83 .ops = &sandbox_pch_ops,
Simon Glass8a2b47f2020-12-03 16:55:17 -070084 .priv_auto = sizeof(struct sandbox_pch_priv),
Simon Glass53a68b32019-02-16 20:24:50 -070085};