xref: /openbmc/u-boot/include/pch.h (revision 1260f8c0efe126cf952c1bc19d975af34908a79d)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (c) 2015 Google, Inc
4  * Written by Simon Glass <sjg@chromium.org>
5  */
6 
7 #ifndef __pch_h
8 #define __pch_h
9 
10 #define PCH_RCBA		0xf0
11 
12 #define BIOS_CTRL_BIOSWE	BIT(0)
13 
14 /* All the supported PCH ioctls */
15 enum pch_req_t {
16 	PCH_REQ_TEST1,		/* Test requests for sandbox driver */
17 	PCH_REQ_TEST2,
18 	PCH_REQ_TEST3,
19 
20 	PCH_REQ_COUNT,		/* Number of ioctrls supported */
21 };
22 
23 /**
24  * struct pch_ops - Operations for the Platform Controller Hub
25  *
26  * Consider using ioctl() to add rarely used or driver-specific operations.
27  */
28 struct pch_ops {
29 	/**
30 	 * get_spi_base() - get the address of SPI base
31 	 *
32 	 * @dev:	PCH device to check
33 	 * @sbasep:	Returns address of SPI base if available, else 0
34 	 * @return 0 if OK, -ve on error (e.g. there is no SPI base)
35 	 */
36 	int (*get_spi_base)(struct udevice *dev, ulong *sbasep);
37 
38 	/**
39 	 * set_spi_protect() - set whether SPI flash is protected or not
40 	 *
41 	 * @dev:	PCH device to adjust
42 	 * @protect:	true to protect, false to unprotect
43 	 *
44 	 * @return 0 on success, -ENOSYS if not implemented
45 	 */
46 	int (*set_spi_protect)(struct udevice *dev, bool protect);
47 
48 	/**
49 	 * get_gpio_base() - get the address of GPIO base
50 	 *
51 	 * @dev:	PCH device to check
52 	 * @gbasep:	Returns address of GPIO base if available, else 0
53 	 * @return 0 if OK, -ve on error (e.g. there is no GPIO base)
54 	 */
55 	int (*get_gpio_base)(struct udevice *dev, u32 *gbasep);
56 
57 	/**
58 	 * get_io_base() - get the address of IO base
59 	 *
60 	 * @dev:	PCH device to check
61 	 * @iobasep:	Returns address of IO base if available, else 0
62 	 * @return 0 if OK, -ve on error (e.g. there is no IO base)
63 	 */
64 	int (*get_io_base)(struct udevice *dev, u32 *iobasep);
65 
66 	/**
67 	 * ioctl() - perform misc read/write operations
68 	 *
69 	 * This is a catch-all operation intended to avoid adding lots of
70 	 * methods to this uclass, of which few are commonly used. Uncommon
71 	 * operations that pertain only to a few devices in this uclass should
72 	 * use this method instead of adding new methods.
73 	 *
74 	 * @dev:	PCH device to check
75 	 * @req:	PCH request ID
76 	 * @data:	Input/output data
77 	 * @size:	Size of input data (and maximum size of output data)
78 	 * @return size of output data on sucesss, -ve on error
79 	 */
80 	int (*ioctl)(struct udevice *dev, enum pch_req_t req, void *data,
81 		     int size);
82 };
83 
84 #define pch_get_ops(dev)        ((struct pch_ops *)(dev)->driver->ops)
85 
86 /**
87  * pch_get_spi_base() - get the address of SPI base
88  *
89  * @dev:	PCH device to check
90  * @sbasep:	Returns address of SPI base if available, else 0
91  * @return 0 if OK, -ve on error (e.g. there is no SPI base)
92  */
93 int pch_get_spi_base(struct udevice *dev, ulong *sbasep);
94 
95 /**
96  * set_spi_protect() - set whether SPI flash is protected or not
97  *
98  * @dev:	PCH device to adjust
99  * @protect:	true to protect, false to unprotect
100  *
101  * @return 0 on success, -ENOSYS if not implemented
102  */
103 int pch_set_spi_protect(struct udevice *dev, bool protect);
104 
105 /**
106  * pch_get_gpio_base() - get the address of GPIO base
107  *
108  * @dev:	PCH device to check
109  * @gbasep:	Returns address of GPIO base if available, else 0
110  * @return 0 if OK, -ve on error (e.g. there is no GPIO base)
111  */
112 int pch_get_gpio_base(struct udevice *dev, u32 *gbasep);
113 
114 /**
115  * pch_get_io_base() - get the address of IO base
116  *
117  * @dev:	PCH device to check
118  * @iobasep:	Returns address of IO base if available, else 0
119  * @return 0 if OK, -ve on error (e.g. there is no IO base)
120  */
121 int pch_get_io_base(struct udevice *dev, u32 *iobasep);
122 
123 /**
124  * pch_ioctl() - perform misc read/write operations
125  *
126  * This is a catch-all operation intended to avoid adding lots of
127  * methods to this uclass, of which few are commonly used. Uncommon
128  * operations that pertain only to a few devices in this uclass should
129  * use this method instead of adding new methods.
130  *
131  * @dev:	PCH device to check
132  * @req:	PCH request ID
133  * @data:	Input/output data
134  * @size:	Size of input data (and maximum size of output data)
135  * @return size of output data on sucesss, -ve on error
136  */
137 int pch_ioctl(struct udevice *dev, ulong req, void *data, int size);
138 
139 #endif
140