^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) * Rockchip driver for IR-Cuter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2020 Fuzhou Rockchip Electronics Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * V0.0X01.0X00 first version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^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/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <media/v4l2-subdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <media/v4l2-ctrls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <media/v4l2-device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/version.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/rk-camera-module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define RK_IRCUT_NAME "ircut"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) //#define USED_SYS_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) enum IRCUT_STATE_e {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) IRCUT_STATE_CLOSED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) IRCUT_STATE_CLOSING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) IRCUT_STATE_OPENING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) IRCUT_STATE_OPENED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct ircut_op_work {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) int op_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct ircut_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct ircut_drv_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) int (*parse_dt)(struct ircut_dev *ircut, struct device_node *node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) void (*ctrl)(struct ircut_dev *ircut, int cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct ircut_dev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct v4l2_subdev sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct v4l2_ctrl_handler ctrl_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct completion complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* state mutex */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct mutex mut_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) enum IRCUT_STATE_e state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct workqueue_struct *wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) int pulse_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct gpio_desc *open_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct gpio_desc *close_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct gpio_desc *led_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) u32 module_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) const char *module_facing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) const struct ircut_drv_data *drv_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define IRCUT_STATE_EQ(expected) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) ((ircut->state == (expected)) ? true : false)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static int ap1511a_parse_dt(struct ircut_dev *ircut, struct device_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) ircut->open_gpio = devm_gpiod_get(ircut->dev, "ircut-open", GPIOD_OUT_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (IS_ERR(ircut->open_gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) dev_err(ircut->dev, "Failed to get ircut-open-gpios\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) return PTR_ERR(ircut->open_gpio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) ircut->led_gpio = devm_gpiod_get_optional(ircut->dev, "led", GPIOD_OUT_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (IS_ERR(ircut->led_gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) dev_err(ircut->dev, "Failed to get led-gpios\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static void ap1511a_ctrl(struct ircut_dev *ircut, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (cmd > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) gpiod_set_value_cansleep(ircut->open_gpio, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (!IS_ERR(ircut->led_gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) gpiod_set_value_cansleep(ircut->led_gpio, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) gpiod_set_value_cansleep(ircut->open_gpio, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (!IS_ERR(ircut->led_gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) gpiod_set_value_cansleep(ircut->led_gpio, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static int ba6208_parse_dt(struct ircut_dev *ircut, struct device_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) dev_dbg(ircut->dev, "ircut_gpio_parse_dt");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) ret = of_property_read_u32(node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) "rockchip,pulse-width",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) &ircut->pulse_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ircut->pulse_width = 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) dev_err(ircut->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) "failed get pulse-width,use dafult value 100\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (ircut->pulse_width > 2000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) ircut->pulse_width = 300;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) dev_info(ircut->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) "pulse width to long,use default dafult 300");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) dev_dbg(ircut->dev, "pulse-width value from dts %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) ircut->pulse_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /* get ircut open gpio */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) ircut->open_gpio = devm_gpiod_get(ircut->dev, "ircut-open", GPIOD_OUT_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (IS_ERR(ircut->open_gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) dev_err(ircut->dev, "Failed to get ircut-open-gpios\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /* get ircut close gpio */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) ircut->close_gpio = devm_gpiod_get(ircut->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) "ircut-close", GPIOD_OUT_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (IS_ERR(ircut->close_gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) dev_err(ircut->dev, "Failed to get ircut-close-gpios\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /* get led gpio */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) ircut->led_gpio = devm_gpiod_get_optional(ircut->dev, "led", GPIOD_OUT_LOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (IS_ERR(ircut->led_gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) dev_err(ircut->dev, "Failed to get led-gpios\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static void ba6208_ctrl(struct ircut_dev *ircut, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (cmd > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (!IS_ERR(ircut->open_gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) gpiod_set_value_cansleep(ircut->open_gpio, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) msleep(ircut->pulse_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (!IS_ERR(ircut->open_gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) gpiod_set_value_cansleep(ircut->open_gpio, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (!IS_ERR(ircut->led_gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) gpiod_set_value_cansleep(ircut->led_gpio, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (!IS_ERR(ircut->close_gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) gpiod_set_value_cansleep(ircut->close_gpio, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) msleep(ircut->pulse_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (!IS_ERR(ircut->close_gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) gpiod_set_value_cansleep(ircut->close_gpio, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (!IS_ERR(ircut->led_gpio))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) gpiod_set_value_cansleep(ircut->led_gpio, 1);
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static void ircut_op_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct ircut_op_work *wk =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) container_of(work, struct ircut_op_work, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct ircut_dev *ircut = wk->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) enum IRCUT_STATE_e state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (ircut->drv_data->ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) ircut->drv_data->ctrl(ircut, wk->op_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) state = (wk->op_cmd > 0) ? IRCUT_STATE_OPENED : IRCUT_STATE_CLOSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) mutex_lock(&ircut->mut_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) complete(&ircut->complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) ircut->state = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) mutex_unlock(&ircut->mut_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) kfree(wk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) wk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static int ircut_operation(struct ircut_dev *ircut, int op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct ircut_op_work *wk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) bool should_wait = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) bool do_nothing = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) enum IRCUT_STATE_e old_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) dev_dbg(ircut->dev, "%s, status %d\n", __func__, op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) mutex_lock(&ircut->mut_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) old_state = ircut->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (op > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /* check state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (IRCUT_STATE_EQ(IRCUT_STATE_OPENING) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) IRCUT_STATE_EQ(IRCUT_STATE_OPENED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /* already in opening or opened state, do nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) do_nothing = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) } else if (IRCUT_STATE_EQ(IRCUT_STATE_CLOSING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /* in closing state,should wait */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) should_wait = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /* in closed state,queue work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /* check state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (IRCUT_STATE_EQ(IRCUT_STATE_CLOSING) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) IRCUT_STATE_EQ(IRCUT_STATE_CLOSED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* already in closing or closed state, do nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) do_nothing = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) } else if (IRCUT_STATE_EQ(IRCUT_STATE_OPENING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /* in opening state,should wait */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) should_wait = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /* in opened state,queue work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) mutex_unlock(&ircut->mut_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (do_nothing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) goto op_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (should_wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) wait_for_completion(&ircut->complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) wk = kmalloc(sizeof(*wk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (!wk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) dev_err(ircut->dev, "failed to alloc ircut work struct\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) goto err_ircut_operation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) wk->op_cmd = op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) wk->dev = ircut;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) mutex_lock(&ircut->mut_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (op > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) ircut->state = IRCUT_STATE_OPENING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) ircut->state = IRCUT_STATE_CLOSING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) reinit_completion(&ircut->complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) mutex_unlock(&ircut->mut_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) /* queue work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) INIT_WORK(&wk->work, ircut_op_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (!queue_work(ircut->wq, &wk->work)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) dev_err(ircut->dev, "queue work failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) kfree(wk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) ircut->state = old_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) goto err_ircut_operation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) op_done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) err_ircut_operation:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) #ifdef USED_SYS_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static ssize_t set_ircut_status(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct ircut_dev *ircut = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) ret = sscanf(buf, "%d", &status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) ircut_operation(ircut, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static struct device_attribute attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) __ATTR(sys_set_ircut, S_IWUSR, NULL, set_ircut_status),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static int add_sysfs_interfaces(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) for (i = 0; i < ARRAY_SIZE(attributes); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (device_create_file(dev, attributes + i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) goto undo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) undo:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) for (i--; i >= 0 ; i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) device_remove_file(dev, attributes + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) dev_err(dev, "%s: failed to create sysfs interface\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static int ircut_s_ctrl(struct v4l2_ctrl *ctrl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) struct ircut_dev *ircut = container_of(ctrl->handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) struct ircut_dev, ctrl_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (ctrl->id == V4L2_CID_BAND_STOP_FILTER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) ret = ircut_operation(ircut, ctrl->val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) ircut->val = ctrl->val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static long ircut_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static const struct v4l2_subdev_core_ops ircut_core_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) .ioctl = ircut_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static const struct v4l2_subdev_ops ircut_subdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) .core = &ircut_core_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static const struct v4l2_ctrl_ops ircut_ctrl_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) .s_ctrl = ircut_s_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) static const struct ircut_drv_data ap1511a_drv_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) .parse_dt = ap1511a_parse_dt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) .ctrl = ap1511a_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) static const struct ircut_drv_data ba6208_drv_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) .parse_dt = ba6208_parse_dt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) .ctrl = ba6208_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) #if defined(CONFIG_OF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static const struct of_device_id ircut_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) { .compatible = "rockchip,ircut",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) .data = &ba6208_drv_data },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) { .compatible = "ap1511a,ircut",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) .data = &ap1511a_drv_data },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) MODULE_DEVICE_TABLE(of, ircut_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static int ircut_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) struct ircut_dev *ircut = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) struct device_node *node = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) struct v4l2_ctrl_handler *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) const struct of_device_id *match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) struct v4l2_subdev *sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) char facing[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) dev_info(&pdev->dev, "driver version: %02x.%02x.%02x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) DRIVER_VERSION >> 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) (DRIVER_VERSION & 0xff00) >> 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) DRIVER_VERSION & 0x00ff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) ircut = devm_kzalloc(&pdev->dev, sizeof(*ircut), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) if (!ircut) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) dev_err(&pdev->dev, "alloc ircut failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) match = of_match_node(ircut_of_match, pdev->dev.of_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if (!match)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) ircut->drv_data = match->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) ret = of_property_read_u32(node, RKMODULE_CAMERA_MODULE_INDEX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) &ircut->module_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) ret |= of_property_read_string(node, RKMODULE_CAMERA_MODULE_FACING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) &ircut->module_facing);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) "could not get module information!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) ircut->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) mutex_init(&ircut->mut_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) init_completion(&ircut->complete);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) ircut->wq = alloc_workqueue("ircut wq",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) WQ_UNBOUND | WQ_MEM_RECLAIM, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) v4l2_subdev_init(&ircut->sd, &ircut_subdev_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) ircut->sd.owner = pdev->dev.driver->owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) ircut->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) ircut->sd.dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) v4l2_set_subdevdata(&ircut->sd, pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) platform_set_drvdata(pdev, &ircut->sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) handler = &ircut->ctrl_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) ret = v4l2_ctrl_handler_init(handler, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) v4l2_ctrl_new_std(handler, &ircut_ctrl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) V4L2_CID_BAND_STOP_FILTER, 0, 4, 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (handler->error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) ret = handler->error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) dev_err(&pdev->dev, "Failed to init controls(%d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) ircut->sd.ctrl_handler = handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) ret = media_entity_pads_init(&ircut->sd.entity, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (ircut->drv_data->parse_dt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) ret = ircut->drv_data->parse_dt(ircut, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) sd = &ircut->sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) sd->entity.function = MEDIA_ENT_F_LENS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) sd->entity.flags = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) memset(facing, 0, sizeof(facing));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (strcmp(ircut->module_facing, "back") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) facing[0] = 'b';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) facing[0] = 'f';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) snprintf(sd->name, sizeof(sd->name), "m%02d_%s_%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) ircut->module_index, facing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) RK_IRCUT_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) ret = v4l2_async_register_subdev(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) dev_err(&pdev->dev, "v4l2 async register subdev failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) /* set default state to open */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) ircut_operation(ircut, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) ircut->val = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) #ifdef USED_SYS_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) add_sysfs_interfaces(ircut->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) dev_info(&pdev->dev, "probe successful!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) err_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) v4l2_ctrl_handler_free(handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) v4l2_device_unregister_subdev(&ircut->sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) media_entity_cleanup(&ircut->sd.entity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static int ircut_drv_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) struct v4l2_subdev *sd = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) struct ircut_dev *ircut = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) if (sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) ircut = v4l2_get_subdevdata(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if (ircut && ircut->wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) drain_workqueue(ircut->wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) if (sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) v4l2_device_unregister_subdev(sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) v4l2_ctrl_handler_free(&ircut->ctrl_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) media_entity_cleanup(&ircut->sd.entity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static struct platform_driver ircut_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) .name = RK_IRCUT_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) .of_match_table = of_match_ptr(ircut_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) .probe = ircut_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) .remove = ircut_drv_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) module_platform_driver(ircut_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) MODULE_ALIAS("platform:rockchip-ircut");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) MODULE_AUTHOR("ROCKCHIP");