From patchwork Thu Sep 10 06:36:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 7151061 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@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 5262BBEEC1 for ; Thu, 10 Sep 2015 06:36:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EA50720899 for ; Thu, 10 Sep 2015 06:36:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2C50720898 for ; Thu, 10 Sep 2015 06:36:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753143AbbIJGgU (ORCPT ); Thu, 10 Sep 2015 02:36:20 -0400 Received: from relmlor3.renesas.com ([210.160.252.173]:47302 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752843AbbIJGgT (ORCPT ); Thu, 10 Sep 2015 02:36:19 -0400 Received: from unknown (HELO relmlir2.idc.renesas.com) ([10.200.68.152]) by relmlie2.idc.renesas.com with ESMTP; 10 Sep 2015 15:36:17 +0900 Received: from relmlac1.idc.renesas.com (relmlac1.idc.renesas.com [10.200.69.21]) by relmlir2.idc.renesas.com (Postfix) with ESMTP id 1E9044CCAE; Thu, 10 Sep 2015 15:36:17 +0900 (JST) Received: by relmlac1.idc.renesas.com (Postfix, from userid 0) id 0D6258002E; Thu, 10 Sep 2015 15:36:17 +0900 (JST) Received: from relmlac1.idc.renesas.com (localhost [127.0.0.1]) by relmlac1.idc.renesas.com (Postfix) with ESMTP id 078328002D; Thu, 10 Sep 2015 15:36:17 +0900 (JST) Received: from relmlii1.idc.renesas.com [10.200.68.65] by relmlac1.idc.renesas.com with ESMTP id RAL19261; Thu, 10 Sep 2015 15:36:16 +0900 X-IronPort-AV: E=Sophos;i="5.17,502,1437404400"; d="scan'";a="194137375" Received: from mail-pu1apc01lp0016.outbound.protection.outlook.com (HELO APC01-PU1-obe.outbound.protection.outlook.com) ([65.55.88.16]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES256-SHA; 10 Sep 2015 15:36:16 +0900 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=kuninori.morimoto.gx@renesas.com; Received: from morimoto-PC.renesas.com (211.11.155.144) by HKXPR06MB0600.apcprd06.prod.outlook.com (10.161.181.149) with Microsoft SMTP Server (TLS) id 15.1.262.15; Thu, 10 Sep 2015 06:36:14 +0000 Message-ID: <87mvwuokd3.wl%kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH] misc: add CS2000 Fractional-N driver User-Agent: Wanderlust/2.15.9 Emacs/24.3 Mule/6.0 To: Simon , Arnd Bergmann , Greg Kroah-Hartman CC: , Magnus , MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Date: Thu, 10 Sep 2015 06:36:14 +0000 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: TY1PR0201CA0008.apcprd02.prod.outlook.com (25.164.90.146) To HKXPR06MB0600.apcprd06.prod.outlook.com (25.161.181.149) X-Microsoft-Exchange-Diagnostics: 1; HKXPR06MB0600; 2:qyWmL2NC7p543kNPwVL2NODWdVYFDmEjD/VmfoigXkxMwJadn7AkTTOIHJZsWk1m9hyJNLdacmqNpcay+Xmi6oTyMqm8qmF+NDMGdZuClmAHntlFibjCVpPEFEBXhNA8AJELrgUNsCxSGQAwhkdbz4mk9R7Ia5ubsV4kg8KMQ9s=; 3:HYXpAJFIhBmJIZoiZQJ9GfV4U5tQYqpNnDtHt87d88QFh1N2oBVaaCfT/E0BlbKk9PJuRqSP4xZGJ3apWgCUnHmc+dha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A4sEtPIgUdp4Bs8XZm4uRCAtkAjKEtDS07q7s5/QWEfAda08NaWNc2wzDeOPtPwqRzjWTcKYoi3R4xmecpT3SPbWYw0bhMekDE0sz1yUJcl6IZraI40ooB3QGNGypJf8mVpKZcqlyKeppAoIKmN/8puHzhOSIrmNdchWXMw4ZoXFRkwzlyEtiFbgOXJJRM+5 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(8121501046)(5005006)(3002001); SRVR:HKXPR06MB0600; BCL:0; PCL:0; RULEID:; SRVR:HKXPR06MB0600; X-Forefront-PRVS: 06952FC175 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(199003)(189002)(53416004)(5007970100001)(77156002)(50466002)(5004730100002)(23726002)(54356999)(42186005)(62966003)(105586002)(106356001)(87976001)(83506001)(92566002)(19580395003)(50986999)(5001830100001)(36756003)(33646002)(229853001)(97736004)(5001770100001)(81156007)(64706001)(46406003)(66066001)(19580405001)(4001540100001)(69596002)(86362001)(40100003)(122386002)(46102003)(101416001)(189998001)(5001920100001)(68736005)(5001860100001)(47776003)(77096005)(5001960100002)(4001350100001)(2004002); DIR:OUT; SFP:1102; SCL:1; SRVR:HKXPR06MB0600; H:morimoto-PC.renesas.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HKXPR06MB0600; 23:usuIjrrfzsmOEd5NCtUHtjjca5iZjH0cvoCE1Yb1F?= =?us-ascii?Q?FAxj2HW0WMwK9kZ7bjjKTJkmv4vRXdS4Zs0o4F4E2jQh8d/TGLJfz/nz14uJ?= =?us-ascii?Q?kHe08Dfx1XfuAvbMH+kPDz+ybbugNVX+6ZoJZHmeFj+lfR+1VpNTEi4KB0CE?= =?us-ascii?Q?bykw6RqfykufOTnYAAdg9m9SwKm7N9fc2Zf3ge3CNF3pYMD3Eso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IqDsB7WV7SzVUwNBSh4iJ0QR+IaVmLLp6Nsq4dot5pu4?= =?us-ascii?Q?EFQuhZxiXQz5S+/CB8Vy8wxiKbW/s5SRh4ywqBU2hPPNKSzpVpu5Yux/aJAv?= =?us-ascii?Q?AtSUUwIZWkDloG21j4mNhPrUwyB6/6F7he/RrcEd2sSYFz98spPtahoV3Y1y?= =?us-ascii?Q?k/EWoQqycf4JtNt28k=3D?= X-Microsoft-Exchange-Diagnostics: 1; HKXPR06MB0600; 5:9jF1FU3CTLXLCUitA9Hr5S9qujLMn6NZn17YBaF1eiLYeI8O+uDLEsSd57DPMLuKg+qr9lnHFOaXy8J2TPIS018dhNFB9lPtxagWjogBm/oRapLUkiGkOPPwf+lJQ+UUlCsL0yX4wOibWkFw54bM4Q==; 24:6VRkEuCezNSdLoSs2yQ/o8VIC091LMloCPb2q/XqIV+BHRVRSXvl8DlN/B6Cb8JxNMXLrazmi7dRqoSEYKEBBvHaP+GmIdBRm7dazjLjtlQ=; 20:EFgXOGcU+JHrusZtlW1qYoS/+00mRdbQG8BzqJqpfStkqLSeAeWUGh3ZKkSyk3/h+URuaoGnXVj1Qg7wq9+oiC83QWHo6XBYcngeziY5mD0tfBbj136holHFCQZULwBLswZWZ1MxCY2ObcDgDAbApD7Mr8FenR686pmsZz1Ih2I= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2015 06:36:14.3334 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HKXPR06MB0600 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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: Kuninori Morimoto This patch adds CS2000 Fractional-N driver as clock provider. It is useful if it supports runtime clock setting, but it supports fixed clock rate at this point. Signed-off-by: Kuninori Morimoto --- .../devicetree/bindings/misc/cs2000-cp.txt | 20 ++ drivers/misc/Kconfig | 6 + drivers/misc/Makefile | 1 + drivers/misc/cs2000-cp.c | 341 +++++++++++++++++++++ 4 files changed, 368 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/cs2000-cp.txt create mode 100644 drivers/misc/cs2000-cp.c diff --git a/Documentation/devicetree/bindings/misc/cs2000-cp.txt b/Documentation/devicetree/bindings/misc/cs2000-cp.txt new file mode 100644 index 0000000..e79cf10 --- /dev/null +++ b/Documentation/devicetree/bindings/misc/cs2000-cp.txt @@ -0,0 +1,20 @@ +CIRRUS LOGIC Fractional-N Clock Synthesizer & Clock Multiplier + +Required properties: + +- compatible: "cirrus,cs2000-cp" +- reg: The chip select number on the I2C bus +- clocks: common clock binding for CLK_IN, XTI/REF_CLK +- clock-frequency: clock frequency of CLK_OUT + +Example: + +&i2c2 { + ... + cs2000: clk_multiplier@0x4f { + compatible = "cirrus,cs2000-cp"; + reg = <0x4f>; + clocks = <&rcar_sound 0>, <&x12_clk>; + clock-frequency = <24576000>; /* 1/1 divide */ + }; +}; diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index ccccc29..deec03e 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -224,6 +224,12 @@ config SGI_XP this feature will allow for direct communication between SSIs based on a network adapter and DMA messaging. +config CS2000_CP + tristate "CS2000 Fractional-N Clock Synthesizer & Clock Multiplier" + depends on I2C + help + If you say yes here you get support for the CS2000 clock multiplier + config CS5535_MFGPT tristate "CS5535/CS5536 Geode Multi-Function General Purpose Timer (MFGPT) support" depends on MFD_CS5535 diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 537d7f3b..36491e6 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -27,6 +27,7 @@ obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o obj-$(CONFIG_KGDB_TESTS) += kgdbts.o obj-$(CONFIG_SGI_XP) += sgi-xp/ obj-$(CONFIG_SGI_GRU) += sgi-gru/ +obj-$(CONFIG_CS2000_CP) += cs2000-cp.o obj-$(CONFIG_CS5535_MFGPT) += cs5535-mfgpt.o obj-$(CONFIG_HP_ILO) += hpilo.o obj-$(CONFIG_APDS9802ALS) += apds9802als.o diff --git a/drivers/misc/cs2000-cp.c b/drivers/misc/cs2000-cp.c new file mode 100644 index 0000000..be639e3 --- /dev/null +++ b/drivers/misc/cs2000-cp.c @@ -0,0 +1,341 @@ +/* + * CS2000 -- CIRRUS LOGIC Fractional-N Clock Synthesizer & Clock Multiplier + * + * Copyright (C) 2015 Renesas Electronics Corporation + * Kuninori Morimoto + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#include +#include +#include +#include +#include +#include + +#define CLK_MAIN 0 /* CLK_IN on datasheet */ +#define CLK_IN 1 /* REF_CLK on datasheet */ + +#define CH_MAX 4 + +#define DEVICE_ID 0x1 +#define DEVICE_CTRL 0x2 +#define DEVICE_CFG1 0x3 +#define DEVICE_CFG2 0x4 +#define GLOBAL_CFG 0x5 +#define Ratio_Add(x, nth) (6 + (x * 4) + (nth)) +#define Ratio_Val(x, nth) ((x >> (24 - (8 * nth))) & 0xFF) +#define FUNC_CFG1 0x16 +#define FUNC_CFG2 0x17 + +/* DEVICE_CTRL */ +#define PLL_UNLOCK (1 << 7) + +/* DEVICE_CFG1 */ +#define RSEL(x) (((x) & 0x3) << 3) +#define RSEL_MASK RSEL(0x3) +#define ENDEV1 (0x1) + +/* GLOBAL_CFG */ +#define ENDEV2 (0x1) + + +#define CH_ERR(ch) ((ch < 0) || (ch >= CH_MAX)) + +struct cs2000_priv { + struct clk *clk_main; + struct clk *clk_in; + struct clk *clk_out; +}; + +static const struct of_device_id cs2000_of_match[] = { + { .compatible = "cirrus,cs2000-cp", }, + {}, +}; +MODULE_DEVICE_TABLE(of, cs2000_of_match); + +static const struct i2c_device_id cs2000_id[] = { + { "cs2000-cp", }, + {} +}; +MODULE_DEVICE_TABLE(i2c, cs2000_id); + +#define cs2000_read(c, addr) i2c_smbus_read_byte_data(c, addr) +static void cs2000_write(struct i2c_client *client, u8 addr, u8 val) +{ + struct device *dev = &client->dev; + + dev_dbg(dev, "0x%02x : 0x%02x\n", addr, val); + + i2c_smbus_write_byte_data(client, addr, val); +} + +static void cs2000_bset(struct i2c_client *client, u8 addr, u8 mask, u8 val) +{ + u32 data; + + data = cs2000_read(client, addr); + + data &= ~mask; + data |= (val & mask); + + cs2000_write(client, addr, data); +} + +static int cs2000_ratio_set(struct i2c_client *client, + int ch, u32 rate_in, u64 rate_out) +{ + u32 val; + int i; + + if (CH_ERR(ch)) + return -EINVAL; + + /* + * ratio = rate_out / rate_in * 2^20 + * + * To avoid over flow, rate_out is u64 + * The result should be u32 + */ + + val = rate_out * (1 << 20) / rate_in; + for (i = 0; i < 4; i++) + cs2000_write(client, + Ratio_Add(ch, i), + Ratio_Val(val, i)); + + return 0; +} + +static int cs2000_ratio_select(struct i2c_client *client, int ch) +{ + if (CH_ERR(ch)) + return -EINVAL; + + /* + * FIXME + * + * this driver supports static ratio mode only + * at this point + */ + cs2000_bset(client, DEVICE_CFG1, RSEL_MASK, RSEL(ch)); + cs2000_write(client, DEVICE_CFG2, 0x0); + + return 0; +} + +static int cs2000_enable_dev_config(struct i2c_client *client) +{ + cs2000_bset(client, DEVICE_CFG1, ENDEV1, ENDEV1); + cs2000_bset(client, GLOBAL_CFG, ENDEV2, ENDEV2); + + return 0; +} + +static int cs2000_get_clk(struct i2c_client *client, + u32 *rate_in, u32 *rate_out) +{ + struct cs2000_priv *priv = i2c_get_clientdata(client); + struct device *dev = &client->dev; + struct device_node *np = dev->of_node; + struct clk *clk_main, *clk_in; + + clk_main = of_clk_get(np, CLK_MAIN); + /* not yet provided */ + if (IS_ERR(clk_main)) + return -EPROBE_DEFER; + + clk_in = of_clk_get(np, CLK_IN); + if (IS_ERR(clk_in)) + return PTR_ERR(clk_in); + + *rate_in = clk_get_rate(clk_in); + + if (of_property_read_u32(np, "clock-frequency", rate_out)) + return -EINVAL; + + dev_dbg(dev, "%d -> %d\n", + *rate_in, *rate_out); + + priv->clk_main = clk_main; + priv->clk_in = clk_in; + + return 0; +} + +static int cs2000_clk_in_bound_rate(struct i2c_client *client, + u32 rate_in) +{ + u32 val; + + if ((32000000 <= rate_in) && + (56000000 > rate_in)) + val = 0x0; + else if ((16000000 <= rate_in) && + (28000000 > rate_in)) + val = 0x1; + else if ((8000000 <= rate_in) && + (14000000 > rate_in)) + val = 0x2; + else + return -EINVAL; + + cs2000_bset(client, FUNC_CFG1, 0x3 << 3, val << 3); + + return 0; +} + +static int cs2000_wait_pll_lock(struct i2c_client *client) +{ + struct device *dev = &client->dev; + u32 val; + int i; + + for (i = 0; i < 256; i++) { + val = cs2000_read(client, DEVICE_CTRL); + if (!(val & PLL_UNLOCK)) + return 0; + udelay(1); + } + + dev_err(dev, "pll lock failed\n"); + + return -EIO; +} + +static int cs2000_enable_clk_out(struct i2c_client *client) +{ + /* enable both AUX_OUT, CLK_OUT */ + cs2000_write(client, DEVICE_CTRL, 0x0); + + return 0; +} + +static int cs2000_register_clock(struct i2c_client *client) +{ + struct cs2000_priv *priv = i2c_get_clientdata(client); + struct device *dev = &client->dev; + struct device_node *np = dev->of_node; + struct clk *clk; + const char *parent_clk_name = __clk_get_name(priv->clk_in); + u32 rate; + + if (of_property_read_u32(np, "clock-frequency", &rate)) + return -EINVAL; + + /* + * FIXME + * + * register this driver as fixed rate clock + * at this point + */ + clk = clk_register_fixed_rate(dev, "clk_out", parent_clk_name, + (parent_clk_name) ? 0 : CLK_IS_ROOT, + rate); + if (IS_ERR(clk)) + return PTR_ERR(clk); + + priv->clk_out = clk; + of_clk_add_provider(np, of_clk_src_simple_get, clk); + + return 0; +} + +static int cs2000_version_print(struct i2c_client *client) +{ + struct device *dev = &client->dev; + u32 val = cs2000_read(client, DEVICE_ID); + char *revision; + + /* CS2000 should be 0x0 */ + if (0 != (val >> 3)) + return -EIO; + + switch (val & 0x7) { + case 0x4: + revision = "B2 / B3"; + break; + case 0x6: + revision = "C1"; + break; + default: + return -EIO; + } + + dev_info(dev, "revision - %s\n", revision); + + return 0; +} + +static int cs2000_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct cs2000_priv *priv; + struct device *dev = &client->dev; + u32 rate_in = 0; + u32 rate_out = 0; + int ret; + int ch = 0; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + i2c_set_clientdata(client, priv); + + ret = cs2000_get_clk(client, &rate_in, &rate_out); + if (ret < 0) + return ret; + + ret = cs2000_enable_dev_config(client); + if (ret < 0) + return ret; + + ret = cs2000_clk_in_bound_rate(client, rate_in); + if (ret < 0) + return ret; + + ret = cs2000_ratio_set(client, ch, rate_in, rate_out); + if (ret < 0) + return ret; + + ret = cs2000_ratio_select(client, ch); + if (ret < 0) + return ret; + + ret = cs2000_wait_pll_lock(client); + if (ret < 0) + return ret; + + ret = cs2000_enable_clk_out(client); + if (ret < 0) + return ret; + + ret = cs2000_register_clock(client); + if (ret < 0) + return ret; + + ret = cs2000_version_print(client); + if (ret < 0) + return ret; + + return 0; +} + +static struct i2c_driver cs2000_driver = { + .driver = { + .name = "cs2000-cp", + .owner = THIS_MODULE, + .of_match_table = cs2000_of_match, + }, + .probe = cs2000_probe, + .id_table = cs2000_id, +}; + +module_i2c_driver(cs2000_driver); + +MODULE_DESCRIPTION("CS2000-CP driver"); +MODULE_AUTHOR("Kuninori Morimoto "); +MODULE_LICENSE("GPL v2");