From patchwork Fri May 4 18:23:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 8400 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 802F123EAB for ; Fri, 4 May 2012 18:23:44 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id 39B30A18068 for ; Fri, 4 May 2012 18:23:44 +0000 (UTC) Received: by gglu1 with SMTP id u1so659646ggl.11 for ; Fri, 04 May 2012 11:23:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=qYVFMwlMT+Dcp21jUqda6MpMQfhnwIH38dtCqGNaiZI=; b=KEicH22k0r7EHxKiPoVP1LXEHbbQZgdsNN+BrDOCyStl8rzorsXXArwvKyU+YA/9iS 46vfPCEjpJSPYmKwRaQD9a6Hb7e6hgTHU6m2prtrNoPiiMwRmoMYsRxC9hD+biSv7diC 6SsXOn/HPln4bR7hwsLmw5pZ7dtfm+xE7smt8xMRGsOgHf6XCZiBuwbPe7C3wDArexfr 2MHm/hDJAl/K2DWppagYN5m2r6wwRVS8mzqG/453YQ1Ue/YDDycXTPey41uLJLMH0gdi 2vpxEIbJqpkGXZKK2nv78vxgkiSf/7tWo83uJRdPGlEc7zHfB+VNJpPMcz/19mZQMkRb CDcg== Received: by 10.42.122.76 with SMTP id m12mr3160901icr.38.1336155823566; Fri, 04 May 2012 11:23:43 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.137.198 with SMTP id x6csp106242ibt; Fri, 4 May 2012 11:23:41 -0700 (PDT) Received: by 10.180.92.9 with SMTP id ci9mr15226712wib.15.1336155821513; Fri, 04 May 2012 11:23:41 -0700 (PDT) Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com [209.85.212.172]) by mx.google.com with ESMTPS id x65si10940785weq.85.2012.05.04.11.23.41 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 04 May 2012 11:23:41 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.172 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.212.172; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.172 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) smtp.mail=lee.jones@linaro.org Received: by wibhj6 with SMTP id hj6so1338560wib.13 for ; Fri, 04 May 2012 11:23:41 -0700 (PDT) Received: by 10.180.83.38 with SMTP id n6mr15318443wiy.4.1336155820953; Fri, 04 May 2012 11:23:40 -0700 (PDT) Received: from localhost.localdomain ([89.192.128.60]) by mx.google.com with ESMTPS id fn2sm17590123wib.0.2012.05.04.11.23.38 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 04 May 2012 11:23:40 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org Cc: arnd@arndb.de, linus.walleij@stericsson.com, grant.likely@secretlab.ca, cjb@laptop.org, ben-linux@fluff.org, linux-i2c@vger.kernel.org, broonie@opensource.wolfsonmicro.com, sameo@linux.intel.com, Lee Jones Subject: [PATCH 01/15] i2c/busses: Add Device Tree support to the Nomadik I2C driver Date: Fri, 4 May 2012 19:23:11 +0100 Message-Id: <1336155805-18554-2-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1336155805-18554-1-git-send-email-lee.jones@linaro.org> References: <1336155805-18554-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQmhKeQ0+YTrynpjDBuWUNAtWsxSyxVDfIhAUfBRIFxRVNHz6mbwhcacQhvrKhOrJnnNICT6 Here we move the i2c-nomadik's default settings into the driver rather than specifying them from platform code. At the time of this writing we only have one user, the u8500. As new users are added, it is expected that they will be Device Tree compliant. If this is the case, we will look up their initialisation values by compatible entry, then apply them forthwith. Signed-off-by: Lee Jones --- drivers/i2c/busses/i2c-nomadik.c | 50 +++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c index 5267ab9..8803467 100644 --- a/drivers/i2c/busses/i2c-nomadik.c +++ b/drivers/i2c/busses/i2c-nomadik.c @@ -899,15 +899,57 @@ static const struct i2c_algorithm nmk_i2c_algo = { .functionality = nmk_i2c_functionality }; +static const struct nmk_i2c_controller u8500_i2c = { + /* + * slave data setup time, which is + * 250 ns,100ns,10ns which is 14,6,2 + * respectively for a 48 Mhz + * i2c clock + */ + .slsu = 0xe, + /* Tx FIFO threshold */ + .tft = 1, + /* Rx FIFO threshold */ + .rft = 8, + /* std. mode operation */ + .clk_freq = 100000, + /* Slave response timeout(ms) */ + .timeout = 200, + .sm = I2C_FREQ_MODE_FAST, +}; + +static const struct nmk_i2c_controller * +nmk_i2c_find_pdata_from_compatible(struct device_node *np) +{ + /* + * The u8500 is currently our only user. As more SoCs are added, + * search for the correct value set using of_machine_is_compatible + * and return a 'struct nmk_i2c_controller *' which contains the + * correct information for the given SoC, whilst leaving u8500_i2c + * as the default/fall-back value set. + */ + return &u8500_i2c; +} + static int __devinit nmk_i2c_probe(struct platform_device *pdev) { int ret = 0; struct resource *res; - struct nmk_i2c_controller *pdata = + const struct nmk_i2c_controller *pdata = pdev->dev.platform_data; + struct device_node *np = pdev->dev.of_node; struct nmk_i2c_dev *dev; struct i2c_adapter *adap; + if (!pdata) { + if (!np) { + dev_err(&pdev->dev, + "Neither platform_data nor Device Tree not found\n"); + return -EINVAL; + } + pdata = nmk_i2c_find_pdata_from_compatible(np); + } + dev = kzalloc(sizeof(struct nmk_i2c_dev), GFP_KERNEL); if (!dev) { dev_err(&pdev->dev, "cannot allocate memory\n"); @@ -1039,11 +1081,17 @@ static int __devexit nmk_i2c_remove(struct platform_device *pdev) return 0; } +static const struct of_device_id nmk_gpio_match[] = { + { .compatible = "st,nomadik-i2c", }, + {} +}; + static struct platform_driver nmk_i2c_driver = { .driver = { .owner = THIS_MODULE, .name = DRIVER_NAME, .pm = &nmk_i2c_pm, + .of_match_table = nmk_gpio_match, }, .probe = nmk_i2c_probe, .remove = __devexit_p(nmk_i2c_remove),