Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * motor  driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2020 Rockchip Electronics Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) //#define DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/of_gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/fb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/of_irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/wakelock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/hrtimer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/pwm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <media/v4l2-subdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <media/v4l2-ctrls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <media/v4l2-device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/version.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/rk-camera-module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/rk_vcm_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define DRIVER_VERSION	KERNEL_VERSION(0, 0x01, 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define DRIVER_NAME "hall-dc"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define IRIS_MAX_LOG 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define IRIS_LOG_STEP 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define PWM_PERIOD_DEF 333333
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) struct motor_dev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	struct v4l2_subdev sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	struct v4l2_ctrl_handler ctrl_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct pwm_device *pwm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct mutex mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct pwm_state pwm_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	u32 module_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	const char *module_facing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static int motor_dev_parse_dt(struct motor_dev *motor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct device_node *node = motor->dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	motor->pwm = devm_pwm_get(motor->dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (IS_ERR(motor->pwm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		error = PTR_ERR(motor->pwm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		if (error != -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 			dev_err(motor->dev, "Failed to request PWM device: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (motor->pwm && motor->pwm->args.period != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		motor->pwm_state.period = motor->pwm->args.period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		motor->pwm_state.polarity = motor->pwm->args.polarity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)         } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		motor->pwm_state.period = PWM_PERIOD_DEF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		motor->pwm_state.polarity = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	ret = of_property_read_u32(node, RKMODULE_CAMERA_MODULE_INDEX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 				   &motor->module_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	ret |= of_property_read_string(node, RKMODULE_CAMERA_MODULE_FACING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 				       &motor->module_facing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		dev_err(motor->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			"could not get module information!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static int motor_s_ctrl(struct v4l2_ctrl *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct motor_dev *motor = container_of(ctrl->handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 					     struct motor_dev, ctrl_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	switch (ctrl->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	case V4L2_CID_IRIS_ABSOLUTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		motor->pwm_state.enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		motor->pwm_state.duty_cycle =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			div64_u64((u64)motor->pwm_state.period * ctrl->val, IRIS_MAX_LOG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		pwm_apply_state(motor->pwm, &motor->pwm_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		dev_dbg(motor->dev, "iris, ctrl->val %d, pwm duty %lld, period %lld, polarity %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			ctrl->val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			motor->pwm_state.duty_cycle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			motor->pwm_state.period,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			motor->pwm_state.polarity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		dev_err(motor->dev, "not support cmd %d\n", ctrl->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static long motor_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static const struct v4l2_subdev_core_ops motor_core_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	.ioctl = motor_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static const struct v4l2_subdev_ops motor_subdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	.core	= &motor_core_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static const struct v4l2_ctrl_ops motor_ctrl_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	.s_ctrl = motor_s_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static int motor_initialize_controls(struct motor_dev *motor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct v4l2_ctrl_handler *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	handler = &motor->ctrl_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	ret = v4l2_ctrl_handler_init(handler, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	handler->lock = &motor->mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	v4l2_ctrl_new_std(handler, &motor_ctrl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		V4L2_CID_IRIS_ABSOLUTE, 0, IRIS_MAX_LOG, IRIS_LOG_STEP, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (handler->error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		ret = handler->error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		dev_err(motor->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			"Failed to init controls(%d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		goto err_free_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	motor->sd.ctrl_handler = handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) err_free_handler:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	v4l2_ctrl_handler_free(handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static int motor_dev_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	struct motor_dev *motor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	struct v4l2_subdev *sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	char facing[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	dev_info(&pdev->dev, "driver version: %02x.%02x.%02x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		DRIVER_VERSION >> 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		(DRIVER_VERSION & 0xff00) >> 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		DRIVER_VERSION & 0x00ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	motor = devm_kzalloc(&pdev->dev, sizeof(*motor), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (!motor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	motor->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	dev_set_name(motor->dev, "motor");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	dev_set_drvdata(motor->dev, motor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (motor_dev_parse_dt(motor)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		dev_err(motor->dev, "parse dt error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	mutex_init(&motor->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	v4l2_subdev_init(&motor->sd, &motor_subdev_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	motor->sd.owner = pdev->dev.driver->owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	motor->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	motor->sd.dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	v4l2_set_subdevdata(&motor->sd, pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	platform_set_drvdata(pdev, &motor->sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	motor_initialize_controls(motor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	ret = media_entity_pads_init(&motor->sd.entity, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	sd = &motor->sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	sd->entity.function = MEDIA_ENT_F_LENS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	sd->entity.flags = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	memset(facing, 0, sizeof(facing));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (strcmp(motor->module_facing, "back") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		facing[0] = 'b';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		facing[0] = 'f';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	snprintf(sd->name, sizeof(sd->name), "m%02d_%s_%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		 motor->module_index, facing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		 DRIVER_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	ret = v4l2_async_register_subdev(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		dev_err(&pdev->dev, "v4l2 async register subdev failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	dev_info(motor->dev, "gpio motor driver probe success\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) err_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	v4l2_ctrl_handler_free(&motor->ctrl_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	v4l2_device_unregister_subdev(&motor->sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	media_entity_cleanup(&motor->sd.entity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static int motor_dev_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	struct v4l2_subdev *sd = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct motor_dev *motor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		motor = v4l2_get_subdevdata(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	if (sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		v4l2_device_unregister_subdev(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	v4l2_ctrl_handler_free(&motor->ctrl_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	media_entity_cleanup(&motor->sd.entity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #if defined(CONFIG_OF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static const struct of_device_id motor_dev_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	{ .compatible = "rockchip,hall-dc", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	{},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static struct platform_driver motor_dev_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		.name = DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		.of_match_table = of_match_ptr(motor_dev_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	.probe = motor_dev_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	.remove = motor_dev_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) module_platform_driver(motor_dev_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) MODULE_ALIAS("platform:motor");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) MODULE_AUTHOR("ROCKCHIP");