From patchwork Mon Apr 15 14:13:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 10900899 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D73414DB for ; Mon, 15 Apr 2019 14:14:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7E96284AF for ; Mon, 15 Apr 2019 14:14:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA87E28965; Mon, 15 Apr 2019 14:14:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EA902874E for ; Mon, 15 Apr 2019 14:14:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727531AbfDOOOF (ORCPT ); Mon, 15 Apr 2019 10:14:05 -0400 Received: from esa1.microchip.iphmx.com ([68.232.147.91]:13722 "EHLO esa1.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727506AbfDOOOC (ORCPT ); Mon, 15 Apr 2019 10:14:02 -0400 X-IronPort-AV: E=Sophos;i="5.60,353,1549954800"; d="scan'208";a="31528028" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 15 Apr 2019 07:14:01 -0700 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.76.38) with Microsoft SMTP Server (TLS) id 14.3.352.0; Mon, 15 Apr 2019 07:14:01 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microchiptechnology.onmicrosoft.com; s=selector1-microchiptechnology-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Wh13mGcJ79mU8dzlhCqI3aGOCF+L4mQikThS20j02ZM=; b=18aDXYHDeV7jgX3ABHRvy0YzRoipcfCjrtzVf1UonSzCYFVpxMzupgtRAoEDePLlXG9X8QZTC+xQ9x8ZOtAtQlF02Q3zrP0LENKlaAHbUSkwWSoRu7H1zH5aKXFTyOENcOTRtROpXR8/FWXk7W2miYqc69NtsQdRS7WSF0yjGn4= Received: from DM5PR11MB1242.namprd11.prod.outlook.com (10.168.108.8) by DM5PR11MB1770.namprd11.prod.outlook.com (10.175.88.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1792.15; Mon, 15 Apr 2019 14:13:54 +0000 Received: from DM5PR11MB1242.namprd11.prod.outlook.com ([fe80::e0e3:1d51:9e3e:6dc]) by DM5PR11MB1242.namprd11.prod.outlook.com ([fe80::e0e3:1d51:9e3e:6dc%3]) with mapi id 15.20.1792.018; Mon, 15 Apr 2019 14:13:54 +0000 From: To: , , , CC: , , , Subject: [PATCH v2 3/4] media: atmel: atmel-isc: add support for DO_WHITE_BALANCE Thread-Topic: [PATCH v2 3/4] media: atmel: atmel-isc: add support for DO_WHITE_BALANCE Thread-Index: AQHU85V1JH7yFKuv0UWLf8l8PaB2Jg== Date: Mon, 15 Apr 2019 14:13:54 +0000 Message-ID: <1555337305-13767-4-git-send-email-eugen.hristev@microchip.com> References: <1555337305-13767-1-git-send-email-eugen.hristev@microchip.com> In-Reply-To: <1555337305-13767-1-git-send-email-eugen.hristev@microchip.com> Accept-Language: ro-RO, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VE1PR08CA0005.eurprd08.prod.outlook.com (2603:10a6:803:104::18) To DM5PR11MB1242.namprd11.prod.outlook.com (2603:10b6:3:14::8) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Eugen.Hristev@microchip.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.7.4 x-originating-ip: [94.177.32.154] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 3a8e2df0-b634-4b0b-15c0-08d6c1ac9764 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600140)(711020)(4605104)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020);SRVR:DM5PR11MB1770; x-ms-traffictypediagnostic: DM5PR11MB1770: x-microsoft-antispam-prvs: x-forefront-prvs: 000800954F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(136003)(39860400002)(346002)(376002)(366004)(199004)(189003)(50226002)(107886003)(68736007)(8676002)(256004)(14444005)(6512007)(446003)(2616005)(72206003)(2906002)(6436002)(2201001)(486006)(86362001)(8936002)(81156014)(81166006)(97736004)(11346002)(478600001)(14454004)(476003)(110136005)(52116002)(76176011)(25786009)(3846002)(102836004)(186003)(6506007)(386003)(66066001)(5660300002)(105586002)(106356001)(4326008)(54906003)(6486002)(305945005)(71190400001)(7736002)(99286004)(53936002)(6116002)(36756003)(71200400001)(316002)(26005)(2501003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR11MB1770;H:DM5PR11MB1242.namprd11.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microchip.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: Ne9ydLrnlNMCiucYMxC97mnn3DS+tRoca4hEOzfTujxUQCbM/2oDeoxM5KioJAw0Emgw5ZP+YTHED/as5KoUpVu4E8BIU9U9M23ZUXvLUKifNZDTc56U10Jdtd5kYdOlQToHaBpbOSuuBLtTYqnuW0vw6PfpyKLlgFJfAVltbADe0MZgARHxf4pzdkahPcAaV4723HuNEkbnDdRE+r1OFuysj3HBtwDrCX6T6qmvEdP6BvVD6KEok8lbHSotSGyWaWyRq6vktJOX6fbaetn7n/A2sU7WdY+Hr8HRoiY+x0845ahlYpFbjVDre6oxLNUcHtI5bLdX6t+LKZSY0NazXjwOO/kE2ssZhRM2s2v1YpNkyxPynLSKdtGsKSMezE7QZ+1RWMqSEt0r3Du3PNbURStzk/obzTZbD3B5TpvNnJA= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 3a8e2df0-b634-4b0b-15c0-08d6c1ac9764 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Apr 2019 14:13:54.1731 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR11MB1770 X-OriginatorOrg: microchip.com Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eugen Hristev This adds support for the 'button' control DO_WHITE_BALANCE This feature will enable the ISC to compute the white balance coefficients in a one time shot, at the user discretion. This can be used if a color chart/grey chart is present in front of the camera. The ISC will adjust the coefficients and have them fixed until next balance or until sensor mode is changed. This is particularly useful for white balance adjustment in different lighting scenarios, and then taking photos to similar scenery. The old auto white balance stays in place, where the ISC will adjust every 4 frames to the current scenery lighting, if the scenery is approximately grey in average, otherwise grey world algorithm fails. One time white balance adjustments needs streaming to be enabled, such that capture is enabled and the histogram has data to work with. Histogram without capture does not work in this hardware module. To start the one time white balance procedure: v4l2-ctl --set-ctrl=do_white_balance=1 This feature works only if the sensor is streaming RAW data, as the hardware supports a histogram only for RAW bayer components. If the auto white balance is enabled, do_white_balance does nothing. If the streaming is disabled, or the sensor does not output RAW data, the control is inactive. User controls now include the do_white_balance ctrl: User Controls brightness 0x00980900 (int) : min=-1024 max=1023 step=1 default=0 value=0 flags=slider contrast 0x00980901 (int) : min=-2048 max=2047 step=1 default=256 value=256 flags=slider white_balance_automatic 0x0098090c (bool) : default=1 value=0 do_white_balance 0x0098090d (button) : flags=write-only, execute-on-write gamma 0x00980910 (int) : min=0 max=2 step=1 default=2 value=2 flags=slider Signed-off-by: Eugen Hristev --- Changes in v2: - changed according to review by Hans: DO_WB works evne if AWB is enabled and does nothing; use active/inactive on do_wb ctrl to make it inactive if not streaming or not raw; do not do anything on inactive ctrls in ctrls callback. drivers/media/platform/atmel/atmel-isc.c | 66 ++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/atmel/atmel-isc.c b/drivers/media/platform/atmel/atmel-isc.c index 0ac5953..777e27f 100644 --- a/drivers/media/platform/atmel/atmel-isc.c +++ b/drivers/media/platform/atmel/atmel-isc.c @@ -167,6 +167,9 @@ struct isc_ctrls { u32 brightness; u32 contrast; u8 gamma_index; +#define ISC_WB_NONE 0 +#define ISC_WB_AUTO 1 +#define ISC_WB_ONETIME 2 u8 awb; /* one for each component : GR, R, GB, B */ @@ -210,6 +213,7 @@ struct isc_device { struct fmt_config try_config; struct isc_ctrls ctrls; + struct v4l2_ctrl *do_wb_ctrl; struct work_struct awb_work; struct mutex lock; @@ -838,7 +842,7 @@ static void isc_set_pipeline(struct isc_device *isc, u32 pipeline) bay_cfg = isc->config.sd_format->cfa_baycfg; - if (!ctrls->awb) + if (ctrls->awb == ISC_WB_NONE) isc_reset_awb_ctrls(isc); regmap_write(regmap, ISC_WB_CFG, bay_cfg); @@ -993,6 +997,10 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count) spin_unlock_irqrestore(&isc->dma_queue_lock, flags); + /* if we streaming from RAW, we can do one-shot white balance adj */ + if (ISC_IS_FORMAT_RAW(isc->config.sd_format->mbus_code)) + v4l2_ctrl_activate(isc->do_wb_ctrl, true); + return 0; err_configure: @@ -1017,6 +1025,8 @@ static void isc_stop_streaming(struct vb2_queue *vq) struct isc_buffer *buf; int ret; + v4l2_ctrl_activate(isc->do_wb_ctrl, false); + isc->stop = true; /* Wait until the end of the current frame */ @@ -1941,7 +1951,7 @@ static void isc_awb_work(struct work_struct *w) baysel = isc->config.sd_format->cfa_baycfg << ISC_HIS_CFG_BAYSEL_SHIFT; /* if no more auto white balance, reset controls. */ - if (!ctrls->awb) + if (ctrls->awb == ISC_WB_NONE) isc_reset_awb_ctrls(isc); pm_runtime_get_sync(isc->dev); @@ -1950,7 +1960,7 @@ static void isc_awb_work(struct work_struct *w) * only update if we have all the required histograms and controls * if awb has been disabled, we need to reset registers as well. */ - if (hist_id == ISC_HIS_CFG_MODE_GR || !ctrls->awb) { + if (hist_id == ISC_HIS_CFG_MODE_GR || ctrls->awb == ISC_WB_NONE) { /* * It may happen that DMA Done IRQ will trigger while we are * updating white balance registers here. @@ -1960,6 +1970,16 @@ static void isc_awb_work(struct work_struct *w) spin_lock_irqsave(&isc->awb_lock, flags); isc_update_awb_ctrls(isc); spin_unlock_irqrestore(&isc->awb_lock, flags); + + /* + * if we are doing just the one time white balance adjustment, + * we are basically done. + */ + if (ctrls->awb == ISC_WB_ONETIME) { + v4l2_info(&isc->v4l2_dev, + "Completed one time white-balance adjustment.\n"); + ctrls->awb = ISC_WB_NONE; + } } regmap_write(regmap, ISC_HIS_CFG, hist_id | baysel | ISC_HIS_CFG_RAR); isc_update_profile(isc); @@ -1976,6 +1996,9 @@ static int isc_s_ctrl(struct v4l2_ctrl *ctrl) struct isc_device, ctrls.handler); struct isc_ctrls *ctrls = &isc->ctrls; + if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE) + return 0; + switch (ctrl->id) { case V4L2_CID_BRIGHTNESS: ctrls->brightness = ctrl->val & ISC_CBC_BRIGHT_MASK; @@ -1987,10 +2010,33 @@ static int isc_s_ctrl(struct v4l2_ctrl *ctrl) ctrls->gamma_index = ctrl->val; break; case V4L2_CID_AUTO_WHITE_BALANCE: - ctrls->awb = ctrl->val; - if (ctrls->hist_stat != HIST_ENABLED) { + if (ctrl->val == 1) + ctrls->awb = ISC_WB_AUTO; + else + ctrls->awb = ISC_WB_NONE; + + /* we did not configure ISC yet */ + if (!isc->config.sd_format) + break; + + if (ctrls->hist_stat != HIST_ENABLED) isc_reset_awb_ctrls(isc); - } + + if (isc->ctrls.awb == ISC_WB_AUTO && + vb2_is_streaming(&isc->vb2_vidq) && + ISC_IS_FORMAT_RAW(isc->config.sd_format->mbus_code)) + isc_set_histogram(isc, true); + + break; + case V4L2_CID_DO_WHITE_BALANCE: + /* if AWB is enabled, do nothing */ + if (ctrls->awb == ISC_WB_AUTO) + return 0; + + ctrls->awb = ISC_WB_ONETIME; + isc_set_histogram(isc, true); + v4l2_dbg(1, debug, &isc->v4l2_dev, + "One time white-balance started.\n"); break; default: return -EINVAL; @@ -2013,7 +2059,7 @@ static int isc_ctrl_init(struct isc_device *isc) ctrls->hist_stat = HIST_INIT; isc_reset_awb_ctrls(isc); - ret = v4l2_ctrl_handler_init(hdl, 4); + ret = v4l2_ctrl_handler_init(hdl, 5); if (ret < 0) return ret; @@ -2025,6 +2071,12 @@ static int isc_ctrl_init(struct isc_device *isc) v4l2_ctrl_new_std(hdl, ops, V4L2_CID_GAMMA, 0, GAMMA_MAX, 1, 2); v4l2_ctrl_new_std(hdl, ops, V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 1); + /* do_white_balance is a button, so min,max,step,default are ignored */ + isc->do_wb_ctrl = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_DO_WHITE_BALANCE, + 0, 0, 0, 0); + + v4l2_ctrl_activate(isc->do_wb_ctrl, false); + v4l2_ctrl_handler_setup(hdl); return 0;