summaryrefslogtreecommitdiff
path: root/drivers/pch/sandbox_pch.c
blob: 76f552527e37724acd4c52092da1432be6cae077 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright 2018 Google LLC
 */

#include <common.h>
#include <dm.h>
#include <pch.h>

struct sandbox_pch_priv {
	bool protect;
};

int sandbox_get_pch_spi_protect(struct udevice *dev)
{
	struct sandbox_pch_priv *priv = dev_get_priv(dev);

	return priv->protect;
}

static int sandbox_pch_get_spi_base(struct udevice *dev, ulong *sbasep)
{
	*sbasep = 0x10;

	return 0;
}

static int sandbox_pch_set_spi_protect(struct udevice *dev, bool protect)
{
	struct sandbox_pch_priv *priv = dev_get_priv(dev);

	priv->protect = protect;

	return 0;
}

static int sandbox_pch_get_gpio_base(struct udevice *dev, u32 *gbasep)
{
	*gbasep = 0x20;

	return 0;
}

static int sandbox_pch_get_io_base(struct udevice *dev, u32 *iobasep)
{
	*iobasep = 0x30;

	return 0;
}

int sandbox_pch_ioctl(struct udevice *dev, enum pch_req_t req, void *data,
		      int size)
{
	switch (req) {
	case PCH_REQ_TEST1:
		return -ENOSYS;
	case PCH_REQ_TEST2:
		return *(char *)data;
	case PCH_REQ_TEST3:
		*(char *)data = 'x';
		return 1;
	default:
		return -ENOSYS;
	}
}

static const struct pch_ops sandbox_pch_ops = {
	.get_spi_base	= sandbox_pch_get_spi_base,
	.set_spi_protect = sandbox_pch_set_spi_protect,
	.get_gpio_base	= sandbox_pch_get_gpio_base,
	.get_io_base = sandbox_pch_get_io_base,
	.ioctl		= sandbox_pch_ioctl,
};

static const struct udevice_id sandbox_pch_ids[] = {
	{ .compatible = "sandbox,pch" },
	{ }
};

U_BOOT_DRIVER(sandbox_pch_drv) = {
	.name		= "sandbox-pch",
	.id		= UCLASS_PCH,
	.of_match	= sandbox_pch_ids,
	.ops		= &sandbox_pch_ops,
	.priv_auto_alloc_size	= sizeof(struct sandbox_pch_priv),
};