linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Corbet <corbet@lwn.net>
To: linux-kernel@vger.kernel.org
Cc: Harald Welte <laforge@gnumonks.org>,
	Deepak Saxena <dsaxena@laptop.org>,
	linux-fbdev@vger.kernel.org, JosephChan@via.com.tw,
	ScottFang@viatech.com.cn,
	Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
Subject: [PATCH 05/13] viafb: Convert GPIO and i2c to the new indexed port ops
Date: Fri, 23 Apr 2010 21:28:05 +0000	[thread overview]
Message-ID: <1272058093-20914-6-git-send-email-corbet@lwn.net> (raw)
In-Reply-To: <1272058093-20914-1-git-send-email-corbet@lwn.net>

Also add low-level locking to the i2c driver.

Signed-off-by: Jonathan Corbet <corbet@lwn.net>
---
 drivers/video/via/via-core.c |    2 +-
 drivers/video/via/via-gpio.c |   14 ++++++------
 drivers/video/via/via_i2c.c  |   46 ++++++++++++++++++++++++++---------------
 drivers/video/via/via_i2c.h  |    2 +-
 4 files changed, 38 insertions(+), 26 deletions(-)

diff --git a/drivers/video/via/via-core.c b/drivers/video/via/via-core.c
index 00b9021..68f5756 100644
--- a/drivers/video/via/via-core.c
+++ b/drivers/video/via/via-core.c
@@ -219,7 +219,7 @@ static int __devinit via_pci_probe(struct pci_dev *pdev,
 	 * Create the I2C busses.  Bailing out on failure seems extreme,
 	 * but that's what the code did before.
 	 */
-	ret = viafb_create_i2c_busses(adap_configs);
+	ret = viafb_create_i2c_busses(&global_dev, adap_configs);
 	if (ret) {
 		via_fb_pci_remove(pdev);
 		return ret;
diff --git a/drivers/video/via/via-gpio.c b/drivers/video/via/via-gpio.c
index e119d21..6b36117 100644
--- a/drivers/video/via/via-gpio.c
+++ b/drivers/video/via/via-gpio.c
@@ -91,13 +91,13 @@ static void via_gpio_set(struct gpio_chip *chip, unsigned int nr,
 
 	spin_lock_irqsave(&cfg->vdev->reg_lock, flags);
 	gpio = cfg->active_gpios[nr];
-	reg = viafb_read_reg(VIASR, gpio->vg_port_index);
+	reg = via_read_reg(VIASR, gpio->vg_port_index);
 	reg |= 0x40 << gpio->vg_mask_shift;  /* output enable */
 	if (value)
 		reg |= 0x10 << gpio->vg_mask_shift;
 	else
 		reg &= ~(0x10 << gpio->vg_mask_shift);
-	viafb_write_reg(gpio->vg_port_index, VIASR, reg);
+	via_write_reg(VIASR, gpio->vg_port_index, reg);
 	spin_unlock_irqrestore(&cfg->vdev->reg_lock, flags);
 }
 
@@ -122,8 +122,8 @@ static int via_gpio_dir_input(struct gpio_chip *chip, unsigned int nr)
 
 	spin_lock_irqsave(&cfg->vdev->reg_lock, flags);
 	gpio = cfg->active_gpios[nr];
-	viafb_write_reg_mask(gpio->vg_port_index, VIASR, 0,
-			     0x40 << gpio->vg_mask_shift);
+	via_write_reg_mask(VIASR, gpio->vg_port_index, 0,
+			0x40 << gpio->vg_mask_shift);
 	spin_unlock_irqrestore(&cfg->vdev->reg_lock, flags);
 	return 0;
 }
@@ -139,7 +139,7 @@ static int via_gpio_get(struct gpio_chip *chip, unsigned int nr)
 
 	spin_lock_irqsave(&cfg->vdev->reg_lock, flags);
 	gpio = cfg->active_gpios[nr];
-	reg = viafb_read_reg(VIASR, gpio->vg_port_index);
+	reg = via_read_reg(VIASR, gpio->vg_port_index);
 	spin_unlock_irqrestore(&cfg->vdev->reg_lock, flags);
 	return reg & (0x04 << gpio->vg_mask_shift);
 }
