From patchwork Thu Nov 14 09:29:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 21492 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f71.google.com (mail-oa0-f71.google.com [209.85.219.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C52F723FBC for ; Thu, 14 Nov 2013 09:29:37 +0000 (UTC) Received: by mail-oa0-f71.google.com with SMTP id k1sf4071444oag.6 for ; Thu, 14 Nov 2013 01:29:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=RsmbqYQUlkkCPOTpn211f48Ynoq2tX0jx4gzZRV/+Qo=; b=gMZIVcrneCWlTo/TyGZcVhwfQjQ6uqbRnN7cMH26vrQBnPL3ZYHbxayxNI4tJCyEO2 2FO/mmnGYZ4IQY585va93Fh8+CcUv5pT6DKORzKAlIv7Ea3/QkKOJNmq8Mnng97QbTGN 5rTKQhcYL2ErgA4MzGx8ilsOdDFAjYsKGvyKfwf7DNXUHFHZwm+CBCCGcxTpfs6tqCFb M+KrIffQED3hyKuttm7Cu2KzICb/tZVFn+WBXlyWsWf46gwV3jBnyirob/J0knl7YTuf +Y6wWPi9JlfTmHzHJy1tENo3OlzTFHZO0t4FJzKUtYUPJb1tFpe/Gc2oHRP+A28ExCws J6Jg== X-Gm-Message-State: ALoCoQkAt+RRMSqdrqEplhYzLHqn5vi86n3dzjCy8OnWr60j6lT7TGRDbMKVe+oeCId8uPhDQzdh X-Received: by 10.182.153.68 with SMTP id ve4mr157892obb.39.1384421377125; Thu, 14 Nov 2013 01:29:37 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.29.129 with SMTP id k1ls942186qeh.75.gmail; Thu, 14 Nov 2013 01:29:37 -0800 (PST) X-Received: by 10.52.37.36 with SMTP id v4mr155911vdj.54.1384421376977; Thu, 14 Nov 2013 01:29:36 -0800 (PST) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id nh5si16727969vec.30.2013.11.14.01.29.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 14 Nov 2013 01:29:36 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.169; Received: by mail-ve0-f169.google.com with SMTP id pa12so1600420veb.28 for ; Thu, 14 Nov 2013 01:29:36 -0800 (PST) X-Received: by 10.220.16.73 with SMTP id n9mr197689vca.24.1384421376878; Thu, 14 Nov 2013 01:29:36 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp302023vcz; Thu, 14 Nov 2013 01:29:36 -0800 (PST) X-Received: by 10.60.70.209 with SMTP id o17mr339069oeu.65.1384421376229; Thu, 14 Nov 2013 01:29:36 -0800 (PST) Received: from mail-oa0-f41.google.com (mail-oa0-f41.google.com [209.85.219.41]) by mx.google.com with ESMTPS id mx9si28475002obc.80.2013.11.14.01.29.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 14 Nov 2013 01:29:36 -0800 (PST) Received-SPF: neutral (google.com: 209.85.219.41 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.219.41; Received: by mail-oa0-f41.google.com with SMTP id g12so1937504oah.14 for ; Thu, 14 Nov 2013 01:29:36 -0800 (PST) X-Received: by 10.60.134.230 with SMTP id pn6mr440967oeb.52.1384421375921; Thu, 14 Nov 2013 01:29:35 -0800 (PST) Received: from localhost.localdomain (cpc15-aztw25-2-0-cust493.aztw.cable.virginm.net. [92.233.57.238]) by mx.google.com with ESMTPSA id rr6sm5545348oeb.0.2013.11.14.01.29.33 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 14 Nov 2013 01:29:35 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, sameo@linux.intel.com, micky_ching@realsil.com.cn Cc: linus.walleij@linaro.org, Lee Jones Subject: [PATCH 1/4] mfd: rtsx: Generify call-back operations in order to reduce code duplication Date: Thu, 14 Nov 2013 09:29:12 +0000 Message-Id: <1384421355-4434-2-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1384421355-4434-1-git-send-email-lee.jones@linaro.org> References: <1384421355-4434-1-git-send-email-lee.jones@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , With only a few variations between devices, it seems silly to keep bolting on entirely new and mostly duplicated operation structs when a generic one could be defined and the small differences could be handled in the init functions. Signed-off-by: Lee Jones --- drivers/mfd/rtl8411.c | 118 ++++++++++++++++++------------------------- include/linux/mfd/rtsx_pci.h | 2 +- 2 files changed, 50 insertions(+), 70 deletions(-) diff --git a/drivers/mfd/rtl8411.c b/drivers/mfd/rtl8411.c index 5280135..92e9bf6 100644 --- a/drivers/mfd/rtl8411.c +++ b/drivers/mfd/rtl8411.c @@ -279,38 +279,6 @@ static int rtl8411_conv_clk_and_div_n(int input, int dir) return output; } -static const struct pcr_ops rtl8411_pcr_ops = { - .fetch_vendor_settings = rtl8411_fetch_vendor_settings, - .extra_init_hw = rtl8411_extra_init_hw, - .optimize_phy = NULL, - .turn_on_led = rtl8411_turn_on_led, - .turn_off_led = rtl8411_turn_off_led, - .enable_auto_blink = rtl8411_enable_auto_blink, - .disable_auto_blink = rtl8411_disable_auto_blink, - .card_power_on = rtl8411_card_power_on, - .card_power_off = rtl8411_card_power_off, - .switch_output_voltage = rtl8411_switch_output_voltage, - .cd_deglitch = rtl8411_cd_deglitch, - .conv_clk_and_div_n = rtl8411_conv_clk_and_div_n, - .force_power_down = rtl8411_force_power_down, -}; - -static const struct pcr_ops rtl8411b_pcr_ops = { - .fetch_vendor_settings = rtl8411b_fetch_vendor_settings, - .extra_init_hw = rtl8411b_extra_init_hw, - .optimize_phy = NULL, - .turn_on_led = rtl8411_turn_on_led, - .turn_off_led = rtl8411_turn_off_led, - .enable_auto_blink = rtl8411_enable_auto_blink, - .disable_auto_blink = rtl8411_disable_auto_blink, - .card_power_on = rtl8411_card_power_on, - .card_power_off = rtl8411_card_power_off, - .switch_output_voltage = rtl8411_switch_output_voltage, - .cd_deglitch = rtl8411_cd_deglitch, - .conv_clk_and_div_n = rtl8411_conv_clk_and_div_n, - .force_power_down = rtl8411_force_power_down, -}; - /* SD Pull Control Enable: * SD_DAT[3:0] ==> pull up * SD_CD ==> pull up @@ -441,60 +409,72 @@ static const u32 rtl8411b_qfn48_ms_pull_ctl_disable_tbl[] = { 0, }; -void rtl8411_init_params(struct rtsx_pcr *pcr) +#define set_pull_ctrl_tables(__device) \ + pcr->sd_pull_ctl_enable_tbl = __device##_sd_pull_ctl_enable_tbl; \ + pcr->sd_pull_ctl_disable_tbl = __device##_sd_pull_ctl_disable_tbl; \ + pcr->ms_pull_ctl_enable_tbl = __device##_ms_pull_ctl_enable_tbl; \ + pcr->ms_pull_ctl_disable_tbl = __device##_ms_pull_ctl_disable_tbl; + +static struct pcr_ops rtl84xx_pcr_generic_ops = { + .fetch_vendor_settings = NULL, /* Dynamic */ + .extra_init_hw = NULL, /* Dynamic */ + .optimize_phy = NULL, + .turn_on_led = rtl8411_turn_on_led, + .turn_off_led = rtl8411_turn_off_led, + .enable_auto_blink = rtl8411_enable_auto_blink, + .disable_auto_blink = rtl8411_disable_auto_blink, + .card_power_on = rtl8411_card_power_on, + .card_power_off = rtl8411_card_power_off, + .switch_output_voltage = rtl84xx_switch_output_voltage, + .cd_deglitch = rtl8411_cd_deglitch, + .conv_clk_and_div_n = rtl8411_conv_clk_and_div_n, + .force_power_down = rtl8411_force_power_down, +}; + +void rtl84xx_generic_params(struct rtsx_pcr *pcr) { + pcr->ops = &rtl84xx_pcr_generic_ops; + pcr->extra_caps = EXTRA_CAPS_SD_SDR50 | EXTRA_CAPS_SD_SDR104; pcr->num_slots = 2; - pcr->ops = &rtl8411_pcr_ops; pcr->flags = 0; pcr->card_drive_sel = RTL8411_CARD_DRIVE_DEFAULT; pcr->sd30_drive_sel_1v8 = DRIVER_TYPE_B; pcr->sd30_drive_sel_3v3 = DRIVER_TYPE_D; pcr->aspm_en = ASPM_L1_EN; - pcr->tx_initial_phase = SET_CLOCK_PHASE(23, 7, 14); - pcr->rx_initial_phase = SET_CLOCK_PHASE(4, 3, 10); pcr->ic_version = rtl8411_get_ic_version(pcr); - pcr->sd_pull_ctl_enable_tbl = rtl8411_sd_pull_ctl_enable_tbl; - pcr->sd_pull_ctl_disable_tbl = rtl8411_sd_pull_ctl_disable_tbl; - pcr->ms_pull_ctl_enable_tbl = rtl8411_ms_pull_ctl_enable_tbl; - pcr->ms_pull_ctl_disable_tbl = rtl8411_ms_pull_ctl_disable_tbl; +} + +void rtl8411_init_params(struct rtsx_pcr *pcr) +{ + /* Fill in common parameters. */ + rtl84xx_generic_params(pcr); + + /* Device Ops variation. */ + pcr->ops->fetch_vendor_settings = rtl8411_fetch_vendor_settings; + pcr->ops->extra_init_hw = rtl8411_extra_init_hw; + + pcr->rx_initial_phase = SET_CLOCK_PHASE(4, 3, 10); + + set_pull_ctrl_tables(rtl8411); } void rtl8411b_init_params(struct rtsx_pcr *pcr) { - pcr->extra_caps = EXTRA_CAPS_SD_SDR50 | EXTRA_CAPS_SD_SDR104; - pcr->num_slots = 2; - pcr->ops = &rtl8411b_pcr_ops; + /* Fill in common parameters. */ + rtl84xx_generic_params(pcr); + + /* Device Ops variation. */ + pcr->ops->fetch_vendor_settings = rtl8411b_fetch_vendor_settings; + pcr->ops->extra_init_hw = rtl8411b_extra_init_hw; - pcr->flags = 0; - pcr->card_drive_sel = RTL8411_CARD_DRIVE_DEFAULT; - pcr->sd30_drive_sel_1v8 = DRIVER_TYPE_B; - pcr->sd30_drive_sel_3v3 = DRIVER_TYPE_D; - pcr->aspm_en = ASPM_L1_EN; pcr->tx_initial_phase = SET_CLOCK_PHASE(23, 7, 14); pcr->rx_initial_phase = SET_CLOCK_PHASE(4, 3, 10); - pcr->ic_version = rtl8411_get_ic_version(pcr); - - if (rtl8411b_is_qfn48(pcr)) { - pcr->sd_pull_ctl_enable_tbl = - rtl8411b_qfn48_sd_pull_ctl_enable_tbl; - pcr->sd_pull_ctl_disable_tbl = - rtl8411b_qfn48_sd_pull_ctl_disable_tbl; - pcr->ms_pull_ctl_enable_tbl = - rtl8411b_qfn48_ms_pull_ctl_enable_tbl; - pcr->ms_pull_ctl_disable_tbl = - rtl8411b_qfn48_ms_pull_ctl_disable_tbl; - } else { - pcr->sd_pull_ctl_enable_tbl = - rtl8411b_qfn64_sd_pull_ctl_enable_tbl; - pcr->sd_pull_ctl_disable_tbl = - rtl8411b_qfn64_sd_pull_ctl_disable_tbl; - pcr->ms_pull_ctl_enable_tbl = - rtl8411b_qfn64_ms_pull_ctl_enable_tbl; - pcr->ms_pull_ctl_disable_tbl = - rtl8411b_qfn64_ms_pull_ctl_disable_tbl; - } + if (rtl8411b_is_qfn48(pcr)) + set_pull_ctrl_tables(rtl8411b_qfn48); + else + set_pull_ctrl_tables(rtl8411b_qfn64); } diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h index d1382df..f5f3ffc 100644 --- a/include/linux/mfd/rtsx_pci.h +++ b/include/linux/mfd/rtsx_pci.h @@ -855,7 +855,7 @@ struct rtsx_pcr { const u32 *ms_pull_ctl_enable_tbl; const u32 *ms_pull_ctl_disable_tbl; - const struct pcr_ops *ops; + struct pcr_ops *ops; enum PDEV_STAT state; int num_slots;