diff --git a/Documentation/devicetree/bindings/media/apple,t8010-isp.yaml b/Documentation/devicetree/bindings/media/apple,t8010-isp.yaml index aef6b751a6da11..4a49731333b35e 100644 --- a/Documentation/devicetree/bindings/media/apple,t8010-isp.yaml +++ b/Documentation/devicetree/bindings/media/apple,t8010-isp.yaml @@ -70,6 +70,8 @@ properties: maxItems: 1 tele-shutdown-gpios: maxItems: 1 + description: the telephoto camera's shutdown line, on the boards that + have a telephoto camera (the iPhone 7 Plus) only front-shutdown-gpios: maxItems: 1 @@ -80,7 +82,8 @@ properties: apple,platform-id: $ref: /schemas/types.yaml#/definitions/uint32 description: the board's camera platform, which selects the firmware's - sensor setup (0x88 on the iPhone 6s, 0x90 on the iPhone 7) + sensor setup (0x88 on the iPhone 6s, 0x90 on the iPhone 7, 0x91 on + the iPhone 7 Plus) firmware-name: maxItems: 1 diff --git a/arch/arm64/boot/dts/apple/t8010-7.dtsi b/arch/arm64/boot/dts/apple/t8010-7.dtsi index d8784ac061f228..59deddf73f3b14 100644 --- a/arch/arm64/boot/dts/apple/t8010-7.dtsi +++ b/arch/arm64/boot/dts/apple/t8010-7.dtsi @@ -50,6 +50,23 @@ status = "okay"; }; +/* + * The cameras: rear 12 MP and front 7 MP on every iPhone 7 and 7 Plus, + * wired the same (ADT isp). The 7 Plus adds its telephoto camera's shutdown + * line; each board sets its camera platform (the ADT's sensor-type). + */ +&isp { + cam-avdd-supply = <&cam_avdd>; + cam-avdd2-supply = <&cam_avdd2>; + cam-avdd3-supply = <&cam_avdd3>; + cam0-supply = <&cam0>; + rear-shutdown-gpios = <&pinctrl_ap 65 GPIO_ACTIVE_HIGH>; + front-shutdown-gpios = <&pinctrl_ap 43 GPIO_ACTIVE_HIGH>; + strobe-gpios = <&pinctrl_ap 176 GPIO_ACTIVE_HIGH>; + firmware-name = "apple/isp-t8010.bin"; + status = "okay"; +}; + &framebuffer0 { power-domains = <&ps_disp0_fe &ps_disp0_be &ps_mipi_dsi>; }; diff --git a/arch/arm64/boot/dts/apple/t8010-d10.dts b/arch/arm64/boot/dts/apple/t8010-d10.dts index 9c811bf64b5da6..26481e278e247c 100644 --- a/arch/arm64/boot/dts/apple/t8010-d10.dts +++ b/arch/arm64/boot/dts/apple/t8010-d10.dts @@ -76,14 +76,5 @@ /* The cameras: rear 12 MP, front 7 MP */ &isp { - cam-avdd-supply = <&cam_avdd>; - cam-avdd2-supply = <&cam_avdd2>; - cam-avdd3-supply = <&cam_avdd3>; - cam0-supply = <&cam0>; - rear-shutdown-gpios = <&pinctrl_ap 65 GPIO_ACTIVE_HIGH>; - front-shutdown-gpios = <&pinctrl_ap 43 GPIO_ACTIVE_HIGH>; - strobe-gpios = <&pinctrl_ap 176 GPIO_ACTIVE_HIGH>; apple,platform-id = <0x90>; - firmware-name = "apple/isp-t8010.bin"; - status = "okay"; }; diff --git a/arch/arm64/boot/dts/apple/t8010-d101.dts b/arch/arm64/boot/dts/apple/t8010-d101.dts index a6fee7d0175dcc..531c515d348b70 100644 --- a/arch/arm64/boot/dts/apple/t8010-d101.dts +++ b/arch/arm64/boot/dts/apple/t8010-d101.dts @@ -76,14 +76,5 @@ /* The cameras: rear 12 MP, front 7 MP */ &isp { - cam-avdd-supply = <&cam_avdd>; - cam-avdd2-supply = <&cam_avdd2>; - cam-avdd3-supply = <&cam_avdd3>; - cam0-supply = <&cam0>; - rear-shutdown-gpios = <&pinctrl_ap 65 GPIO_ACTIVE_HIGH>; - front-shutdown-gpios = <&pinctrl_ap 43 GPIO_ACTIVE_HIGH>; - strobe-gpios = <&pinctrl_ap 176 GPIO_ACTIVE_HIGH>; apple,platform-id = <0x90>; - firmware-name = "apple/isp-t8010.bin"; - status = "okay"; }; diff --git a/arch/arm64/boot/dts/apple/t8010-d11.dts b/arch/arm64/boot/dts/apple/t8010-d11.dts index e0a883c0f51e72..b9f25a1b0fd189 100644 --- a/arch/arm64/boot/dts/apple/t8010-d11.dts +++ b/arch/arm64/boot/dts/apple/t8010-d11.dts @@ -65,3 +65,9 @@ touchscreen-size-x = <1080>; touchscreen-size-y = <1920>; }; + +/* The cameras: rear 12 MP, telephoto 12 MP, front 7 MP */ +&isp { + tele-shutdown-gpios = <&pinctrl_ap 69 GPIO_ACTIVE_HIGH>; + apple,platform-id = <0x91>; +}; diff --git a/arch/arm64/boot/dts/apple/t8010-d111.dts b/arch/arm64/boot/dts/apple/t8010-d111.dts index 24a0743bcf1710..e3864abe4b2638 100644 --- a/arch/arm64/boot/dts/apple/t8010-d111.dts +++ b/arch/arm64/boot/dts/apple/t8010-d111.dts @@ -65,3 +65,9 @@ touchscreen-size-x = <1080>; touchscreen-size-y = <1920>; }; + +/* The cameras: rear 12 MP, telephoto 12 MP, front 7 MP */ +&isp { + tele-shutdown-gpios = <&pinctrl_ap 69 GPIO_ACTIVE_HIGH>; + apple,platform-id = <0x91>; +}; diff --git a/arch/arm64/boot/dts/apple/t8010.dtsi b/arch/arm64/boot/dts/apple/t8010.dtsi index c44a38cf5db6eb..0c1f9896ed40ce 100644 --- a/arch/arm64/boot/dts/apple/t8010.dtsi +++ b/arch/arm64/boot/dts/apple/t8010.dtsi @@ -899,19 +899,27 @@ , ; - /* The camera sensors' reference clocks: rear (66), front (72) */ + /* + * The camera sensors' reference clocks: rear (66), + * telephoto (70) and front (72). Every iPhone 7 and 7 + * Plus ADT lists all three as the ISP's extclk pads, + * including the boards without a telephoto. + */ isp_refclk_gpio: isp-refclk-gpio-pins { pinmux = , + , ; }; isp_refclk_f1: isp-refclk-f1-pins { pinmux = , + , ; }; isp_refclk_f2: isp-refclk-f2-pins { pinmux = , + , ; }; diff --git a/drivers/media/platform/apple/isp/t8010_isp.c b/drivers/media/platform/apple/isp/t8010_isp.c index 0b8f4244302f2c..ac3612b8f00cc6 100644 --- a/drivers/media/platform/apple/isp/t8010_isp.c +++ b/drivers/media/platform/apple/isp/t8010_isp.c @@ -170,6 +170,25 @@ enum { RING_H2T = 0, RING_T2H = 1, RING_REPORT = 2 }; struct isp_mode; +/* + * A camera: its firmware channel, its shutdown line (the index into the + * shutdown GPIOs: rear, tele, front) and its sensor modes. An optional + * camera exists on the boards that wire its shutdown line only: the + * telephoto, which the iPhone 7 Plus has and the iPhone 7 has not. + */ +struct isp_cam { + const char *name; /* in the node, media and subdevice names */ + const char *label; /* the video device's name */ + unsigned int ch; + unsigned int shutdown; + bool optional; + bool front; /* faces the user */ + bool af; /* autofocus */ + bool torch; /* the flash and the high frame rates */ + const struct isp_mode *modes; + unsigned int n_modes; +}; + /* what differs between the ISPs this driver runs */ struct isp_soc { const char *name; /* the debugfs directory */ @@ -190,9 +209,8 @@ struct isp_soc { unsigned int n_pre_boot; u32 stop_drain; /* read 8 times after the CPU stops */ const char *model; /* in the media devices' model */ - unsigned int front_ch; /* the front camera's firmware channel (rear: 0) */ - const struct isp_mode *rear_modes, *front_modes; - unsigned int n_rear_modes, n_front_modes; + const struct isp_cam *cams; /* in video node order */ + unsigned int n_cams; /* * What is known on the A10 only: 3A, frame-rate and torch controls * (with the torch LED), set-files, the metadata's layout, YUYV output @@ -260,6 +278,7 @@ struct isp_video { struct vb2_queue queue; struct mutex lock; /* the video device's ioctls and queue */ struct v4l2_ctrl_handler ctrls; + const struct isp_cam *cam; unsigned int ch; /* firmware channel */ const struct isp_mode *modes, *mode; unsigned int n_modes; @@ -377,7 +396,8 @@ struct t8010_isp { struct dentry *dbg; int irq; - struct isp_video video[2]; /* rear (channel 0), front (channel 2, A9: 1) */ + struct isp_video video[3]; /* the cameras the board has, in soc->cams order */ + unsigned int n_video; struct isp_video *streaming; unsigned int users; /* queues holding the firmware */ unsigned int vbufs; /* vb2 buffers alive (maybe still mmapped) */ @@ -3215,8 +3235,10 @@ static const struct v4l2_ctrl_config isp_hfr_ctrl = { }; /* the A10's controls: sensor rotation, 3A, the rear's focus and torch, sizes and rates */ -static int isp_video_ctrls(struct isp_video *v, unsigned int i) +static int isp_video_ctrls(struct isp_video *v) { + const struct isp_cam *cam = v->cam; + /* both sensors read out landscape: upright after 270 degrees (front unmirrored) */ v4l2_ctrl_new_std(&v->ctrls, NULL, V4L2_CID_CAMERA_SENSOR_ROTATION, 270, 270, 1, 270); v->exp_auto = v4l2_ctrl_new_std_menu(&v->ctrls, &isp_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, @@ -3241,13 +3263,20 @@ static int isp_video_ctrls(struct isp_video *v, unsigned int i) V4L2_CID_WHITE_BALANCE_TEMPERATURE, 2500, 6500, 50, 5000); v->lock3a = v4l2_ctrl_new_std(&v->ctrls, &isp_ctrl_ops, V4L2_CID_3A_LOCK, 0, V4L2_LOCK_EXPOSURE | V4L2_LOCK_WHITE_BALANCE | - (i ? 0 : V4L2_LOCK_FOCUS), 0, 0); - if (!i) { /* rear: autofocus, the torch; the front camera is fixed-focus */ + (cam->af ? V4L2_LOCK_FOCUS : 0), 0, 0); + if (cam->af) { /* rear and telephoto; the front camera is fixed-focus */ v->focus_auto = v4l2_ctrl_new_std(&v->ctrls, &isp_ctrl_ops, V4L2_CID_FOCUS_AUTO, 0, 1, 1, 1); v->focus_abs = v4l2_ctrl_new_std(&v->ctrls, &isp_ctrl_ops, V4L2_CID_FOCUS_ABSOLUTE, 0, 255, 1, 128); v4l2_ctrl_new_std(&v->ctrls, &isp_ctrl_ops, V4L2_CID_AUTO_FOCUS_START, 0, 0, 0, 0); + v->af_status = v4l2_ctrl_new_std(&v->ctrls, &isp_ctrl_ops, + V4L2_CID_AUTO_FOCUS_STATUS, 0, + V4L2_AUTO_FOCUS_STATUS_BUSY | + V4L2_AUTO_FOCUS_STATUS_REACHED | + V4L2_AUTO_FOCUS_STATUS_FAILED, 0, 0); + } + if (cam->torch) { /* the rear camera: the flash, high frame rates */ v->led_mode = v4l2_ctrl_new_std_menu(&v->ctrls, &isp_ctrl_ops, V4L2_CID_FLASH_LED_MODE, V4L2_FLASH_LED_MODE_TORCH, @@ -3255,11 +3284,6 @@ static int isp_video_ctrls(struct isp_video *v, unsigned int i) V4L2_FLASH_LED_MODE_NONE); v->torch = v4l2_ctrl_new_std(&v->ctrls, &isp_ctrl_ops, V4L2_CID_FLASH_TORCH_INTENSITY, 1, 255, 1, 128); - v->af_status = v4l2_ctrl_new_std(&v->ctrls, &isp_ctrl_ops, - V4L2_CID_AUTO_FOCUS_STATUS, 0, - V4L2_AUTO_FOCUS_STATUS_BUSY | - V4L2_AUTO_FOCUS_STATUS_REACHED | - V4L2_AUTO_FOCUS_STATUS_FAILED, 0, 0); v4l2_ctrl_new_custom(&v->ctrls, &isp_hfr_ctrl, NULL); } v4l2_ctrl_new_custom(&v->ctrls, &isp_uhd_ctrl, NULL); @@ -3286,7 +3310,8 @@ static int isp_video_ctrls(struct isp_video *v, unsigned int i) return 0; } -static int isp_video_register(struct t8010_isp *isp, unsigned int i) +static int isp_video_register(struct t8010_isp *isp, unsigned int i, + const struct isp_cam *cam) { struct isp_video *v = &isp->video[i]; struct video_device *vdev = &v->vdev; @@ -3294,21 +3319,22 @@ static int isp_video_register(struct t8010_isp *isp, unsigned int i) int ret; v->isp = isp; + v->cam = cam; v->mdev.dev = isp->dev; snprintf(v->mdev.model, sizeof(v->mdev.model), "Apple %s ISP, %s camera", - isp->soc->model, i ? "front" : "rear"); + isp->soc->model, cam->name); snprintf(v->mdev.bus_info, sizeof(v->mdev.bus_info), "platform:%s-%s", - dev_name(isp->dev), i ? "front" : "rear"); + dev_name(isp->dev), cam->name); media_device_init(&v->mdev); v->v4l2.mdev = &v->mdev; snprintf(v->v4l2.name, sizeof(v->v4l2.name), "%s-%s", dev_name(isp->dev), - i ? "front" : "rear"); + cam->name); ret = v4l2_device_register(isp->dev, &v->v4l2); if (ret) return ret; - v->ch = i ? isp->soc->front_ch : 0; - v->modes = i ? isp->soc->front_modes : isp->soc->rear_modes; - v->n_modes = i ? isp->soc->n_front_modes : isp->soc->n_rear_modes; + v->ch = cam->ch; + v->modes = cam->modes; + v->n_modes = cam->n_modes; v->mode = &v->modes[0]; v->fps = isp_pick_rate(v, v->mode, 30); v->want_fps = 30; @@ -3321,8 +3347,9 @@ static int isp_video_register(struct t8010_isp *isp, unsigned int i) v4l2_ctrl_handler_init(&v->ctrls, 16); v4l2_ctrl_new_std_menu(&v->ctrls, NULL, V4L2_CID_CAMERA_ORIENTATION, V4L2_CAMERA_ORIENTATION_EXTERNAL, 0, - i ? V4L2_CAMERA_ORIENTATION_FRONT : V4L2_CAMERA_ORIENTATION_BACK); - ret = isp->soc->controls ? isp_video_ctrls(v, i) : v->ctrls.error; + cam->front ? V4L2_CAMERA_ORIENTATION_FRONT : + V4L2_CAMERA_ORIENTATION_BACK); + ret = isp->soc->controls ? isp_video_ctrls(v) : v->ctrls.error; if (ret) return ret; @@ -3340,7 +3367,7 @@ static int isp_video_register(struct t8010_isp *isp, unsigned int i) if (ret) return ret; - strscpy(vdev->name, i ? "Front camera" : "Rear camera", sizeof(vdev->name)); + strscpy(vdev->name, cam->label, sizeof(vdev->name)); vdev->fops = &isp_fops; vdev->ioctl_ops = &isp_ioctl_ops; vdev->release = video_device_release_empty; @@ -3360,7 +3387,8 @@ static int isp_video_register(struct t8010_isp *isp, unsigned int i) /* * The media graph, for media-controller programs (libmegapixels): each camera - * is a sensor subdevice ("isp-rear", "isp-front") linked to its video node. + * is a sensor subdevice ("isp-rear", "isp-tele", "isp-front") linked to its + * video node. * The firmware drives the real sensors; the subdevice offers the video node's * sizes as YUYV and its rates (AE's cap), and the camera's controls. */ @@ -3504,7 +3532,7 @@ static int isp_sensor_register(struct t8010_isp *isp, unsigned int i) sd->dev = isp->dev; sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; sd->ctrl_handler = &v->ctrls; - strscpy(sd->name, i ? "isp-front" : "isp-rear", sizeof(sd->name)); + snprintf(sd->name, sizeof(sd->name), "isp-%s", v->cam->name); sd->entity.function = MEDIA_ENT_F_CAM_SENSOR; v->sensor_pad.flags = MEDIA_PAD_FL_SOURCE; ret = media_entity_pads_init(&sd->entity, 1, &v->sensor_pad); @@ -3930,10 +3958,16 @@ static int isp_probe(struct platform_device *pdev) if (isp->soc->chan_pools) isp_pool_defaults(isp); - for (i = 0; i < ARRAY_SIZE(isp->video); i++) { - ret = isp_video_register(isp, i); + for (i = 0; i < isp->soc->n_cams; i++) { + const struct isp_cam *cam = &isp->soc->cams[i]; + + if (cam->optional && !isp->shutdown[cam->shutdown]) + continue; /* not on this board */ + if (WARN_ON(isp->n_video == ARRAY_SIZE(isp->video))) + break; + ret = isp_video_register(isp, isp->n_video++, cam); if (!ret) - ret = isp_sensor_register(isp, i); + ret = isp_sensor_register(isp, isp->n_video - 1); if (ret) goto err_cameras; } @@ -3945,14 +3979,15 @@ static int isp_probe(struct platform_device *pdev) ret = isp->soc->controls ? led_classdev_register(dev, &isp->torch_led) : 0; if (ret) goto err_cameras; - dev_info(dev, "%u power domains, platform %#x; %s and %s; debugfs %s/\n", - isp->pds->num_pds, isp->platform_id, - video_device_node_name(&isp->video[0].vdev), - video_device_node_name(&isp->video[1].vdev), isp->soc->name); + dev_info(dev, "%u power domains, platform %#x; debugfs %s/\n", + isp->pds->num_pds, isp->platform_id, isp->soc->name); + for (i = 0; i < isp->n_video; i++) + dev_info(dev, "%s camera: %s\n", isp->video[i].cam->name, + video_device_node_name(&isp->video[i].vdev)); return 0; err_cameras: - for (i = 0; i < ARRAY_SIZE(isp->video); i++) + for (i = 0; i < isp->n_video; i++) isp_camera_unregister(&isp->video[i]); err_debugfs: debugfs_remove_recursive(isp->dbg); @@ -3968,7 +4003,7 @@ static void isp_remove(struct platform_device *pdev) led_classdev_unregister(&isp->torch_led); /* turns the torch off */ isp_set_torch(isp, 0); } - for (i = 0; i < ARRAY_SIZE(isp->video); i++) + for (i = 0; i < isp->n_video; i++) isp_camera_unregister(&isp->video[i]); debugfs_remove_recursive(isp->dbg); cancel_delayed_work_sync(&isp->off_work); @@ -4007,6 +4042,19 @@ static DEFINE_SIMPLE_DEV_PM_OPS(isp_pm_ops, isp_suspend, NULL); static const u16 isp_t8010_pmu_gates[] = { 0x14, 0x18, 0x20, 0x24 }; static const char * const isp_t8010_rails[] = { "cam-avdd", "cam-avdd2", "cam-avdd3", "cam0" }; +/* the telephoto shares the rear camera's modes */ +static const struct isp_cam isp_t8010_cams[] = { + { .name = "rear", .label = "Rear camera", .ch = 0, .shutdown = 0, + .af = true, .torch = true, + .modes = isp_rear_modes, .n_modes = ARRAY_SIZE(isp_rear_modes) }, + { .name = "tele", .label = "Telephoto camera", .ch = 1, .shutdown = 1, + .optional = true, .af = true, + .modes = isp_rear_modes, .n_modes = ARRAY_SIZE(isp_rear_modes) }, + { .name = "front", .label = "Front camera", .ch = 2, .shutdown = 2, + .front = true, + .modes = isp_front_modes, .n_modes = ARRAY_SIZE(isp_front_modes) }, +}; + static const struct isp_soc isp_t8010 = { .name = "t8010-isp", .fw_name = "apple/isp-t8010.bin", @@ -4022,11 +4070,8 @@ static const struct isp_soc isp_t8010 = { .rails = isp_t8010_rails, .n_rails = ARRAY_SIZE(isp_t8010_rails), .model = "T8010", - .front_ch = 2, - .rear_modes = isp_rear_modes, - .n_rear_modes = ARRAY_SIZE(isp_rear_modes), - .front_modes = isp_front_modes, - .n_front_modes = ARRAY_SIZE(isp_front_modes), + .cams = isp_t8010_cams, + .n_cams = ARRAY_SIZE(isp_t8010_cams), .controls = true, }; @@ -4041,6 +4086,16 @@ static const struct isp_reg_val isp_s8000_pre_boot[] = { { 0x20, 0x80550034 }, { 0x10080c, 0x60000001 }, { 0x100040, 0x000f0401 }, }; +/* the A9: no telephoto, the front camera on channel 1 */ +static const struct isp_cam isp_s8000_cams[] = { + { .name = "rear", .label = "Rear camera", .ch = 0, .shutdown = 0, + .af = true, .torch = true, + .modes = isp_s8000_rear_modes, .n_modes = ARRAY_SIZE(isp_s8000_rear_modes) }, + { .name = "front", .label = "Front camera", .ch = 1, .shutdown = 2, + .front = true, + .modes = isp_s8000_front_modes, .n_modes = ARRAY_SIZE(isp_s8000_front_modes) }, +}; + static const struct isp_soc isp_s8000 = { .name = "s8000-isp", .fw_name = "apple/isp-s8000.bin", @@ -4059,11 +4114,8 @@ static const struct isp_soc isp_s8000 = { .n_pre_boot = ARRAY_SIZE(isp_s8000_pre_boot), .stop_drain = 0x10081c, .model = "S8000", - .front_ch = 1, - .rear_modes = isp_s8000_rear_modes, - .n_rear_modes = ARRAY_SIZE(isp_s8000_rear_modes), - .front_modes = isp_s8000_front_modes, - .n_front_modes = ARRAY_SIZE(isp_s8000_front_modes), + .cams = isp_s8000_cams, + .n_cams = ARRAY_SIZE(isp_s8000_cams), .a8_stream = true, /* the 6s: pools 1 and 2 on channel 0, 16 and 17 on channel 1 */ .chan_pools = 15,