Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: v4l2-core: move spi helpers out of v4l2-common.c

Separate the spi helpers to v4l2-spi.c, in order to get rid
of the ifdefery. No functional changes intended, this is
just a cosmetic change to organize the code better.

Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

authored by

Ezequiel Garcia and committed by
Mauro Carvalho Chehab
7c795df5 ff35213f

+82 -67
+1
drivers/media/v4l2-core/Makefile
··· 11 11 videodev-$(CONFIG_COMPAT) += v4l2-compat-ioctl32.o 12 12 videodev-$(CONFIG_TRACEPOINTS) += v4l2-trace.o 13 13 videodev-$(CONFIG_MEDIA_CONTROLLER) += v4l2-mc.o 14 + videodev-$(CONFIG_SPI) += v4l2-spi.o 14 15 15 16 obj-$(CONFIG_V4L2_FWNODE) += v4l2-fwnode.o 16 17 obj-$(CONFIG_VIDEO_V4L2) += videodev.o
-65
drivers/media/v4l2-core/v4l2-common.c
··· 41 41 #include <linux/string.h> 42 42 #include <linux/errno.h> 43 43 #include <linux/i2c.h> 44 - #if defined(CONFIG_SPI) 45 - #include <linux/spi/spi.h> 46 - #endif 47 44 #include <linux/uaccess.h> 48 45 #include <asm/pgtable.h> 49 46 #include <asm/io.h> ··· 231 234 EXPORT_SYMBOL_GPL(v4l2_i2c_tuner_addrs); 232 235 233 236 #endif /* defined(CONFIG_I2C) */ 234 - 235 - #if defined(CONFIG_SPI) 236 - 237 - /* Load an spi sub-device. */ 238 - 239 - void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi, 240 - const struct v4l2_subdev_ops *ops) 241 - { 242 - v4l2_subdev_init(sd, ops); 243 - sd->flags |= V4L2_SUBDEV_FL_IS_SPI; 244 - /* the owner is the same as the spi_device's driver owner */ 245 - sd->owner = spi->dev.driver->owner; 246 - sd->dev = &spi->dev; 247 - /* spi_device and v4l2_subdev point to one another */ 248 - v4l2_set_subdevdata(sd, spi); 249 - spi_set_drvdata(spi, sd); 250 - /* initialize name */ 251 - snprintf(sd->name, sizeof(sd->name), "%s %s", 252 - spi->dev.driver->name, dev_name(&spi->dev)); 253 - } 254 - EXPORT_SYMBOL_GPL(v4l2_spi_subdev_init); 255 - 256 - struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev, 257 - struct spi_master *master, struct spi_board_info *info) 258 - { 259 - struct v4l2_subdev *sd = NULL; 260 - struct spi_device *spi = NULL; 261 - 262 - BUG_ON(!v4l2_dev); 263 - 264 - if (info->modalias[0]) 265 - request_module(info->modalias); 266 - 267 - spi = spi_new_device(master, info); 268 - 269 - if (spi == NULL || spi->dev.driver == NULL) 270 - goto error; 271 - 272 - if (!try_module_get(spi->dev.driver->owner)) 273 - goto error; 274 - 275 - sd = spi_get_drvdata(spi); 276 - 277 - /* Register with the v4l2_device which increases the module's 278 - use count as well. */ 279 - if (v4l2_device_register_subdev(v4l2_dev, sd)) 280 - sd = NULL; 281 - 282 - /* Decrease the module use count to match the first try_module_get. */ 283 - module_put(spi->dev.driver->owner); 284 - 285 - error: 286 - /* If we have a client but no subdev, then something went wrong and 287 - we must unregister the client. */ 288 - if (!sd) 289 - spi_unregister_device(spi); 290 - 291 - return sd; 292 - } 293 - EXPORT_SYMBOL_GPL(v4l2_spi_new_subdev); 294 - 295 - #endif /* defined(CONFIG_SPI) */ 296 237 297 238 /* Clamp x to be between min and max, aligned to a multiple of 2^align. min 298 239 * and max don't have to be aligned, but there must be at least one valid
+65
drivers/media/v4l2-core/v4l2-spi.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * v4l2-spi - SPI helpers for Video4Linux2 4 + */ 5 + 6 + #include <linux/module.h> 7 + #include <linux/spi/spi.h> 8 + #include <media/v4l2-common.h> 9 + #include <media/v4l2-device.h> 10 + 11 + void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi, 12 + const struct v4l2_subdev_ops *ops) 13 + { 14 + v4l2_subdev_init(sd, ops); 15 + sd->flags |= V4L2_SUBDEV_FL_IS_SPI; 16 + /* the owner is the same as the spi_device's driver owner */ 17 + sd->owner = spi->dev.driver->owner; 18 + sd->dev = &spi->dev; 19 + /* spi_device and v4l2_subdev point to one another */ 20 + v4l2_set_subdevdata(sd, spi); 21 + spi_set_drvdata(spi, sd); 22 + /* initialize name */ 23 + snprintf(sd->name, sizeof(sd->name), "%s %s", 24 + spi->dev.driver->name, dev_name(&spi->dev)); 25 + } 26 + EXPORT_SYMBOL_GPL(v4l2_spi_subdev_init); 27 + 28 + struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev, 29 + struct spi_master *master, struct spi_board_info *info) 30 + { 31 + struct v4l2_subdev *sd = NULL; 32 + struct spi_device *spi = NULL; 33 + 34 + BUG_ON(!v4l2_dev); 35 + 36 + if (info->modalias[0]) 37 + request_module(info->modalias); 38 + 39 + spi = spi_new_device(master, info); 40 + 41 + if (spi == NULL || spi->dev.driver == NULL) 42 + goto error; 43 + 44 + if (!try_module_get(spi->dev.driver->owner)) 45 + goto error; 46 + 47 + sd = spi_get_drvdata(spi); 48 + 49 + /* Register with the v4l2_device which increases the module's 50 + use count as well. */ 51 + if (v4l2_device_register_subdev(v4l2_dev, sd)) 52 + sd = NULL; 53 + 54 + /* Decrease the module use count to match the first try_module_get. */ 55 + module_put(spi->dev.driver->owner); 56 + 57 + error: 58 + /* If we have a client but no subdev, then something went wrong and 59 + we must unregister the client. */ 60 + if (!sd) 61 + spi_unregister_device(spi); 62 + 63 + return sd; 64 + } 65 + EXPORT_SYMBOL_GPL(v4l2_spi_new_subdev);
+16 -2
include/media/v4l2-common.h
··· 216 216 /* ------------------------------------------------------------------------- */ 217 217 218 218 /* SPI Helper functions */ 219 - #if defined(CONFIG_SPI) 220 219 221 220 #include <linux/spi/spi.h> 222 221 223 - struct spi_device; 222 + #if defined(CONFIG_SPI) 224 223 225 224 /** 226 225 * v4l2_spi_new_subdev - Load an spi module and return an initialized ··· 245 246 */ 246 247 void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi, 247 248 const struct v4l2_subdev_ops *ops); 249 + 250 + #else 251 + 252 + static inline struct v4l2_subdev * 253 + v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev, 254 + struct spi_master *master, struct spi_board_info *info) 255 + { 256 + return NULL; 257 + } 258 + 259 + static inline void 260 + v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi, 261 + const struct v4l2_subdev_ops *ops) 262 + {} 263 + 248 264 #endif 249 265 250 266 /* ------------------------------------------------------------------------- */