diff options
author | Xiao Guangrong <guangrong.xiao@linux.intel.com> | 2018-06-29 20:53:16 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-07-15 07:55:45 -0400 |
commit | 5b57d02a2f94bb04c6b36932412f7f3b1bb38518 (patch) | |
tree | 3065909e12962864351492bb6beb2b03a55cc3e2 /drivers/fpga/dfl.c | |
parent | 5d56e117001996766c3dab5767663b0c43b76639 (diff) |
fpga: dfl: add feature device infrastructure
This patch abstracts the common operations of the sub features and defines
the feature_ops data structure, including init, uinit and ioctl function
pointers. And this patch adds some common helper functions for FME and AFU
drivers, e.g. dfl_feature_dev_use_begin/end which are used to ensure
exclusive usage of the feature device file.
Signed-off-by: Tim Whisonant <tim.whisonant@intel.com>
Signed-off-by: Enno Luebbers <enno.luebbers@intel.com>
Signed-off-by: Shiva Rao <shiva.rao@intel.com>
Signed-off-by: Christopher Rauer <christopher.rauer@intel.com>
Signed-off-by: Kang Luwei <luwei.kang@intel.com>
Signed-off-by: Zhang Yi <yi.z.zhang@intel.com>
Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
Signed-off-by: Wu Hao <hao.wu@intel.com>
Acked-by: Alan Tull <atull@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/fpga/dfl.c')
-rw-r--r-- | drivers/fpga/dfl.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/drivers/fpga/dfl.c b/drivers/fpga/dfl.c index 68e0b45617b2..e2c72c5dd9e6 100644 --- a/drivers/fpga/dfl.c +++ b/drivers/fpga/dfl.c | |||
@@ -136,6 +136,77 @@ static enum dfl_id_type dfh_id_to_type(u32 id) | |||
136 | return DFL_ID_MAX; | 136 | return DFL_ID_MAX; |
137 | } | 137 | } |
138 | 138 | ||
139 | /** | ||
140 | * dfl_fpga_dev_feature_uinit - uinit for sub features of dfl feature device | ||
141 | * @pdev: feature device. | ||
142 | */ | ||
143 | void dfl_fpga_dev_feature_uinit(struct platform_device *pdev) | ||
144 | { | ||
145 | struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev); | ||
146 | struct dfl_feature *feature; | ||
147 | |||
148 | dfl_fpga_dev_for_each_feature(pdata, feature) | ||
149 | if (feature->ops) { | ||
150 | feature->ops->uinit(pdev, feature); | ||
151 | feature->ops = NULL; | ||
152 | } | ||
153 | } | ||
154 | EXPORT_SYMBOL_GPL(dfl_fpga_dev_feature_uinit); | ||
155 | |||
156 | static int dfl_feature_instance_init(struct platform_device *pdev, | ||
157 | struct dfl_feature_platform_data *pdata, | ||
158 | struct dfl_feature *feature, | ||
159 | struct dfl_feature_driver *drv) | ||
160 | { | ||
161 | int ret; | ||
162 | |||
163 | ret = drv->ops->init(pdev, feature); | ||
164 | if (ret) | ||
165 | return ret; | ||
166 | |||
167 | feature->ops = drv->ops; | ||
168 | |||
169 | return ret; | ||
170 | } | ||
171 | |||
172 | /** | ||
173 | * dfl_fpga_dev_feature_init - init for sub features of dfl feature device | ||
174 | * @pdev: feature device. | ||
175 | * @feature_drvs: drvs for sub features. | ||
176 | * | ||
177 | * This function will match sub features with given feature drvs list and | ||
178 | * use matched drv to init related sub feature. | ||
179 | * | ||
180 | * Return: 0 on success, negative error code otherwise. | ||
181 | */ | ||
182 | int dfl_fpga_dev_feature_init(struct platform_device *pdev, | ||
183 | struct dfl_feature_driver *feature_drvs) | ||
184 | { | ||
185 | struct dfl_feature_platform_data *pdata = dev_get_platdata(&pdev->dev); | ||
186 | struct dfl_feature_driver *drv = feature_drvs; | ||
187 | struct dfl_feature *feature; | ||
188 | int ret; | ||
189 | |||
190 | while (drv->ops) { | ||
191 | dfl_fpga_dev_for_each_feature(pdata, feature) { | ||
192 | /* match feature and drv using id */ | ||
193 | if (feature->id == drv->id) { | ||
194 | ret = dfl_feature_instance_init(pdev, pdata, | ||
195 | feature, drv); | ||
196 | if (ret) | ||
197 | goto exit; | ||
198 | } | ||
199 | } | ||
200 | drv++; | ||
201 | } | ||
202 | |||
203 | return 0; | ||
204 | exit: | ||
205 | dfl_fpga_dev_feature_uinit(pdev); | ||
206 | return ret; | ||
207 | } | ||
208 | EXPORT_SYMBOL_GPL(dfl_fpga_dev_feature_init); | ||
209 | |||
139 | static void dfl_chardev_uinit(void) | 210 | static void dfl_chardev_uinit(void) |
140 | { | 211 | { |
141 | int i; | 212 | int i; |