From patchwork Wed Mar 18 07:57:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kassey Lee X-Patchwork-Id: 6036831 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 80618BF90F for ; Wed, 18 Mar 2015 07:57:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 959AE204EB for ; Wed, 18 Mar 2015 07:57:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8C7B8204E7 for ; Wed, 18 Mar 2015 07:57:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755021AbbCRH5l (ORCPT ); Wed, 18 Mar 2015 03:57:41 -0400 Received: from mail-pd0-f175.google.com ([209.85.192.175]:35364 "EHLO mail-pd0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755014AbbCRH5k (ORCPT ); Wed, 18 Mar 2015 03:57:40 -0400 Received: by pdbop1 with SMTP id op1so35594279pdb.2 for ; Wed, 18 Mar 2015 00:57:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=DB4rqHzAQaGctUdiXvUADLoyJngGnhXFpA6nq35M9Wg=; b=FrJjdGxdqPErqtAvTXwwvwc+LuymuWZNHakmWzHuLhgvOUf2Du1eponqLpOaVPl+L8 tjdRy64sC0T9ErflNW0eDMPmJCf6WLYzC3sp4a5nWvXRx259Hm5UTQ2Arynt8ajiUq/Z ALKszh1fop85LQZ8cLSetPSwLd69vxD4hLycR4jru6kTcst4HweLADUsCpKrpMST5k8z wQv+oUdookRw4gm/HnyvWq8pYLAG4O7l4TueHEHiiYsuoBdq3knvQkEYm9cpJljoqFrT 9NkdqRsPJ9YtsRK9/D4Z0dv3JBkLw8WJf+778P6aUI9NCn+pRUJglfwoTWD9pT0h9mqM gEuQ== X-Received: by 10.70.54.130 with SMTP id j2mr137353859pdp.122.1426665460327; Wed, 18 Mar 2015 00:57:40 -0700 (PDT) Received: from ce-xian.nvidia.com ([203.18.50.4]) by mx.google.com with ESMTPSA id bt2sm26085131pad.12.2015.03.18.00.57.38 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 18 Mar 2015 00:57:39 -0700 (PDT) From: Kassey Li To: g.liakhovetski@gmx.de Cc: linux-media@vger.kernel.org, kasseyl@nvidia.com Subject: [PATCH V2 03/18] [media] V4L: soc-camera: add SPI device support Date: Wed, 18 Mar 2015 15:57:34 +0800 Message-Id: <1426665454-6903-1-git-send-email-kassey1216@gmail.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Kassey Li This adds support for spi interface sub device for soc_camera. Signed-off-by: Kassey Li --- drivers/media/platform/soc_camera/soc_camera.c | 94 ++++++++++++++++++++++++ include/media/soc_camera.h | 4 + 2 files changed, 98 insertions(+) diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c index b3db51c..b01c075 100644 --- a/drivers/media/platform/soc_camera/soc_camera.c +++ b/drivers/media/platform/soc_camera/soc_camera.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -1430,6 +1431,91 @@ static void soc_camera_i2c_free(struct soc_camera_device *icd) icd->clk = NULL; } +static int soc_camera_spi_init(struct soc_camera_device *icd, + struct soc_camera_desc *sdesc) +{ + struct soc_camera_subdev_desc *ssdd; + struct spi_device *spi; + struct soc_camera_host *ici; + struct soc_camera_host_desc *shd = &sdesc->host_desc; + struct spi_master *spi_master; + struct v4l2_subdev *subdev; + char clk_name[V4L2_SUBDEV_NAME_SIZE]; + int ret; + + /* First find out how we link the main client */ + if (icd->sasc) { + /* Async non-OF probing handled by the subdevice list */ + return -EPROBE_DEFER; + } + + ici = to_soc_camera_host(icd->parent); + spi_master = spi_busnum_to_master(shd->spi_bus_id); + if (!spi_master) { + dev_err(icd->pdev, "Cannot get SPI master #%d. No driver?\n", + shd->spi_bus_id); + return -ENODEV; + } + + ssdd = kmemdup(&sdesc->subdev_desc, sizeof(*ssdd), GFP_KERNEL); + if (!ssdd) + return -ENOMEM; + /* + * In synchronous case we request regulators ourselves in + * soc_camera_pdrv_probe(), make sure the subdevice driver doesn't try + * to allocate them again. + */ + ssdd->sd_pdata.num_regulators = 0; + ssdd->sd_pdata.regulators = NULL; + shd->board_info_spi->platform_data = ssdd; + + snprintf(clk_name, sizeof(clk_name), "%d", + shd->spi_bus_id); + + icd->clk = v4l2_clk_register(&soc_camera_clk_ops, clk_name, "mclk", icd); + if (IS_ERR(icd->clk)) { + ret = PTR_ERR(icd->clk); + goto eclkreg; + } + + subdev = v4l2_spi_new_subdev(&ici->v4l2_dev, spi_master, + shd->board_info_spi); + if (!subdev) { + ret = -ENODEV; + goto espind; + } + + spi = v4l2_get_subdevdata(subdev); + + icd->control = &spi->dev; + + return 0; +espind: + v4l2_clk_unregister(icd->clk); + icd->clk = NULL; +eclkreg: + kfree(ssdd); + return ret; +} + +static void soc_camera_spi_free(struct soc_camera_device *icd) +{ + struct spi_device *spi = + to_spi_device(to_soc_camera_control(icd)); + struct soc_camera_subdev_desc *ssdd; + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); + + icd->control = NULL; + if (icd->sasc) + return; + ssdd = spi->dev.platform_data; + v4l2_device_unregister_subdev(sd); + spi_unregister_device(spi); + kfree(ssdd); + v4l2_clk_unregister(icd->clk); + icd->clk = NULL; +} + /* * V4L2 asynchronous notifier callbacks. They are all called under a v4l2-async * internal global mutex, therefore cannot race against other asynchronous @@ -1762,6 +1848,10 @@ static int soc_camera_probe(struct soc_camera_host *ici, ret = soc_camera_i2c_init(icd, sdesc); if (ret < 0 && ret != -EPROBE_DEFER) goto eadd; + } else if (shd->board_info_spi) { + ret = soc_camera_spi_init(icd, sdesc); + if (ret < 0) + goto eadd; } else if (!shd->add_device || !shd->del_device) { ret = -EINVAL; goto eadd; @@ -1803,6 +1893,8 @@ static int soc_camera_probe(struct soc_camera_host *ici, efinish: if (shd->board_info) { soc_camera_i2c_free(icd); + } else if (shd->board_info_spi) { + soc_camera_spi_free(icd); } else { shd->del_device(icd); module_put(control->driver->owner); @@ -1843,6 +1935,8 @@ static int soc_camera_remove(struct soc_camera_device *icd) if (sdesc->host_desc.board_info) { soc_camera_i2c_free(icd); + } else if (sdesc->host_desc.board_info_spi) { + soc_camera_spi_free(icd); } else { struct device *dev = to_soc_camera_control(icd); struct device_driver *drv = dev ? dev->driver : NULL; diff --git a/include/media/soc_camera.h b/include/media/soc_camera.h index 2f6261f..a948ff6 100644 --- a/include/media/soc_camera.h +++ b/include/media/soc_camera.h @@ -178,6 +178,8 @@ struct soc_camera_host_desc { int i2c_adapter_id; struct i2c_board_info *board_info; const char *module_name; + struct spi_board_info *board_info_spi; + int spi_bus_id; /* * For non-I2C devices platform has to provide methods to add a device @@ -243,6 +245,8 @@ struct soc_camera_link { int i2c_adapter_id; struct i2c_board_info *board_info; const char *module_name; + struct spi_board_info *board_info_spi; + int spi_bus_id; /* * For non-I2C devices platform has to provide methods to add a device