@@ -164,12 +164,12 @@ static struct viafb_gpio_cfg gpio_config = {
  */
 static void viafb_gpio_enable(struct viafb_gpio *gpio)
 {
-	viafb_write_reg_mask(gpio->vg_port_index, VIASR, 0x02, 0x02);
+	via_write_reg_mask(VIASR, gpio->vg_port_index, 0x02, 0x02);
 }
 
 static void viafb_gpio_disable(struct viafb_gpio *gpio)
 {
-	viafb_write_reg_mask(gpio->vg_port_index, VIASR, 0, 0x02);
+	via_write_reg_mask(VIASR, gpio->vg_port_index, 0, 0x02);
 }
 
 
diff --git a/drivers/video/via/via_i2c.c b/drivers/video/via/via_i2c.c
index 6cb94a8..195110a 100644
--- a/drivers/video/via/via_i2c.c
+++ b/drivers/video/via/via_i2c.c
@@ -29,16 +29,18 @@
  */
 #define VIAFB_NUM_I2C		5
 static struct via_i2c_stuff via_i2c_par[VIAFB_NUM_I2C];
+struct viafb_dev *i2c_vdev;  /* Passed in from core */
 
 static void via_i2c_setscl(void *data, int state)
 {
 	u8 val;
 	struct via_port_cfg *adap_data = data;
+	unsigned long flags;
 
 	DEBUG_MSG(KERN_DEBUG "reading index 0x%02x from IO 0x%x\n",
 		adap_data->ioport_index, adap_data->io_port);
-	val = viafb_read_reg(adap_data->io_port,
-			     adap_data->ioport_index) & 0xF0;
+	spin_lock_irqsave(&i2c_vdev->reg_lock, flags);
+	val = via_read_reg(adap_data->io_port, adap_data->ioport_index) & 0xF0;
 	if (state)
 		val |= 0x20;
 	else
@@ -53,35 +55,44 @@ static void via_i2c_setscl(void *data, int state)
 	default:
 		DEBUG_MSG("viafb_i2c: specify wrong i2c type.\n");
 	}
-	viafb_write_reg(adap_data->ioport_index,
-			adap_data->io_port, val);
+	via_write_reg(adap_data->io_port, adap_data->ioport_index, val);
+	spin_unlock_irqrestore(&i2c_vdev->reg_lock, flags);
 }
 
 static int via_i2c_getscl(void *data)
 {
 	struct via_port_cfg *adap_data = data;
-
-	if (viafb_read_reg(adap_data->io_port, adap_data->ioport_index) & 0x08)
-		return 1;
-	return 0;
+	unsigned long flags;
+	int ret = 0;
+
+	spin_lock_irqsave(&i2c_vdev->reg_lock, flags);
+	if (via_read_reg(adap_data->io_port, adap_data->ioport_index) & 0x08)
+		ret = 1;
+	spin_unlock_irqrestore(&i2c_vdev->reg_lock, flags);
+	return ret;
 }
 
 static int via_i2c_getsda(void *data)
 {
 	struct via_port_cfg *adap_data = data;
-
-	if (viafb_read_reg(adap_data->io_port, adap_data->ioport_index) & 0x04)
-		return 1;
-	return 0;
+	unsigned long flags;
+	int ret = 0;
+
+	spin_lock_irqsave(&i2c_vdev->reg_lock, flags);
+	if (via_read_reg(adap_data->io_port, adap_data->ioport_index) & 0x04)
+		ret = 1;
+	spin_unlock_irqrestore(&i2c_vdev->reg_lock, flags);
+	return ret;
 }
 
 static void via_i2c_setsda(void *data, int state)
 {
 	u8 val;
 	struct via_port_cfg *adap_data = data;
+	unsigned long flags;
 
-	val = viafb_read_reg(adap_data->io_port,
-			     adap_data->ioport_index) & 0xF0;
+	spin_lock_irqsave(&i2c_vdev->reg_lock, flags);
+	val = via_read_reg(adap_data->io_port, adap_data->ioport_index) & 0xF0;
 	if (state)
 		val |= 0x10;
 	else
@@ -96,8 +107,8 @@ static void via_i2c_setsda(void *data, int state)
 	default:
 		DEBUG_MSG("viafb_i2c: specify wrong i2c type.\n");
 	}
