From patchwork Wed Nov 13 08:42:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Shiyan X-Patchwork-Id: 3177611 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 55253C045B for ; Wed, 13 Nov 2013 08:43:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DA1D02058C for ; Wed, 13 Nov 2013 08:43:19 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 27DFC204B5 for ; Wed, 13 Nov 2013 08:43:18 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VgW2b-0002ji-Q2; Wed, 13 Nov 2013 08:43:14 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VgW2Z-0000CC-Bq; Wed, 13 Nov 2013 08:43:11 +0000 Received: from smtp12.mail.ru ([94.100.176.89]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VgW2W-0000Ae-4Q for linux-arm-kernel@lists.infradead.org; Wed, 13 Nov 2013 08:43:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail2; h=Message-Id:Date:Subject:Cc:To:From; bh=9JnqbaezWb/0I5PlQQMPqEZqyEsvXsqp2VWxS8yS1n8=; b=tIie9FhJFIFVOXNXaXH0SJZ/CmWyv1wPphq2z4ij2g3SEIrqXF4o9Eua9QHOLGLEoicHW5spUzucUPgjCmUSQWqShmOPO/O3crw+DVgnSlF6PK7SZcVoxXnizIvGXdxkjVjktiAa5o63XQS5HZ8ETRkCffNhpnK3LUc2lYoAkm8=; Received: from [217.119.30.118] (port=24513 helo=shc.milas.spb.ru) by smtp12.mail.ru with esmtpa (envelope-from ) id 1VgW28-0006B5-MH; Wed, 13 Nov 2013 12:42:45 +0400 From: Alexander Shiyan To: linux-can@vger.kernel.org Subject: [PATCH 1/3] can: mcp251x: Convert driver to use common clk framework Date: Wed, 13 Nov 2013 12:42:24 +0400 Message-Id: <1384332144-15211-1-git-send-email-shc_work@mail.ru> X-Mailer: git-send-email 1.8.1.5 X-Mras: Ok X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131113_034308_586843_7E21A26C X-CRM114-Status: GOOD ( 23.20 ) X-Spam-Score: -1.2 (-) Cc: Russell King , Alexander Shiyan , netdev@vger.kernel.org, Haojian Zhuang , Marc Kleine-Budde , linux-arm-kernel@lists.infradead.org, Sascha Hauer , Eric Miao , Wolfgang Grandegger X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_WEB,RP_MATCHES_RCVD, T_DKIM_INVALID,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 This patch converts mcp251x driver to using common clk framework for getting input frequency. The change was made for the preparation of the driver work with the devicetree. As a result private header for the driver is eliminated. Additionally, all existing users of the driver was converted to use this feature. Signed-off-by: Alexander Shiyan Acked-by: Marc Kleine-Budde --- arch/arm/mach-imx/mach-cpuimx51sd.c | 18 ++++++++++---- arch/arm/mach-pxa/icontrol.c | 23 +++++++++++------ arch/arm/mach-pxa/zeus.c | 18 ++++++++++---- drivers/net/can/mcp251x.c | 48 ++++++++++++++++++------------------ include/linux/can/platform/mcp251x.h | 21 ---------------- 5 files changed, 65 insertions(+), 63 deletions(-) delete mode 100644 include/linux/can/platform/mcp251x.h diff --git a/arch/arm/mach-imx/mach-cpuimx51sd.c b/arch/arm/mach-imx/mach-cpuimx51sd.c index 9b5ddf5..493c0fc 100644 --- a/arch/arm/mach-imx/mach-cpuimx51sd.c +++ b/arch/arm/mach-imx/mach-cpuimx51sd.c @@ -24,7 +24,8 @@ #include #include #include -#include +#include +#include #include #include @@ -244,9 +245,14 @@ static struct platform_device hsi2c_gpio_device = { .dev.platform_data = &pdata, }; -static struct mcp251x_platform_data mcp251x_info = { - .oscillator_frequency = 24E6, -}; +static void initialize_clocks(void) +{ + struct clk *clk24; + + clk24 = clk_register_fixed_rate(NULL, "clk24", NULL, + CLK_IS_ROOT, 24000000); + clk_register_clkdev(clk24, NULL, "spi0.0"); +} static struct spi_board_info cpuimx51sd_spi_device[] = { { @@ -255,7 +261,6 @@ static struct spi_board_info cpuimx51sd_spi_device[] = { .bus_num = 0, .mode = SPI_MODE_0, .chip_select = 0, - .platform_data = &mcp251x_info, /* irq number is run-time assigned */ }, }; @@ -302,6 +307,9 @@ static void __init eukrea_cpuimx51sd_init(void) gpio_direction_output(CAN_RST, 0); msleep(20); gpio_set_value(CAN_RST, 1); + + initialize_clocks(); + imx51_add_ecspi(0, &cpuimx51sd_ecspi1_pdata); cpuimx51sd_spi_device[0].irq = gpio_to_irq(CAN_IRQGPIO); spi_register_board_info(cpuimx51sd_spi_device, diff --git a/arch/arm/mach-pxa/icontrol.c b/arch/arm/mach-pxa/icontrol.c index c98511c..ebf453e 100644 --- a/arch/arm/mach-pxa/icontrol.c +++ b/arch/arm/mach-pxa/icontrol.c @@ -23,9 +23,10 @@ #include #include +#include +#include #include #include -#include #include "generic.h" @@ -71,9 +72,17 @@ static struct pxa2xx_spi_chip mcp251x_chip_info4 = { .gpio_cs = ICONTROL_MCP251x_nCS4 }; -static struct mcp251x_platform_data mcp251x_info = { - .oscillator_frequency = 16E6, -}; +static void initialize_clocks(void) +{ + struct clk *clk16; + + clk16 = clk_register_fixed_rate(NULL, "clk16", NULL, + CLK_IS_ROOT, 16000000); + clk_register_clkdev(clk16, NULL, "spi3.0"); + clk_register_clkdev(clk16, NULL, "spi3.1"); + clk_register_clkdev(clk16, NULL, "spi4.0"); + clk_register_clkdev(clk16, NULL, "spi4.1"); +} static struct spi_board_info mcp251x_board_info[] = { { @@ -81,7 +90,6 @@ static struct spi_board_info mcp251x_board_info[] = { .max_speed_hz = 6500000, .bus_num = 3, .chip_select = 0, - .platform_data = &mcp251x_info, .controller_data = &mcp251x_chip_info1, .irq = PXA_GPIO_TO_IRQ(ICONTROL_MCP251x_nIRQ1) }, @@ -90,7 +98,6 @@ static struct spi_board_info mcp251x_board_info[] = { .max_speed_hz = 6500000, .bus_num = 3, .chip_select = 1, - .platform_data = &mcp251x_info, .controller_data = &mcp251x_chip_info2, .irq = PXA_GPIO_TO_IRQ(ICONTROL_MCP251x_nIRQ2) }, @@ -99,7 +106,6 @@ static struct spi_board_info mcp251x_board_info[] = { .max_speed_hz = 6500000, .bus_num = 4, .chip_select = 0, - .platform_data = &mcp251x_info, .controller_data = &mcp251x_chip_info3, .irq = PXA_GPIO_TO_IRQ(ICONTROL_MCP251x_nIRQ3) }, @@ -108,7 +114,6 @@ static struct spi_board_info mcp251x_board_info[] = { .max_speed_hz = 6500000, .bus_num = 4, .chip_select = 1, - .platform_data = &mcp251x_info, .controller_data = &mcp251x_chip_info4, .irq = PXA_GPIO_TO_IRQ(ICONTROL_MCP251x_nIRQ4) } @@ -173,6 +178,8 @@ static mfp_cfg_t mfp_can_cfg[] __initdata = { static void __init icontrol_can_init(void) { + initialize_clocks(); + pxa3xx_mfp_config(ARRAY_AND_SIZE(mfp_can_cfg)); platform_add_devices(ARRAY_AND_SIZE(icontrol_spi_devices)); spi_register_board_info(ARRAY_AND_SIZE(mcp251x_board_info)); diff --git a/arch/arm/mach-pxa/zeus.c b/arch/arm/mach-pxa/zeus.c index b19d1c3..7009e6e 100644 --- a/arch/arm/mach-pxa/zeus.c +++ b/arch/arm/mach-pxa/zeus.c @@ -28,7 +28,8 @@ #include #include #include -#include +#include +#include #include #include @@ -419,14 +420,18 @@ static struct platform_device can_regulator_device = { }, }; -static struct mcp251x_platform_data zeus_mcp2515_pdata = { - .oscillator_frequency = 16*1000*1000, -}; +static void initialize_clocks(void) +{ + struct clk *clk16; + + clk16 = clk_register_fixed_rate(NULL, "clk16", NULL, + CLK_IS_ROOT, 16000000); + clk_register_clkdev(clk16, NULL, "spi3.0"); +} static struct spi_board_info zeus_spi_board_info[] = { [0] = { .modalias = "mcp2515", - .platform_data = &zeus_mcp2515_pdata, .irq = PXA_GPIO_TO_IRQ(ZEUS_CAN_GPIO), .max_speed_hz = 1*1000*1000, .bus_num = 3, @@ -859,6 +864,9 @@ static void __init zeus_init(void) pxa_set_ac97_info(&zeus_ac97_info); pxa_set_i2c_info(NULL); i2c_register_board_info(0, ARRAY_AND_SIZE(zeus_i2c_devices)); + + initialize_clocks(); + pxa2xx_set_spi_info(3, &pxa2xx_spi_ssp3_master_info); spi_register_board_info(zeus_spi_board_info, ARRAY_SIZE(zeus_spi_board_info)); } diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c index 08ac401..3a8d80b 100644 --- a/drivers/net/can/mcp251x.c +++ b/drivers/net/can/mcp251x.c @@ -35,30 +35,21 @@ * * Your platform definition file should specify something like: * - * static struct mcp251x_platform_data mcp251x_info = { - * .oscillator_frequency = 8000000, - * }; - * * static struct spi_board_info spi_board_info[] = { * { * .modalias = "mcp2510", * // or "mcp2515" depending on your controller - * .platform_data = &mcp251x_info, * .irq = IRQ_EINT13, * .max_speed_hz = 2*1000*1000, * .chip_select = 2, * }, * }; - * - * Please see mcp251x.h for a description of the fields in - * struct mcp251x_platform_data. - * */ #include #include #include -#include +#include #include #include #include @@ -264,6 +255,7 @@ struct mcp251x_priv { int restart_tx; struct regulator *power; struct regulator *transceiver; + struct clk *clk; }; #define MCP251X_IS(_model) \ @@ -999,27 +991,30 @@ static int mcp251x_can_probe(struct spi_device *spi) { struct net_device *net; struct mcp251x_priv *priv; - struct mcp251x_platform_data *pdata = dev_get_platdata(&spi->dev); - int ret = -ENODEV; - - if (!pdata) - /* Platform data is required for osc freq */ - goto error_out; + int ret; /* Allocate can/net device */ net = alloc_candev(sizeof(struct mcp251x_priv), TX_ECHO_SKB_MAX); - if (!net) { - ret = -ENOMEM; - goto error_alloc; - } + if (!net) + return -ENOMEM; net->netdev_ops = &mcp251x_netdev_ops; net->flags |= IFF_ECHO; priv = netdev_priv(net); + + priv->clk = devm_clk_get(&spi->dev, NULL); + if (IS_ERR(priv->clk)) + ret = PTR_ERR(priv->clk); + else + ret = clk_prepare_enable(priv->clk); + + if (ret) + goto error_clk; + priv->can.bittiming_const = &mcp251x_bittiming_const; priv->can.do_set_mode = mcp251x_do_set_mode; - priv->can.clock.freq = pdata->oscillator_frequency / 2; + priv->can.clock.freq = clk_get_rate(priv->clk) / 2; priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LOOPBACK | CAN_CTRLMODE_LISTENONLY; priv->model = spi_get_device_id(spi)->driver_data; @@ -1117,12 +1112,15 @@ error_tx_buf: if (mcp251x_enable_dma) dma_free_coherent(&spi->dev, PAGE_SIZE, priv->spi_tx_buf, priv->spi_tx_dma); + mcp251x_power_enable(priv->power, 0); + error_power: + clk_disable_unprepare(priv->clk); + +error_clk: free_candev(net); -error_alloc: - dev_err(&spi->dev, "probe failed\n"); -error_out: + return ret; } @@ -1143,6 +1141,8 @@ static int mcp251x_can_remove(struct spi_device *spi) mcp251x_power_enable(priv->power, 0); + clk_disable_unprepare(priv->clk); + free_candev(net); return 0; diff --git a/include/linux/can/platform/mcp251x.h b/include/linux/can/platform/mcp251x.h deleted file mode 100644 index dc029db..0000000 --- a/include/linux/can/platform/mcp251x.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __CAN_PLATFORM_MCP251X_H__ -#define __CAN_PLATFORM_MCP251X_H__ - -/* - * - * CAN bus driver for Microchip 251x CAN Controller with SPI Interface - * - */ - -#include - -/* - * struct mcp251x_platform_data - MCP251X SPI CAN controller platform data - * @oscillator_frequency: - oscillator frequency in Hz - */ - -struct mcp251x_platform_data { - unsigned long oscillator_frequency; -}; - -#endif /* __CAN_PLATFORM_MCP251X_H__ */