From patchwork Mon Dec 20 03:50:54 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Reilly X-Patchwork-Id: 419281 Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oBK3pNkl012519 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 20 Dec 2010 03:51:44 GMT Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1PUWmR-0000jp-MZ; Mon, 20 Dec 2010 03:51:23 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1PUWmQ-0000jL-6t for spi-devel-general@lists.sourceforge.net; Mon, 20 Dec 2010 03:51:22 +0000 Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of gmail.com designates 209.85.210.53 as permitted sender) client-ip=209.85.210.53; envelope-from=marc.reilly@gmail.com; helo=mail-pz0-f53.google.com; Received: from mail-pz0-f53.google.com ([209.85.210.53]) by sog-mx-3.v43.ch3.sourceforge.com with esmtp (Exim 4.72) id 1PUWmO-0006x9-LT for spi-devel-general@lists.sourceforge.net; Mon, 20 Dec 2010 03:51:22 +0000 Received: by mail-pz0-f53.google.com with SMTP id 37so703800pzk.12 for ; Sun, 19 Dec 2010 19:51:20 -0800 (PST) Received: by 10.142.97.15 with SMTP id u15mr2944229wfb.389.1292817080338; Sun, 19 Dec 2010 19:51:20 -0800 (PST) Received: from localhost.localdomain (220-244-174-13.static.tpgi.com.au [220.244.174.13]) by mx.google.com with ESMTPS id w14sm5156070wfd.18.2010.12.19.19.51.17 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 19 Dec 2010 19:51:19 -0800 (PST) From: Marc Reilly To: linux-arm-kernel@lists.infradead.org, u.kleine-koenig@pengutronix.de Subject: [PATCHv3 3/4] mc13xxx: Add i2c driver Date: Mon, 20 Dec 2010 14:50:54 +1100 Message-Id: <1292817055-17715-4-git-send-email-marc@cpdesign.com.au> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1292817055-17715-1-git-send-email-marc@cpdesign.com.au> References: <1292817055-17715-1-git-send-email-marc@cpdesign.com.au> X-Spam-Score: -0.9 (/) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain 0.0 FREEMAIL_FROM Sender email is freemail (marc.reilly[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 T_TO_NO_BRKTS_FREEMAIL T_TO_NO_BRKTS_FREEMAIL 0.6 AWL AWL: From: address is in the auto white-list X-Headers-End: 1PUWmO-0006x9-LT Cc: spi-devel-general@lists.sourceforge.net, w.sang@pengutronix.de, Marc Reilly , linux-i2c@vger.kernel.org X-BeenThere: spi-devel-general@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux SPI core/device drivers discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: spi-devel-general-bounces@lists.sourceforge.net X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Mon, 20 Dec 2010 03:51:44 +0000 (UTC) diff --git a/drivers/mfd/mc13xxx-i2c.c b/drivers/mfd/mc13xxx-i2c.c new file mode 100644 index 0000000..f7ceed8 --- /dev/null +++ b/drivers/mfd/mc13xxx-i2c.c @@ -0,0 +1,115 @@ +/* + * Copyright 2009-2010 Creative Product Design + * Marc Reilly marc@cpdesign.com.au + * + * + * 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 +#include + +static int mc13xxx_i2c_reg_read(struct mc13xxx *mc13xxx, unsigned int offset, + u32 *val) +{ + int ret; + unsigned char buf[3] = {0, 0, 0}; + + ret = i2c_smbus_read_i2c_block_data(mc13xxx->i2cclient, + offset, 3, buf); + *val = buf[0] << 16 | buf[1] << 8 | buf[2]; + + return ret == 3 ? 0 : ret; +} + +static int mc13xxx_i2c_reg_write(struct mc13xxx *mc13xxx, unsigned int offset, + u32 val) +{ + int ret; + unsigned char buf[3]; + + buf[0] = (val >> 16) & 0xff; + buf[1] = (val >> 8) & 0xff; + buf[2] = val & 0xff; + + ret = i2c_smbus_write_i2c_block_data(mc13xxx->i2cclient, + offset, 3, buf); + + return ret; +} + +static int mc13xxx_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct mc13xxx *mc13xxx; + struct mc13xxx_platform_data *pdata = dev_get_platdata(&client->dev); + int ret; + + mc13xxx = kzalloc(sizeof(*mc13xxx), GFP_KERNEL); + if (!mc13xxx) + return -ENOMEM; + + dev_set_drvdata(&client->dev, mc13xxx); + mc13xxx->dev = &client->dev; + mc13xxx->i2cclient = client; + mc13xxx->read_dev = mc13xxx_i2c_reg_read; + mc13xxx->write_dev = mc13xxx_i2c_reg_write; + + ret = mc13xxx_common_init(mc13xxx, pdata, client->irq); + + if (ret == 0 && (id->driver_data != mc13xxx->ictype)) + dev_warn(mc13xxx->dev, + "device id doesn't match auto detection!\n"); + + return ret; +} + +static int __devexit mc13xxx_i2c_remove(struct i2c_client *client) +{ + struct mc13xxx *mc13xxx = dev_get_drvdata(&client->dev); + + free_irq(client->irq, mc13xxx); + + mfd_remove_devices(&client->dev); + + kfree(mc13xxx); + + return 0; +} + +static const struct i2c_device_id mc13xxx_i2c_idtable[] = { + { "mc13892", MC13XXX_ID_MC13892}, + { } +}; + +static struct i2c_driver mc13xxx_i2c_driver = { + .driver = { + .owner = THIS_MODULE, + .name = "mc13xxx-i2c" + }, + .id_table = mc13xxx_i2c_idtable, + .probe = mc13xxx_i2c_probe, + .remove = __devexit_p(mc13xxx_i2c_remove), +}; + +static int __init mc13xxx_i2c_init(void) +{ + return i2c_add_driver(&mc13xxx_i2c_driver); +} +subsys_initcall(mc13xxx_i2c_init); + +static void __exit mc13xxx_i2c_exit(void) +{ + i2c_del_driver(&mc13xxx_i2c_driver); +} +module_exit(mc13xxx_i2c_exit); + +MODULE_DESCRIPTION("i2c driver for Freescale MC13XXX PMIC"); +MODULE_AUTHOR("Marc Reilly