-	viafb_write_reg(adap_data->ioport_index,
-			adap_data->io_port, val);
+	via_write_reg(adap_data->io_port, adap_data->ioport_index, val);
+	spin_unlock_irqrestore(&i2c_vdev->reg_lock, flags);
 }
 
 int viafb_i2c_readbyte(u8 adap, u8 slave_addr, u8 index, u8 *pdata)
@@ -176,10 +187,11 @@ static int create_i2c_bus(struct i2c_adapter *adapter,
 	return i2c_bit_add_bus(adapter);
 }
 
-int viafb_create_i2c_busses(struct via_port_cfg *configs)
+int viafb_create_i2c_busses(struct viafb_dev *dev, struct via_port_cfg *configs)
 {
 	int i, ret;
 
+	i2c_vdev = dev;
 	for (i = 0; i < VIAFB_NUM_PORTS; i++) {
 		struct via_port_cfg *adap_cfg = configs++;
 		struct via_i2c_stuff *i2c_stuff = &via_i2c_par[i];
diff --git a/drivers/video/via/via_i2c.h b/drivers/video/via/via_i2c.h
index 0093291..0685de9 100644
--- a/drivers/video/via/via_i2c.h
+++ b/drivers/video/via/via_i2c.h
@@ -36,7 +36,7 @@ int viafb_i2c_writebyte(u8 adap, u8 slave_addr, u8 index, u8 data);
 int viafb_i2c_readbytes(u8 adap, u8 slave_addr, u8 index, u8 *buff, int buff_len);
 
 struct viafb_par;
-int viafb_create_i2c_busses(struct via_port_cfg *cfg);
+int viafb_create_i2c_busses(struct viafb_dev *vdev, struct via_port_cfg *cfg);
 void viafb_delete_i2c_busses(void);
 struct i2c_adapter *viafb_find_adapter(enum viafb_i2c_adap which);
 #endif /* __VIA_I2C_H__ */
-- 
1.7.0.1


  parent reply	other threads:[~2010-04-23 21:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-23 21:28 [RFC] Second OLPC Viafb series Jonathan Corbet
2010-04-23 21:28 ` [PATCH 01/13] viafb: Move core stuff into via-core.c Jonathan Corbet
2010-04-23 21:28 ` [PATCH 02/13] viafb: Separate global and fb-specific data Jonathan Corbet
2010-04-23 21:28 ` [PATCH 03/13] viafb: add a driver for GPIO lines Jonathan Corbet
2010-04-23 21:28 ` [PATCH 04/13] viafb: package often used basic io functions Jonathan Corbet
2010-04-23 21:28 ` Jonathan Corbet [this message]
2010-04-23 21:28 ` [PATCH 06/13] viafb: Turn GPIO and i2c into proper platform devices Jonathan Corbet
2010-04-23 21:28 ` [PATCH 07/13] via: Do not attempt I/O on inactive I2C adapters Jonathan Corbet
2010-04-23 21:28 ` [PATCH 08/13] viafb: Introduce viafb_find_i2c_adapter() Jonathan Corbet
2010-04-23 21:28 ` [PATCH 09/13] via: Rationalize vt1636 detection Jonathan Corbet
2010-04-23 21:28 ` [PATCH 10/13] viafb: Add a simple interrupt management infrastructure Jonathan Corbet
2010-04-23 21:28 ` [PATCH 11/13] viafb: Add a simple VX855 DMA engine driver Jonathan Corbet
2010-04-23 21:28 ` [PATCH 12/13] viafb: Reserve framebuffer memory for the upcoming camera driver Jonathan Corbet
2010-04-23 21:28 ` [PATCH 13/13] viafb: Add a driver for the video capture engine Jonathan Corbet
2010-04-24 15:07 ` [RFC] Second OLPC Viafb series Florian Tobias Schandinat

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=1272058093-20914-6-git-send-email-corbet@lwn.net \
    --to=corbet@lwn.net \
    --cc=FlorianSchandinat@gmx.de \
    --cc=JosephChan@via.com.tw \
    --cc=ScottFang@viatech.com.cn \
    --cc=dsaxena@laptop.org \
    --cc=laforge@gnumonks.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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).