Skip to contentSkip to conversation

can: mcp251x: Replace power callbacks with regulator API

PATCH New Alexander Shiyan 2 participants 6 messages Aug 19, 2013 – Aug 20, 2013

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 can: mcp251x: Replace power callbacks with regulator API

This patch replaces power callbacks to the regulator API. To improve the readability of the code, helper for the regulator enable/disable was added.

---
 arch/arm/mach-pxa/icontrol.c         |  3 --
 arch/arm/mach-pxa/zeus.c             | 46 ++++++++++----------
 drivers/net/can/mcp251x.c            | 81 +++++++++++++++++++-----------------
 include/linux/can/platform/mcp251x.h | 13 +-----
 4 files changed, 69 insertions(+), 74 deletions(-)
arch/arm/mach-pxa/icontrol.c +0 -3
index fe31bfc..c98511c 100644
@@ -73,9 +73,6 @@ static struct pxa2xx_spi_chip mcp251x_chip_info4 = {
 
 static struct mcp251x_platform_data mcp251x_info = {
 	.oscillator_frequency = 16E6,
-	.board_specific_setup = NULL,
-	.power_enable         = NULL,
-	.transceiver_enable   = NULL
 };
 
 static struct spi_board_info mcp251x_board_info[] = {
arch/arm/mach-pxa/zeus.c +25 -21

70 lines not on this page · raw message

drivers/net/can/mcp251x.c +43 -38

204 lines not on this page · raw message

include/linux/can/platform/mcp251x.h +1 -12
index 089fe43..8a27256 100644
@@ -9,26 +9,15 @@
 
 #include <linux/spi/spi.h>
 
-/**
+/*
  * struct mcp251x_platform_data - MCP251X SPI CAN controller platform data
  * @oscillator_frequency:       - oscillator frequency in Hz
  * @irq_flags:                  - IRQF configuration flags
- * @board_specific_setup:       - called before probing the chip (power,reset)
- * @transceiver_enable:         - called to power on/off the transceiver
- * @power_enable:               - called to power on/off the mcp *and* the
- *                                transceiver
- *
- * Please note that you should define power_enable or transceiver_enable or
- * none of them. Defining both of them is no use.
- *
  */
 
 struct mcp251x_platform_data {
 	unsigned long oscillator_frequency;
 	unsigned long irq_flags;
-	int (*board_specific_setup)(struct spi_device *spi);
-	int (*transceiver_enable)(int enable);
-	int (*power_enable) (int enable);
 };
 
 #endif /* __CAN_PLATFORM_MCP251X_H__ */
Signature · 1 line
1.8.1.5
#1 lore raw

PATCH v2 2/3 can: mcp251x: Eliminate irq_flags from driver platform_data

Flags is not used by boards, so remove this field from the driver platform_data.

---
 drivers/net/can/mcp251x.c            | 9 +--------
 include/linux/can/platform/mcp251x.h | 2 --
 2 files changed, 1 insertion(+), 10 deletions(-)
drivers/net/can/mcp251x.c +1 -8
index 3df83f8..a48d3df 100644
@@ -935,8 +935,7 @@ static int mcp251x_open(struct net_device *net)
 {
 	struct mcp251x_priv *priv = netdev_priv(net);
 	struct spi_device *spi = priv->spi;
-	struct mcp251x_platform_data *pdata = spi->dev.platform_data;
-	unsigned long flags;
+	unsigned long flags = IRQF_ONESHOT | IRQF_TRIGGER_FALLING;
 	int ret;
 
 	ret = open_candev(net);
@@ -952,12 +951,6 @@ static int mcp251x_open(struct net_device *net)
 	priv->tx_skb = NULL;
 	priv->tx_len = 0;
 
-	flags = IRQF_ONESHOT;
-	if (pdata->irq_flags)
-		flags |= pdata->irq_flags;
-	else
-		flags |= IRQF_TRIGGER_FALLING;
-
 	ret = request_threaded_irq(spi->irq, NULL, mcp251x_can_ist,
 				   flags, DEVICE_NAME, priv);
 	if (ret) {
include/linux/can/platform/mcp251x.h +0 -2
index 8a27256..dc029db 100644
@@ -12,12 +12,10 @@
 /*
  * struct mcp251x_platform_data - MCP251X SPI CAN controller platform data
  * @oscillator_frequency:       - oscillator frequency in Hz
- * @irq_flags:                  - IRQF configuration flags
  */
 
 struct mcp251x_platform_data {
 	unsigned long oscillator_frequency;
-	unsigned long irq_flags;
 };
 
 #endif /* __CAN_PLATFORM_MCP251X_H__ */
Signature · 1 line
1.8.1.5
#2 lore raw

PATCH v2 2/3 can: mcp251x: Eliminate irq_flags from driver platform_data

Quoted 4 lines · Alexander Shiyan

Flags is not used by boards, so remove this field from the driver platform_data.

Applied to linux-can-next/testing

Marc

Signature · 12 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 259 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130820/8905e646/attachment.sig>
#3 lore raw

PATCH v2 3/3 can: mcp251x: Allow tuning SPI mode and limit maximal SPI speed

In reply to Alexander Shiyan

Patch allow to use different mode settings for SPI (MODE3 for example) and limit maximal speed according to IC datasheet.

---
 drivers/net/can/mcp251x.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/can/mcp251x.c +5 -1
index a48d3df..c08edc7 100644
@@ -1082,7 +1082,11 @@ static int mcp251x_can_probe(struct spi_device *spi)
 	SET_NETDEV_DEV(net, &spi->dev);
 
 	/* Configure the SPI bus */
-	spi->mode = SPI_MODE_0;
+	spi->mode = spi->mode ? : SPI_MODE_0;
+	if (mcp251x_is_2510(spi))
+		spi->max_speed_hz = spi->max_speed_hz ? : 5 * 1000 * 1000;
+	else
+		spi->max_speed_hz = spi->max_speed_hz ? : 10 * 1000 * 1000;
 	spi->bits_per_word = 8;
 	spi_setup(spi);
 
Signature · 1 line
1.8.1.5
#4 lore raw

PATCH v2 3/3 can: mcp251x: Allow tuning SPI mode and limit maximal SPI speed

Quoted 4 lines · Alexander Shiyan

Patch allow to use different mode settings for SPI (MODE3 for example) and limit maximal speed according to IC datasheet.

Applied to linux-can-next/testing

tnx,
Marc

Signature · 12 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 259 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130820/d36f3cd3/attachment.sig>
#5 lore raw

PATCH v2 1/3 can: mcp251x: Replace power callbacks with regulator API

In reply to Alexander Shiyan
Quoted 12 lines · Alexander Shiyan

This patch replaces power callbacks to the regulator API. To improve the readability of the code, helper for the regulator enable/disable was added.

---
 arch/arm/mach-pxa/icontrol.c         |  3 --
 arch/arm/mach-pxa/zeus.c             | 46 ++++++++++----------
 drivers/net/can/mcp251x.c            | 81 +++++++++++++++++++-----------------
 include/linux/can/platform/mcp251x.h | 13 +-----
 4 files changed, 69 insertions(+), 74 deletions(-)

[...]

Quoted 4 lines
drivers/net/can/mcp251x.c +0 -0
index 8cda23b..3df83f8 100644

[...]

Quoted 5 lines
drivers/net/can/mcp251x.c +0 -1
@@ -1163,15 +1170,14 @@ static int mcp251x_can_suspend(struct device *dev)
 		netif_device_detach(net);
 
 		mcp251x_hw_sleep(spi);
-		if (pdata->transceiver_enable)

drivers/net/can/mcp251x.c static int mcp251x_can_suspend(struct device *dev) · line 1179

Quoted 10 lines
drivers/net/can/mcp251x.c +2 -3
-			pdata->transceiver_enable(0);
+		mcp251x_power_enable(priv->transceiver, 0);
 		priv->after_suspend = AFTER_SUSPEND_UP;
 	} else {
 		priv->after_suspend = AFTER_SUSPEND_DOWN;
 	}
 
-	if (pdata->power_enable) {
-		pdata->power_enable(0);
+	if (!IS_ERR(priv->power))
                                ^^^

There's a '{' missing.

Quoted 9 lines
drivers/net/can/mcp251x.c +1 -1
+		regulator_disable(priv->power);
 		priv->after_suspend |= AFTER_SUSPEND_POWER;
 	}
 
@@ -1185,12 +1191,11 @@ static int mcp251x_can_resume(struct device *dev)
 	struct mcp251x_priv *priv = spi_get_drvdata(spi);
 
 	if (priv->after_suspend & AFTER_SUSPEND_POWER) {
-		pdata->power_enable(1);

drivers/net/can/mcp251x.c static int mcp251x_can_resume(struct device *dev) · line 1201

Quoted 10 lines
drivers/net/can/mcp251x.c +2 -2
+		mcp251x_power_enable(priv->power, 1);
 		queue_work(priv->wq, &priv->restart_work);
 	} else {
 		if (priv->after_suspend & AFTER_SUSPEND_UP) {
-			if (pdata->transceiver_enable)
-				pdata->transceiver_enable(1);
+			mcp251x_power_enable(priv->transceiver, 1);
 			queue_work(priv->wq, &priv->restart_work);
 		} else {
 			priv->after_suspend = 0;

And I see the following warnings:

Quoted 4 lines

/home/frogger/pengutronix/socketcan/linux/drivers/net/can/mcp251x.c: In function 'mcp251x_can_suspend':
/home/frogger/pengutronix/socketcan/linux/drivers/net/can/mcp251x.c:1156:32: warning: unused variable 'pdata' [-Wunused-variable] /home/frogger/pengutronix/socketcan/linux/drivers/net/can/mcp251x.c: In function 'mcp251x_can_resume':
/home/frogger/pengutronix/socketcan/linux/drivers/net/can/mcp251x.c:1187:32: warning: unused variable 'pdata' [-Wunused-variable]

I've fixed the problems and applied the patch to linux-can/testing.

Marc

Signature · 12 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 259 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130820/3579fa09/attachment.sig>