linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurentp@cse-semaphore.com>
To: linuxppc-dev@ozlabs.org
Cc: linux-kernel@vger.kernel.org, i2c@lm-sensors.org
Subject: Re: [PATCH 19 5/5] Convert pfc8563 i2c driver from old style to new style
Date: Thu, 10 Apr 2008 11:14:15 +0200	[thread overview]
Message-ID: <200804101114.18325.laurentp@cse-semaphore.com> (raw)
In-Reply-To: <20080112024748.7023.90680.stgit@terra.home>

[-- Attachment #1: Type: text/plain, Size: 3996 bytes --]

Hi Jon,

On Saturday 12 January 2008 03:47, Jon Smirl wrote:
> Convert pfc8563 i2c driver from old style to new style. The
> driver is also modified to support device tree names via the
> i2c mod alias mechanism.

The patch breaks the pfc8563 driver.

The old style driver allocated memory for a pcf8563 structure that
encapsulated an i2c_client instance. Various functions use container_of
on an i2c_client instance to get a pointer to the pcf8563 structure.

The new style driver gets rid of the pcf8563 structure allocation, as the
i2c_client structure is now allocated by I2C code.

Here is an incremental patch that fixes the issue.

From 1eac5a8e10e085c3a77c6ba7ed9dac9a39024915 Mon Sep 17 00:00:00 2001
From: Laurent Pinchart <laurentp@cse-semaphore.com>
Date: Thu, 10 Apr 2008 11:12:25 +0200
Subject: [PATCH] Fix pcf8563 breakage introduced by the conversion from old style to new style

The old style I2C driver used to allocate a pcf8563 instance that encapsulated
an i2c_client instance. The i2c_client instance is now allocated by I2C core.

This patch fixes the driver by storing the pcf8563 instance in the I2C client
data field.

Signed-off-by: Laurent Pinchart <laurentp@cse-semaphore.com>
---
 drivers/rtc/rtc-pcf8563.c |   29 ++++++++++++++++++-----------
 1 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index e1ea2a0..7aab24e 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -50,7 +50,7 @@
 #define PCF8563_MO_C		0x80 /* century */
 
 struct pcf8563 {
-	struct i2c_client client;
+	struct rtc_device *rtc;
 	/*
 	 * The meaning of MO_C bit varies by the chip type.
 	 * From PCF8563 datasheet: this bit is toggled when the years
@@ -74,7 +74,7 @@ struct pcf8563 {
  */
 static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
 {
-	struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
+	struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
 	unsigned char buf[13] = { PCF8563_REG_ST1 };
 
 	struct i2c_msg msgs[] = {
@@ -131,7 +131,7 @@ static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
 
 static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
 {
-	struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client);
+	struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
 	int i, err;
 	unsigned char buf[9];
 
@@ -252,10 +252,10 @@ static const struct rtc_class_ops pcf8563_rtc_ops = {
 
 static int pcf8563_remove(struct i2c_client *client)
 {
-	struct rtc_device *rtc = i2c_get_clientdata(client);
+	struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
 
-	if (rtc)
-		rtc_device_unregister(rtc);
+	if (pcf8563->rtc)
+		rtc_device_unregister(pcf8563->rtc);
 
 	return 0;
 }
@@ -274,26 +274,33 @@ static struct i2c_driver pcf8563_driver = {
 		.name	= "rtc-pcf8563",
 	},
 	.id		= I2C_DRIVERID_PCF8563,
-	.probe = &pcf8563_probe,
-	.remove = &pcf8563_remove,
+	.probe		= &pcf8563_probe,
+	.remove		= &pcf8563_remove,
 	.id_table	= pcf8563_id,
 };
 
 static int pcf8563_probe(struct i2c_client *client, const struct i2c_device_id *id)
 {
-	int result;
+	struct pcf8563 *pcf8563;
 	struct rtc_device *rtc;
+	int result;
 
 	result = pcf8563_validate_client(client);
 	if (result)
 		return result;
 
+	if ((pcf8563 = kzalloc(sizeof(*pcf8563), GFP_KERNEL)) == NULL)
+		return -ENOMEM;
+
 	rtc = rtc_device_register(pcf8563_driver.driver.name, &client->dev,
 				&pcf8563_rtc_ops, THIS_MODULE);
-	if (IS_ERR(rtc))
+	if (IS_ERR(rtc)) {
+		kfree(pcf8563);
 		return PTR_ERR(rtc);
+	}
 
-	i2c_set_clientdata(client, rtc);
+	pcf8563->rtc = rtc;
+	i2c_set_clientdata(client, pcf8563);
 
 	return 0;
 }
-- 
1.5.0

-- 
Laurent Pinchart
CSE Semaphore Belgium

Chaussee de Bruxelles, 732A
B-1410 Waterloo
Belgium

T +32 (2) 387 42 59
F +32 (2) 387 42 75

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

      reply	other threads:[~2008-04-10  9:14 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-12  2:47 [PATCH 19 0/5] Version 18, series to add device tree naming to i2c Jon Smirl
2008-01-12  2:47 ` [PATCH 19 1/5] Implement module aliasing for i2c to translate from device tree names Jon Smirl
2008-01-12  3:00   ` [i2c] " Jon Smirl
2008-01-12  3:47     ` Stephen Rothwell
2008-01-12  2:47 ` [PATCH 19 2/5] Modify several rtc drivers to use the alias names list property of i2c Jon Smirl
2008-01-12  2:47 ` [PATCH 19 3/5] Clean up error returns Jon Smirl
2008-01-20 11:07   ` [i2c] " Jean Delvare
2008-01-20 15:18     ` Jon Smirl
2008-01-20 15:39       ` Jon Smirl
2008-01-21 16:10         ` Jean Delvare
2008-01-21 23:04           ` Benjamin Herrenschmidt
2008-01-21 23:06       ` Benjamin Herrenschmidt
2008-01-12  2:47 ` [PATCH 19 4/5] Convert PowerPC MPC i2c to of_platform_driver from platform_driver Jon Smirl
2008-01-12  4:07   ` Stephen Rothwell
2008-01-12  2:47 ` [PATCH 19 5/5] Convert pfc8563 i2c driver from old style to new style Jon Smirl
2008-04-10  9:14   ` Laurent Pinchart [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200804101114.18325.laurentp@cse-semaphore.com \
    --to=laurentp@cse-semaphore.com \
    --cc=i2c@lm-sensors.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).