blob: 76f552527e37724acd4c52092da1432be6cae077 [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
6#include <common.h>
7#include <dm.h>
8#include <pch.h>
9
10struct sandbox_pch_priv {
11 bool protect;
12};
13
14int sandbox_get_pch_spi_protect(struct udevice *dev)
15{
16 struct sandbox_pch_priv *priv = dev_get_priv(dev);
17
18 return priv->protect;
19}
20
21static int sandbox_pch_get_spi_base(struct udevice *dev, ulong *sbasep)
22{
23 *sbasep = 0x10;
24
25 return 0;
26}
27
28static int sandbox_pch_set_spi_protect(struct udevice *dev, bool protect)
29{
30 struct sandbox_pch_priv *priv = dev_get_priv(dev);
31
32 priv->protect = protect;
33
34 return 0;
35}
36
37static int sandbox_pch_get_gpio_base(struct udevice *dev, u32 *gbasep)
38{
39 *gbasep = 0x20;
40
41 return 0;
42}
43
44static int sandbox_pch_get_io_base(struct udevice *dev, u32 *iobasep)
45{
46 *iobasep = 0x30;
47
48 return 0;
49}
50
Simon Glassdbadbb72019-02-16 20:24:51 -070051int sandbox_pch_ioctl(struct udevice *dev, enum pch_req_t req, void *data,
52 int size)
53{
54 switch (req) {
55 case PCH_REQ_TEST1:
56 return -ENOSYS;
57 case PCH_REQ_TEST2:
58 return *(char *)data;
59 case PCH_REQ_TEST3:
60 *(char *)data = 'x';
61 return 1;
62 default:
63 return -ENOSYS;
64 }
65}
66
Simon Glass53a68b32019-02-16 20:24:50 -070067static const struct pch_ops sandbox_pch_ops = {
68 .get_spi_base = sandbox_pch_get_spi_base,
69 .set_spi_protect = sandbox_pch_set_spi_protect,
70 .get_gpio_base = sandbox_pch_get_gpio_base,
71 .get_io_base = sandbox_pch_get_io_base,
Simon Glassdbadbb72019-02-16 20:24:51 -070072 .ioctl = sandbox_pch_ioctl,
Simon Glass53a68b32019-02-16 20:24:50 -070073};
74
75static const struct udevice_id sandbox_pch_ids[] = {
76 { .compatible = "sandbox,pch" },
77 { }
78};
79
80U_BOOT_DRIVER(sandbox_pch_drv) = {
81 .name = "sandbox-pch",
82 .id = UCLASS_PCH,
83 .of_match = sandbox_pch_ids,
84 .ops = &sandbox_pch_ops,
85 .priv_auto_alloc_size = sizeof(struct sandbox_pch_priv),
86};