• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 
19 #ifndef __LINUX_PLATFORM_DEVICE_H__
20 #define __LINUX_PLATFORM_DEVICE_H__
21 
22 #include "linux/device.h"
23 
24 #ifdef __cplusplus
25 #if __cplusplus
26 extern "C" {
27 #endif /* __cplusplus */
28 #endif /* __cplusplus */
29 
30 #define IORESOURCE_IO  0x00000100 /* PCI/ISA I/O ports */
31 #define IORESOURCE_MEM 0x00000200
32 #define IORESOURCE_REG 0x00000300 /* Register offsets */
33 #define IORESOURCE_IRQ 0x00000400
34 #define IORESOURCE_DMA 0x00000800
35 #define IORESOURCE_BUS 0x00001000
36 
37 typedef uintptr_t resource_size_t;
38 
39 struct resource {
40     resource_size_t start;
41     resource_size_t end;
42     const char *name;
43     unsigned long flags;
44     unsigned long desc;
45     struct resource *parent, *sibling, *child;
46 };
47 
48 /* *
49  * @ingroup los_drivers
50  * Define the structure of the parameters used for platform device creation.
51  */
52 struct platform_device {
53     const char *name;
54     struct device dev;
55     int id;
56     UINT32 num_resources;
57     struct resource *resource;
58 };
59 
60 struct pm_message_t {
61     int event;
62 };
63 
64 /* *
65  * @ingroup los_drivers
66  * Define the structure of the parameters used for platform driver creation.
67  */
68 struct platform_driver {
69     int (*probe)(struct platform_device *);
70     int (*remove)(struct platform_device *);
71     void (*shutdown)(struct platform_device *);
72     int (*suspend)(struct platform_device *);
73     int (*resume)(struct platform_device *);
74     struct device_driver driver;
75 };
76 
77 /* *
78  * @ingroup los_drivers
79  * @brief register a platform_driver to platform bus.
80  *
81  * @par Description:
82  * <ul>
83  * <li>This API is used to register a platform_driver to platform bus.</li>
84  * </ul>
85  * @attention
86  * <ul>
87  * <li>The platform bus system is a soft bus that is used to deal the host device and driver.</li>
88  * <li>The same bus node can not be registered twice.</li>
89  * </ul>
90  *
91  * @param  drv      [IN]A point to platform_driver.
92  *
93  * @retval #LOS_ERRNO_DRIVER_INPUT_INVALID        Invalid input.drv and drv.driver->name can not be NULL.
94  * @retval #LOS_ERRNO_DRIVER_DRIVER_REGISTERED    Driver register twice.
95  * @retval #LOS_ERRNO_DRIVER_BUS_MUX_FAIL         Mux create failed.
96  * @retval #LOS_ERRNO_DRIVER_BUS_INVALID          Bus is not in system.
97  * @retval #LOS_ERRNO_DRIVER_BUS_MATCH_FAIL       Do match failed.
98  * @retval #LOS_ERRNO_DRIVER_BUS_PROBE_FAIL       Do probe failed.
99  * @retval #LOS_OK        The platform_driver register success.
100  * @par Dependency:
101  * <ul><li>platform_device.h: the header file that contains the API declaration.</li></ul>
102  */
103 extern UINT32 platform_driver_register(struct platform_driver *drv);
104 
105 /* *
106  * @ingroup los_drivers
107  * @brief unregister a  platform_driver from the platform bus.
108  *
109  * @par Description:
110  * <ul>
111  * <li>This API is used to unregister a platform_driver from the platform bus.</li>
112  * </ul>
113  *
114  * @param  drv      [IN]A point to platform_driver. drv/drv->name/drv->bus can not be NULL.
115  *
116  * @retval #LOS_ERRNO_DRIVER_INPUT_INVALID        Invalid input.drv and drv.driver->name can not be NULL.
117  * @retval #LOS_ERRNO_DRIVER_DRIVER_NOTFOUND      Driver not found.
118  * @retval #LOS_ERRNO_DRIVER_BUS_INVALID          Bus is not in system.
119  * @retval #LOS_ERRNO_DRIVER_DEVICE_BUSY          Device busy.
120  * @retval #LOS_OK                                The platform_driver unregister success.
121  * @par Dependency:
122  * <ul><li>platform_device.h: the header file that contains the API declaration.</li></ul>
123  */
124 extern UINT32 platform_driver_unregister(struct platform_driver *drv);
125 
126 /* *
127  * @ingroup los_drivers
128  * @brief register a platform_device to platform bus.
129  *
130  * @par Description:
131  * <ul>
132  * <li>This API is used to register a platform_device to platform bus.</li>
133  * </ul>
134  * @attention
135  * <ul>
136  * <li>The same platform_device node can not be registered twice.</li>
137  * </ul>
138  *
139  * @param  dev      [IN] A point to platform_device. num_resources can not bigger than the count of resource_array.
140  *
141  * @retval #LOS_ERRNO_DRIVER_INPUT_INVALID       Invalid input.pdev and pdev->name can not be NULL.
142  * @retval #LOS_ERRNO_DRIVER_DEVICE_REGISTERED    Device register twice.
143  * @retval #LOS_ERRNO_DRIVER_DEVICE_INITIALFAIL   Mux create failed.
144  * @retval #LOS_ERRNO_DRIVER_DEVICE_BOUNDED       Do attach failed.device has bounded.
145  * @retval #LOS_ERRNO_DRIVER_BUS_MATCH_FAIL       Do match failed.
146  * @retval #LOS_ERRNO_DRIVER_BUS_PROBE_FAIL       Do probe failed.
147  * @retval #LOS_OK        The platform_device register success.
148  * @par Dependency:
149  * <ul><li>platform_device.h: the header file that contains the API declaration.</li></ul>
150  */
151 extern UINT32 platform_device_register(struct platform_device *dev);
152 
153 /* *
154  * @ingroup los_drivers
155  * @brief unregister a  platform_device from the platform bus.
156  *
157  * @par Description:
158  * <ul>
159  * <li>This API is used to unregister a platform_device from the platform bus.</li>
160  * </ul>
161  *
162  * @param  dev      [IN]A point to platform_device.If dev is NULL,this function will do nothing.
163  *
164  * @par Dependency:
165  * <ul><li>platform_device.h: the header file that contains the API declaration.</li></ul>
166  */
167 extern VOID platform_device_unregister(struct platform_device *dev);
168 
169 extern UINT32 platform_device_add(struct platform_device *dev);
170 
171 extern struct resource *platform_get_resource(struct platform_device *, unsigned int, unsigned int);
172 extern struct resource *platform_get_resource_byname(struct platform_device *, unsigned int, const char *);
173 extern long platform_get_irq(struct platform_device *, unsigned int);
174 
175 extern VOID *platform_ioremap_resource(struct resource *res);
176 
177 #define to_platform_driver(drv) (container_of((drv), struct platform_driver, driver))
178 #define to_platform_device(x) container_of((x), struct platform_device, dev)
179 
resource_size(const struct resource * res)180 STATIC INLINE resource_size_t resource_size(const struct resource *res)
181 {
182     return res->end - res->start + 1;
183 }
184 
platform_get_drvdata(const struct platform_device * dev)185 STATIC INLINE VOID *platform_get_drvdata(const struct platform_device *dev)
186 {
187     if (dev == NULL) {
188         PRINT_WARN("platform_get_drvdata :the input dev is NULL!\n");
189         return NULL;
190     }
191     return dev_get_drvdata(&dev->dev);
192 }
193 
platform_set_drvdata(struct platform_device * dev,VOID * data)194 STATIC INLINE VOID platform_set_drvdata(struct platform_device *dev, VOID *data)
195 {
196     if (dev == NULL) {
197         PRINT_WARN("platform_set_drvdata :the input dev is NULL!\n");
198         return;
199     }
200     dev_set_drvdata(&dev->dev, data);
201 }
202 
203 #ifdef __cplusplus
204 #if __cplusplus
205 }
206 #endif /* __cplusplus */
207 #endif /* __cplusplus */
208 
209 #endif
210