1 /**
2  * Copyright (C) 2015-2021 Alibaba Group Holding Limited
3  */
4 
5 #ifndef _U_PLATFORM_BUS_H_
6 #define _U_PLATFORM_BUS_H_
7 #include <stdbool.h>
8 
9 #include "aos/list.h"
10 
11 #include <drivers/char/u_device.h>
12 #include <drivers/char/u_driver.h>
13 #include <drivers/char/u_bus.h>
14 
15 typedef struct u_platform_device {
16 	const char	*name;
17 	int		id;
18 	struct u_device	dev;
19 
20 #if 0 //TODO: how to originize hardware resources
21 	unsigned		num_resources;
22 	struct u_resource	*resource;
23 #endif
24 } u_platform_device_t;
25 
26 typedef struct u_platform_driver {
27 	/* user can select either legacy driver API or linux-like drivers */
28 	/* for legacy drivers */
29 	int (*init)(struct u_platform_device *_dev);
30 	int (*deinit)(struct u_platform_device *_dev);
31 	int (*pm)(struct u_platform_device *dev, u_pm_ops_t state);
32 
33 	/* for linux-like drivers */
34 	int (*probe)(struct u_platform_device *);
35 	int (*remove)(struct u_platform_device *);
36 	void (*shutdown)(struct u_platform_device *);
37 	int (*suspend)(struct u_platform_device *, /*u_pm_ops_t*/int state);
38 	int (*resume)(struct u_platform_device *);
39 
40 	u_driver_t driver;
41 	u_bus_t *bus;
42 } u_platform_driver_t;
43 
44 #define to_u_platform_device(x) aos_container_of((x), struct u_platform_device, dev)
45 
46 #define to_u_platform_driver(x) aos_container_of((x), struct u_platform_driver, driver)
47 
u_platform_get_user_data(const struct u_platform_device * pdev)48 static inline void *u_platform_get_user_data(const struct u_platform_device *pdev)
49 {
50 	return pdev->dev.user_data;
51 }
52 
u_platform_set_user_data(struct u_platform_device * pdev,void * data)53 static inline void u_platform_set_user_data(struct u_platform_device *pdev,
54                                         void *data)
55 {
56 	pdev->dev.user_data = data;
57 }
58 
59 int u_platform_device_init(void);
60 
61 u_platform_device_t* u_platform_device_alloc(void);
62 int u_platform_device_register(u_platform_device_t *dev);
63 void u_platform_device_del(u_platform_device_t *pdev);
64 int u_platform_device_unregister(u_platform_device_t *dev);
65 
66 int u_platform_driver_register(u_platform_driver_t *drv);
67 int u_platform_driver_unregister(u_platform_driver_t *drv);
68 
69 #endif //_U_PLATFORM_BUS_H_
70