Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Documentation/devicetree/bindings/media/apple,t8010-isp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ properties:

strobe-gpios:
maxItems: 1
description: the flash's supply enable
description: the flash's supply enable, on the boards that have a flash
(the iPhones) only; the torch exists only with it

apple,platform-id:
$ref: /schemas/types.yaml#/definitions/uint32
Expand Down
82 changes: 63 additions & 19 deletions drivers/media/platform/apple/isp/t8010_isp.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
* reference clocks and three rails, and it needs three writes before its
* CPU starts. Its buffer pools follow the A8's numbering, per channel, and
* it streams with the A8's setup. Its cameras (rear channel 0, front
* channel 1) are V4L2 devices too, NV12 at the firmware's rate and without
* controls or set-files so far; debugfs is s8000-isp/.
* channel 1) are V4L2 devices too, NV12 at the firmware's rate, with the
* rear's torch as the only controls; debugfs is s8000-isp/.
*/

#include <linux/bitfield.h>
Expand Down Expand Up @@ -212,10 +212,14 @@ struct isp_soc {
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
* What is known on the A10 only: 3A and frame-rate controls,
* set-files, the metadata's layout, YUYV output
*/
bool controls;
/* the torch's top level (the rear's flash controls, the torch LED); 0: none */
u32 torch_max;
/* the firmware's level for each step 1..torch_max; NULL: the step itself */
const u32 *torch_levels;
/*
* The A8's stream setup (A9): buffer recycling and the crop, output
* range 1, SIF format {3, 1}, the buffers queued before CH_START
Expand Down Expand Up @@ -3027,8 +3031,28 @@ static const struct v4l2_file_operations isp_fops = {
* LM3566 drivers over its own I2C, so it runs while the torch is on, streaming
* or not. @level 1-255 of the firmware's 50 mA per driver (255: 98 mA in all,
* by CH_LED_TORCH_CURRENTS_GET), 0 off. From the rear camera's flash controls
* and the "white:flash" LED.
* and the "white:flash" LED. The A9's firmware takes the same commands, the
* level at +0xc too, but in sixths of the module's calibrated torch current:
* levels 1-5 scale it, 6 and above give all of it. Its flash driver's enable
* is the strobe GPIO.
*/

/*
* The A9's torch steps: the drivers' current only changes at levels 1, 3, 5
* and 6 (22, 46, 68 and 94 mA in all, by CH_LED_TORCH_CURRENTS_GET on an N66);
* 2 and 4 give the same current as the level below them.
*/
static const u32 isp_s8000_torch_levels[] = { 1, 3, 5, 6 };

/*
* Only a board with a flash has the torch: its DT wires the flash's enable
* (strobe-gpios). The iPads with these ISPs have no flash and no torch.
*/
static bool isp_has_torch(struct t8010_isp *isp)
{
return isp->soc->torch_max && isp->strobe;
}

static int isp_set_torch(struct t8010_isp *isp, u32 level)
{
u32 was;
Expand All @@ -3044,10 +3068,13 @@ static int isp_set_torch(struct t8010_isp *isp, u32 level)
goto out;
}
mutex_lock(&isp->lock);
if (level)
ret = isp_ch_cmd(isp, 0, CMD_CH_TORCH_ON, 0x10, &level, 1);
else
if (level) {
u32 fw = isp->soc->torch_levels ? isp->soc->torch_levels[level - 1] : level;

ret = isp_ch_cmd(isp, 0, CMD_CH_TORCH_ON, 0x10, &fw, 1);
} else {
isp_ch_cmd(isp, 0, CMD_CH_TORCH_OFF, 0xc, NULL, 0);
}
mutex_unlock(&isp->lock);
if (ret) {
if (!was)
Expand Down Expand Up @@ -3234,6 +3261,19 @@ static const struct v4l2_ctrl_config isp_hfr_ctrl = {
.min = 0, .max = 1, .step = 1, .def = 0,
};

/* the rear camera's torch: TORCH turns it on, at the intensity (1 to the SoC's top) */
static void isp_torch_ctrls(struct isp_video *v)
{
u32 max = v->isp->soc->torch_max;

v->led_mode = v4l2_ctrl_new_std_menu(&v->ctrls, &isp_ctrl_ops, V4L2_CID_FLASH_LED_MODE,
V4L2_FLASH_LED_MODE_TORCH,
BIT(V4L2_FLASH_LED_MODE_FLASH),
V4L2_FLASH_LED_MODE_NONE);
v->torch = v4l2_ctrl_new_std(&v->ctrls, &isp_ctrl_ops, V4L2_CID_FLASH_TORCH_INTENSITY,
1, max, 1, DIV_ROUND_UP(max, 2));
}

/* 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)
{
Expand Down Expand Up @@ -3277,13 +3317,8 @@ static int isp_video_ctrls(struct isp_video *v)
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,
BIT(V4L2_FLASH_LED_MODE_FLASH),
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);
if (isp_has_torch(v->isp))
isp_torch_ctrls(v);
v4l2_ctrl_new_custom(&v->ctrls, &isp_hfr_ctrl, NULL);
}
v4l2_ctrl_new_custom(&v->ctrls, &isp_uhd_ctrl, NULL);
Expand Down Expand Up @@ -3349,7 +3384,13 @@ static int isp_video_register(struct t8010_isp *isp, unsigned int i,
V4L2_CAMERA_ORIENTATION_EXTERNAL, 0,
cam->front ? V4L2_CAMERA_ORIENTATION_FRONT :
V4L2_CAMERA_ORIENTATION_BACK);
ret = isp->soc->controls ? isp_video_ctrls(v) : v->ctrls.error;
if (isp->soc->controls) {
ret = isp_video_ctrls(v);
} else {
if (cam->torch && isp_has_torch(isp)) /* the A9: the torch only */
isp_torch_ctrls(v);
ret = v->ctrls.error;
}
if (ret)
return ret;

Expand Down Expand Up @@ -3973,10 +4014,10 @@ static int isp_probe(struct platform_device *pdev)
}
/* desktop torch toggles look for a "*:flash" LED */
isp->torch_led.name = "white:flash";
isp->torch_led.max_brightness = 255;
isp->torch_led.max_brightness = isp->soc->torch_max;
isp->torch_led.brightness_set_blocking = isp_torch_led_set;
isp->torch_led.flags = LED_CORE_SUSPENDRESUME;
ret = isp->soc->controls ? led_classdev_register(dev, &isp->torch_led) : 0;
ret = isp_has_torch(isp) ? led_classdev_register(dev, &isp->torch_led) : 0;
if (ret)
goto err_cameras;
dev_info(dev, "%u power domains, platform %#x; debugfs %s/\n",
Expand All @@ -3999,7 +4040,7 @@ static void isp_remove(struct platform_device *pdev)
struct t8010_isp *isp = platform_get_drvdata(pdev);
unsigned int i;

if (isp->soc->controls) {
if (isp_has_torch(isp)) {
led_classdev_unregister(&isp->torch_led); /* turns the torch off */
isp_set_torch(isp, 0);
}
Expand Down Expand Up @@ -4073,6 +4114,7 @@ static const struct isp_soc isp_t8010 = {
.cams = isp_t8010_cams,
.n_cams = ARRAY_SIZE(isp_t8010_cams),
.controls = true,
.torch_max = 255,
};

/* the A8's layout: 0x24-0x40 and 0x48-0x64, busy at 0x44 and 0x68 */
Expand Down Expand Up @@ -4117,6 +4159,8 @@ static const struct isp_soc isp_s8000 = {
.cams = isp_s8000_cams,
.n_cams = ARRAY_SIZE(isp_s8000_cams),
.a8_stream = true,
.torch_max = ARRAY_SIZE(isp_s8000_torch_levels),
.torch_levels = isp_s8000_torch_levels,
/* the 6s: pools 1 and 2 on channel 0, 16 and 17 on channel 1 */
.chan_pools = 15,
.meta_pool = 1,
Expand Down
Loading