From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752964AbbC0VIL (ORCPT ); Fri, 27 Mar 2015 17:08:11 -0400 Received: from mail-bn1on0135.outbound.protection.outlook.com ([157.56.110.135]:48341 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752767AbbC0VHs (ORCPT ); Fri, 27 Mar 2015 17:07:48 -0400 From: "J. German Rivera" To: , , , CC: , , , , , , , , , "J. German Rivera" Subject: [PATCH 3/6] staging: fsl-mc: Bind/unbind driver when MC object is plugged/unplugged Date: Fri, 27 Mar 2015 16:01:06 -0500 Message-ID: <1427490069-3142-4-git-send-email-German.Rivera@freescale.com> X-Mailer: git-send-email 2.3.3 In-Reply-To: <1427490069-3142-1-git-send-email-German.Rivera@freescale.com> References: <1427490069-3142-1-git-send-email-German.Rivera@freescale.com> X-EOPAttributedMessage: 0 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=German.Rivera@freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;BMV:1;SFV:NSPM;SFS:(10019020)(6009001)(339900001)(189002)(199003)(46102003)(36756003)(105606002)(86362001)(48376002)(19580395003)(50466002)(85426001)(19580405001)(106466001)(77096005)(76176999)(50986999)(2950100001)(77156002)(5890100001)(87936001)(92566002)(50226001)(2201001)(229853001)(47776003)(62966003);DIR:OUT;SFP:1102;SCL:1;SRVR:DM2PR03MB509;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;MLV:sfv;MX:1;A:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR03MB509; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5002010)(5005006);SRVR:DM2PR03MB509;BCL:0;PCL:0;RULEID:;SRVR:DM2PR03MB509; X-Forefront-PRVS: 0528942FD8 X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2015 21:07:42.2509 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR03MB509 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: J. German Rivera --- drivers/staging/fsl-mc/bus/dprc-driver.c | 39 +++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c b/drivers/staging/fsl-mc/bus/dprc-driver.c index f02e5e4..9568eea 100644 --- a/drivers/staging/fsl-mc/bus/dprc-driver.c +++ b/drivers/staging/fsl-mc/bus/dprc-driver.c @@ -112,6 +112,41 @@ static struct fsl_mc_device *fsl_mc_device_lookup(struct dprc_obj_desc } /** + * check_plugged_state_change - Check change in an MC object's plugged state + * + * @mc_dev: pointer to the fsl-mc device for a given MC object + * @obj_desc: pointer to the MC object's descriptor in the MC + * + * If the plugged state has changed from unplugged to plugged, the fsl-mc + * device is bound to the corresponding device driver. + * If the plugged state has changed from plugged to unplugged, the fsl-mc + * device is unbound from the corresponding device driver. + */ +static void check_plugged_state_change(struct fsl_mc_device *mc_dev, + struct dprc_obj_desc *obj_desc) +{ + int error; + uint32_t plugged_flag_at_mc = + (obj_desc->state & DPRC_OBJ_STATE_PLUGGED); + + if (plugged_flag_at_mc != + (mc_dev->obj_desc.state & DPRC_OBJ_STATE_PLUGGED)) { + if (plugged_flag_at_mc) { + mc_dev->obj_desc.state |= DPRC_OBJ_STATE_PLUGGED; + error = device_attach(&mc_dev->dev); + if (error < 0) { + dev_err(&mc_dev->dev, + "device_attach() failed: %d\n", + error); + } + } else { + mc_dev->obj_desc.state &= ~DPRC_OBJ_STATE_PLUGGED; + device_release_driver(&mc_dev->dev); + } + } +} + +/** * dprc_add_new_devices - Adds devices to the logical bus for a DPRC * * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object @@ -142,8 +177,10 @@ static void dprc_add_new_devices(struct fsl_mc_device *mc_bus_dev, * Check if device is already known to Linux: */ child_dev = fsl_mc_device_lookup(obj_desc, mc_bus_dev); - if (child_dev) + if (child_dev) { + check_plugged_state_change(child_dev, obj_desc); continue; + } error = fsl_mc_device_add(obj_desc, mc_io, &mc_bus_dev->dev, &child_dev); -- 2.3.3