{"id":638514,"url":"http://patchwork.ozlabs.org/api/patches/638514/?format=json","web_url":"http://patchwork.ozlabs.org/project/rtc-linux/patch/1466493770-11895-6-git-send-email-andrew.smirnov@gmail.com/","project":{"id":9,"url":"http://patchwork.ozlabs.org/api/projects/9/?format=json","name":"Linux RTC development","link_name":"rtc-linux","list_id":"linux-rtc.vger.kernel.org","list_email":"linux-rtc@vger.kernel.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1466493770-11895-6-git-send-email-andrew.smirnov@gmail.com>","list_archive_url":null,"date":"2016-06-21T07:22:40","name":"[v2,07/17] RTC: ds1307: Move chip configuration into a separate routine","commit_ref":null,"pull_url":null,"state":"rejected","archived":false,"hash":"f686bce43aef5189865eb68085a9590fb2c7f63d","submitter":{"id":67013,"url":"http://patchwork.ozlabs.org/api/people/67013/?format=json","name":"Andrey Smirnov","email":"andrew.smirnov@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/rtc-linux/patch/1466493770-11895-6-git-send-email-andrew.smirnov@gmail.com/mbox/","series":[],"comments":"http://patchwork.ozlabs.org/api/patches/638514/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/638514/checks/","tags":{},"related":[],"headers":{"Return-Path":"<rtc-linux+bncBDKOBWPM5ABRBWOWUO5QKGQE33LHVFQ@googlegroups.com>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Received":["from mail-vk0-x23f.google.com (mail-vk0-x23f.google.com\n\t[IPv6:2607:f8b0:400c:c05::23f])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3rYfMZ6FM2z9t0V\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 21 Jun 2016 17:23:06 +1000 (AEST)","by mail-vk0-x23f.google.com with SMTP id c127sf2927934vkb.0\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 21 Jun 2016 00:23:06 -0700 (PDT)","by 10.157.52.137 with SMTP id g9ls3125337otc.41.gmail; Tue, 21 Jun\n\t2016 00:23:05 -0700 (PDT)","from mail-pa0-x241.google.com (mail-pa0-x241.google.com.\n\t[2607:f8b0:400e:c03::241]) by gmr-mx.google.com with ESMTPS id\n\tc11si5951032pfc.2.2016.06.21.00.23.04\n\tfor <rtc-linux@googlegroups.com>\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tTue, 21 Jun 2016 00:23:04 -0700 (PDT)","by mail-pa0-x241.google.com with SMTP id us13so739156pab.1\n\tfor <rtc-linux@googlegroups.com>;\n\tTue, 21 Jun 2016 00:23:04 -0700 (PDT)","from squirtle.localdomain.localdomain\n\t(c-73-225-163-254.hsd1.wa.comcast.net. [73.225.163.254])\n\tby smtp.gmail.com with ESMTPSA id\n\tp187sm19452396pfg.67.2016.06.21.00.23.03\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tTue, 21 Jun 2016 00:23:04 -0700 (PDT)"],"Authentication-Results":"ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=googlegroups.com header.i=@googlegroups.com\n\theader.b=ACX/OfPO; dkim=pass (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com header.b=tR5Nwgx+;\n\tdkim-atps=neutral","DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=googlegroups.com; s=20120806;\n\th=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:x-original-sender:x-original-authentication-results\n\t:reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group\n\t:list-post:list-help:list-archive:list-subscribe:list-unsubscribe;\n\tbh=fE0QzQXMgDoxxSi5I0q/phXDmnx92URzzHCNE5Mwj/g=;\n\tb=ACX/OfPOq9bov7WdMSFPjqaCEjFairjh+DKtMTF5uzVh+TnoFOJW3YyHxHfkBf2ORL\n\t7U+xH9i+gN1EyBxdIJOsqmsGnRDyzPcvfExm8nrII7LLWAkmHABQEVXNyUzGN3epNpjF\n\tEF85WIj0RokMoYtRQswhs8lRddCph0D2xCXzeq6wkSx3+yY897FeWz6hA2qtml2M0/pq\n\tqsoUaJBl0+ZyFiTdOWXiZc9+4MHNKV9N0dXQI+5Erp3r3e875RDh4y9TLKdPKi7ybQZ7\n\tilOnSYXqf/ebGVKUvUSEvYdU7ALZCLV8c1ggn0BpYUHRpGQ13koBFAHNzFz4gLO51xQZ\n\tRcRA==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=gmail.com; s=20120113;\n\th=mime-version:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:x-original-sender:x-original-authentication-results\n\t:reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group\n\t:list-post:list-help:list-archive:list-subscribe:list-unsubscribe;\n\tbh=fE0QzQXMgDoxxSi5I0q/phXDmnx92URzzHCNE5Mwj/g=;\n\tb=tR5Nwgx+scYdSYQEpxJaY4Ehcmu/laWoY1x2Y0XJTznDwcZCWN1nNTjnEPG4zYQjos\n\tdkMIs/e6okVKX0cL6ncLxT0nrjgcffAUij8f9uHQVkA134QhwFXPiVkkGIZtLHzLja3P\n\toc18R48QNc9UMTiH5cQcdfoJIx++37AVd5UcaYlNsmmLh6sr/NznIIMsQ/4YVeDWrtSz\n\tcdp+oZEkLa9PqhVHJgOQABQf5VdK4fbSuUQRUhyVPZ7Tu5Bh9EO9avobE3bwNEk9kmBb\n\tDpamPcLR0vzqp+hFKcUKkjc751xp50zTFEVmE2wIFutO11pllIqNlJGv8Zpcs9nwV4UD\n\tycPA=="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20130820;\n\th=sender:x-gm-message-state:mime-version:from:to:cc:subject:date\n\t:message-id:in-reply-to:references:x-original-sender\n\t:x-original-authentication-results:reply-to:precedence:mailing-list\n\t:list-id:x-spam-checked-in-group:list-post:list-help:list-archive\n\t:list-subscribe:list-unsubscribe;\n\tbh=fE0QzQXMgDoxxSi5I0q/phXDmnx92URzzHCNE5Mwj/g=;\n\tb=WYxuabHzxL9wdcwUPIe0X6kxh2kj4B+VwbRbsnNNvHsXL2FOGHx2v7jskltHmi6dFu\n\tmCphJDkq9EVy+WjZfbOaQuy25oa7tN5wTf/UyZIroPJ9xSJbdUmeFy7WrwbUIuLrfDNJ\n\tf11brC+0SLeofIBvmbQipUVWeYBzLhlU4mdMHx9KPEzFXbLdf0hIJUUmdMt9blT17ogE\n\th4vri2G/i7ilT9gTJ3JOlR2TFOqF87I6Q4dIOkM6Ub5qQJK7hyroZVQXhull5SiqL9Cz\n\tQguMilEyCgw9Wys2t1s3T2YsPCyoJmR0/JqOLSZIEgJX6rLVJUixbS2m3x5gIbiTspjI\n\tL03Q==","Sender":"rtc-linux@googlegroups.com","X-Gm-Message-State":"ALyK8tKn4ngfPzmA4INJR4frdzWoPYu6+kIoL/N0LwNKdb+vEZdS1uo4RijAuzYjniy32g==","X-Received":["by 10.157.34.202 with SMTP id y68mr607758ota.4.1466493785233;\n\tTue, 21 Jun 2016 00:23:05 -0700 (PDT)","by 10.237.35.61 with SMTP id h58mr18439735qtc.3.1466493785031;\n\tTue, 21 Jun 2016 00:23:05 -0700 (PDT)","by 10.66.222.98 with SMTP id ql2mr26612657pac.137.1466493784609; \n\tTue, 21 Jun 2016 00:23:04 -0700 (PDT)"],"MIME-Version":"1.0","X-BeenThere":"rtc-linux@googlegroups.com","Received-SPF":"pass (google.com: domain of andrew.smirnov@gmail.com\n\tdesignates 2607:f8b0:400e:c03::241 as permitted sender)\n\tclient-ip=2607:f8b0:400e:c03::241; ","From":"Andrey Smirnov <andrew.smirnov@gmail.com>","To":"rtc-linux@googlegroups.com","Cc":"Andrey Smirnov <andrew.smirnov@gmail.com>,\n\tAlessandro Zummo <a.zummo@towertech.it>,\n\tAlexandre Belloni <alexandre.belloni@free-electrons.com>,\n\tlinux-kernel@vger.kernel.org, cphealy@gmail.com","Subject":"[rtc-linux] [PATCH v2 07/17] RTC: ds1307: Move chip configuration\n\tinto a separate routine","Date":"Tue, 21 Jun 2016 00:22:40 -0700","Message-Id":"<1466493770-11895-6-git-send-email-andrew.smirnov@gmail.com>","X-Mailer":"git-send-email 2.5.5","In-Reply-To":"<1466493770-11895-1-git-send-email-andrew.smirnov@gmail.com>","References":"<1466493770-11895-1-git-send-email-andrew.smirnov@gmail.com>","X-Original-Sender":"andrew.smirnov@gmail.com","X-Original-Authentication-Results":"gmr-mx.google.com;       dkim=pass\n\theader.i=@gmail.com;       spf=pass (google.com: domain of\n\tandrew.smirnov@gmail.com designates 2607:f8b0:400e:c03::241 as\n\tpermitted\n\tsender) smtp.mailfrom=andrew.smirnov@gmail.com; dmarc=pass (p=NONE\n\tdis=NONE) header.from=gmail.com","Reply-To":"rtc-linux@googlegroups.com","Content-Type":"text/plain; charset=UTF-8","Precedence":"list","Mailing-list":"list rtc-linux@googlegroups.com;\n\tcontact rtc-linux+owners@googlegroups.com","List-ID":"<rtc-linux.googlegroups.com>","X-Spam-Checked-In-Group":"rtc-linux@googlegroups.com","X-Google-Group-Id":"712029733259","List-Post":"<https://groups.google.com/group/rtc-linux/post>,\n\t<mailto:rtc-linux@googlegroups.com>","List-Help":"<https://groups.google.com/support/>,\n\t<mailto:rtc-linux+help@googlegroups.com>","List-Archive":"<https://groups.google.com/group/rtc-linux","List-Subscribe":"<https://groups.google.com/group/rtc-linux/subscribe>,\n\t<mailto:rtc-linux+subscribe@googlegroups.com>","List-Unsubscribe":"<mailto:googlegroups-manage+712029733259+unsubscribe@googlegroups.com>,\n\t<https://groups.google.com/group/rtc-linux/subscribe>"},"content":"Move chip configuration into a separate routine to improve readablity of\nthe code.\n\nSigned-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>\n---\n drivers/rtc/rtc-ds1307.c | 172 ++++++++++++++++++++++++++---------------------\n 1 file changed, 97 insertions(+), 75 deletions(-)","diff":"diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c\nindex ccfaba4..4fa09dc 100644\n--- a/drivers/rtc/rtc-ds1307.c\n+++ b/drivers/rtc/rtc-ds1307.c\n@@ -1271,74 +1271,32 @@ static bool ds1307_want_irq(const struct ds1307 *ds1307,\n \treturn false;\n }\n \n-static int ds1307_probe(struct i2c_client *client,\n-\t\t\tconst struct i2c_device_id *id)\n+static int ds1307_chip_configure(struct ds1307 *ds1307)\n {\n-\tstruct ds1307\t\t*ds1307;\n-\tint\t\t\terr = -ENODEV;\n-\tint\t\t\ttmp;\n-\tstruct chip_desc\t*chip = &chips[id->driver_data];\n-\tstruct i2c_adapter\t*adapter = to_i2c_adapter(client->dev.parent);\n-\tunsigned char\t\t*buf;\n-\tstruct ds1307_platform_data *pdata = dev_get_platdata(&client->dev);\n-\tirq_handler_t\tirq_handler = ds1307_irq;\n-\n-\tstatic const int\tbbsqi_bitpos[] = {\n-\t\t[ds_1337] = 0,\n-\t\t[ds_1341] = 0,\n-\t\t[ds_1339] = DS1339_BIT_BBSQI,\n-\t\t[ds_3231] = DS3231_BIT_BBSQW,\n-\t};\n-\tconst struct rtc_class_ops *rtc_ops = &ds13xx_rtc_ops;\n-\n-\tif (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)\n-\t    && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK))\n-\t\treturn -EIO;\n-\n-\tds1307 = devm_kzalloc(&client->dev, sizeof(struct ds1307), GFP_KERNEL);\n-\tif (!ds1307)\n-\t\treturn -ENOMEM;\n-\n-\ti2c_set_clientdata(client, ds1307);\n-\n-\tds1307->client\t= client;\n-\tds1307->type\t= id->driver_data;\n-\n-\tif (!pdata && client->dev.of_node)\n-\t\tds1307_trickle_of_init(client, chip);\n-\telse if (pdata && pdata->trickle_charger_setup)\n-\t\tchip->trickle_charger_setup = pdata->trickle_charger_setup;\n-\n-\tif (chip->trickle_charger_setup && chip->trickle_charger_reg) {\n-\t\tdev_dbg(&client->dev, \"writing trickle charger info 0x%x to 0x%x\\n\",\n-\t\t    DS13XX_TRICKLE_CHARGER_MAGIC | chip->trickle_charger_setup,\n-\t\t    chip->trickle_charger_reg);\n-\t\ti2c_smbus_write_byte_data(client, chip->trickle_charger_reg,\n-\t\t    DS13XX_TRICKLE_CHARGER_MAGIC |\n-\t\t    chip->trickle_charger_setup);\n-\t}\n+\tint tmp;\n+\tunsigned char *buf;\n+\tstruct i2c_client *client = ds1307->client;\n \n \tbuf = ds1307->regs;\n-\tif (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) {\n-\t\tds1307->read_block_data = ds1307_native_smbus_read_block_data;\n-\t\tds1307->write_block_data = ds1307_native_smbus_write_block_data;\n-\t} else {\n-\t\tds1307->read_block_data = ds1307_read_block_data;\n-\t\tds1307->write_block_data = ds1307_write_block_data;\n-\t}\n \n \tswitch (ds1307->type) {\n \tcase ds_1337:\n \tcase ds_1339:\n \tcase ds_3231:\n-\tcase ds_1341:\n+\tcase ds_1341: {\n+\t\tstatic const int bbsqi_bitpos[] = {\n+\t\t\t[ds_1337] = 0,\n+\t\t\t[ds_1341] = 0,\n+\t\t\t[ds_1339] = DS1339_BIT_BBSQI,\n+\t\t\t[ds_3231] = DS3231_BIT_BBSQW,\n+\t\t};\n+\n \t\t/* get registers that the \"rtc\" read below won't read... */\n-\t\ttmp = ds1307->read_block_data(ds1307->client,\n-\t\t\t\tDS1337_REG_CONTROL, 2, buf);\n+\t\ttmp = ds1307->read_block_data(client,\n+\t\t\t\t\t      DS1337_REG_CONTROL, 2, buf);\n \t\tif (tmp != 2) {\n-\t\t\tdev_dbg(&client->dev, \"read error %d\\n\", tmp);\n-\t\t\terr = -EIO;\n-\t\t\tgoto exit;\n+\t\t\tdev_dbg(&ds1307->client->dev, \"read error %d\\n\", tmp);\n+\t\t\treturn -EIO;\n \t\t}\n \n \t\t/* oscillator off?  turn it on, so clock can tick. */\n@@ -1366,7 +1324,8 @@ static int ds1307_probe(struct i2c_client *client,\n \t\t\t * Write status register. Control register\n \t\t\t * would be set by the code below\n \t\t\t */\n-\t\t\ti2c_smbus_write_byte_data(client, DS1337_REG_STATUS,\n+\t\t\ti2c_smbus_write_byte_data(client,\n+\t\t\t\t\t\t  DS1337_REG_STATUS,\n \t\t\t\t\t\t  ds1307->regs[1]);\n \t\t}\n \n@@ -1379,24 +1338,26 @@ static int ds1307_probe(struct i2c_client *client,\n \t\t\t| bbsqi_bitpos[ds1307->type];\n \t\tds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE);\n \n-\t\ti2c_smbus_write_byte_data(client, DS1337_REG_CONTROL,\n-\t\t\t\t\t\t\tds1307->regs[0]);\n+\t\ti2c_smbus_write_byte_data(client,\n+\t\t\t\t\t  DS1337_REG_CONTROL,\n+\t\t\t\t\t  ds1307->regs[0]);\n \n \t\t/* oscillator fault?  clear flag, and warn */\n \t\tif (ds1307->regs[1] & DS1337_BIT_OSF) {\n-\t\t\ti2c_smbus_write_byte_data(client, DS1337_REG_STATUS,\n-\t\t\t\tds1307->regs[1] & ~DS1337_BIT_OSF);\n-\t\t\tdev_warn(&client->dev, \"SET TIME!\\n\");\n+\t\t\ti2c_smbus_write_byte_data(client,\n+\t\t\t\t\t\t  DS1337_REG_STATUS,\n+\t\t\t\t\t\t  ds1307->regs[1] & ~DS1337_BIT_OSF);\n+\t\t\tdev_warn(&ds1307->client->dev, \"SET TIME!\\n\");\n \t\t}\n \t\tbreak;\n-\n+\t}\n \tcase rx_8025:\n-\t\ttmp = i2c_smbus_read_i2c_block_data(ds1307->client,\n-\t\t\t\tRX8025_REG_CTRL1 << 4 | 0x08, 2, buf);\n+\t\ttmp = i2c_smbus_read_i2c_block_data(client,\n+\t\t\t\t\t\t    RX8025_REG_CTRL1 << 4 | 0x08,\n+\t\t\t\t\t\t    2, buf);\n \t\tif (tmp != 2) {\n \t\t\tdev_dbg(&client->dev, \"read error %d\\n\", tmp);\n-\t\t\terr = -EIO;\n-\t\t\tgoto exit;\n+\t\t\treturn -EIO;\n \t\t}\n \n \t\t/* oscillator off?  turn it on, so clock can tick. */\n@@ -1432,15 +1393,14 @@ static int ds1307_probe(struct i2c_client *client,\n \t\t\t/* switch to 24 hour mode */\n \t\t\ti2c_smbus_write_byte_data(client,\n \t\t\t\t\t\t  RX8025_REG_CTRL1 << 4 | 0x08,\n-\t\t\t\t\t\t  ds1307->regs[0] |\n-\t\t\t\t\t\t  RX8025_BIT_2412);\n+\t\t\t\t\t\t  ds1307->regs[0] | RX8025_BIT_2412);\n \n-\t\t\ttmp = i2c_smbus_read_i2c_block_data(ds1307->client,\n-\t\t\t\t\tRX8025_REG_CTRL1 << 4 | 0x08, 2, buf);\n+\t\t\ttmp = i2c_smbus_read_i2c_block_data(client,\n+\t\t\t\t\t\t\t    RX8025_REG_CTRL1 << 4 | 0x08,\n+\t\t\t\t\t\t\t    2, buf);\n \t\t\tif (tmp != 2) {\n \t\t\t\tdev_dbg(&client->dev, \"read error %d\\n\", tmp);\n-\t\t\t\terr = -EIO;\n-\t\t\t\tgoto exit;\n+\t\t\t\treturn -EIO;\n \t\t\t}\n \n \t\t\t/* correct hour */\n@@ -1455,6 +1415,68 @@ static int ds1307_probe(struct i2c_client *client,\n \t\t\t\t\t\t  hour);\n \t\t}\n \t\tbreak;\n+\tdefault:\n+\t\tbreak;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int ds1307_probe(struct i2c_client *client,\n+\t\t\tconst struct i2c_device_id *id)\n+{\n+\tstruct ds1307\t\t*ds1307;\n+\tint\t\t\terr = -ENODEV;\n+\tint\t\t\ttmp;\n+\tstruct chip_desc\t*chip = &chips[id->driver_data];\n+\tstruct i2c_adapter\t*adapter = to_i2c_adapter(client->dev.parent);\n+\tunsigned char\t\t*buf;\n+\tstruct ds1307_platform_data *pdata = dev_get_platdata(&client->dev);\n+\tirq_handler_t\tirq_handler = ds1307_irq;\n+\n+\tconst struct rtc_class_ops *rtc_ops = &ds13xx_rtc_ops;\n+\n+\tif (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)\n+\t    && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK))\n+\t\treturn -EIO;\n+\n+\tds1307 = devm_kzalloc(&client->dev, sizeof(struct ds1307), GFP_KERNEL);\n+\tif (!ds1307)\n+\t\treturn -ENOMEM;\n+\n+\ti2c_set_clientdata(client, ds1307);\n+\n+\tds1307->client\t= client;\n+\tds1307->type\t= id->driver_data;\n+\n+\tif (!pdata && client->dev.of_node)\n+\t\tds1307_trickle_of_init(client, chip);\n+\telse if (pdata && pdata->trickle_charger_setup)\n+\t\tchip->trickle_charger_setup = pdata->trickle_charger_setup;\n+\n+\tif (chip->trickle_charger_setup && chip->trickle_charger_reg) {\n+\t\tdev_dbg(&client->dev, \"writing trickle charger info 0x%x to 0x%x\\n\",\n+\t\t    DS13XX_TRICKLE_CHARGER_MAGIC | chip->trickle_charger_setup,\n+\t\t    chip->trickle_charger_reg);\n+\t\ti2c_smbus_write_byte_data(client, chip->trickle_charger_reg,\n+\t\t    DS13XX_TRICKLE_CHARGER_MAGIC |\n+\t\t    chip->trickle_charger_setup);\n+\t}\n+\n+\tbuf = ds1307->regs;\n+\tif (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) {\n+\t\tds1307->read_block_data = ds1307_native_smbus_read_block_data;\n+\t\tds1307->write_block_data = ds1307_native_smbus_write_block_data;\n+\t} else {\n+\t\tds1307->read_block_data = ds1307_read_block_data;\n+\t\tds1307->write_block_data = ds1307_write_block_data;\n+\t}\n+\n+\terr = ds1307_chip_configure(ds1307);\n+\tif (err < 0)\n+\t\treturn err;\n+\n+\tswitch (ds1307->type) {\n \tcase ds_1388:\n \t\tds1307->offset = 1; /* Seconds starts at 1 */\n \t\tbreak;\n","prefixes":["v2","07/17"]}