Skip to contentSkip to conversation

bfin_rotary: Move peripheral pinmux definition into platform data of bf527

PATCH Superseded Sonic Zhang 2 participants 8 messages Feb 4, 2015 – Feb 5, 2015

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 2/3 bfin_rotary: Move peripheral pinmux definition into platform data of bf527

From: Sonic Zhang <[email protected]>

v3-changes:
- Pinctrl API is used to set up counter pinmux on bf548 and bf609. Pinmux list is use less on bf548 and bf609.

---
 arch/blackfin/mach-bf527/boards/ad7160eval.c |    8 ++++++++
 arch/blackfin/mach-bf527/boards/ezkit.c      |    8 ++++++++
 drivers/input/misc/bfin_rotary.c             |   12 +++---------
 include/linux/platform_data/bfin_rotary.h    |    1 +
 4 files changed, 20 insertions(+), 9 deletions(-)
arch/blackfin/mach-bf527/boards/ad7160eval.c +8 -0
index beb011b..029a050 100644
@@ -668,6 +668,13 @@ static struct platform_device bfin_sport1_uart_device = {
 #if IS_ENABLED(CONFIG_INPUT_BFIN_ROTARY)
 #include <linux/platform_data/bfin_rotary.h>
 
+static const u16 per_cnt[] = {
+	P_CNT_CUD,
+	P_CNT_CDG,
+	P_CNT_CZM,
+	0
+};
+
 static struct bfin_rotary_platform_data bfin_rotary_data = {
 	/*.rotary_up_key     = KEY_UP,*/
 	/*.rotary_down_key   = KEY_DOWN,*/
@@ -676,6 +683,7 @@ static struct bfin_rotary_platform_data bfin_rotary_data = {
 	.debounce	   = 10,	/* 0..17 */
 	.mode		   = ROT_QUAD_ENC | ROT_DEBE,
 	.pm_wakeup	   = 1,
+	.pin_list	   = per_cnt,
 };
 
 static struct resource bfin_rotary_resources[] = {
arch/blackfin/mach-bf527/boards/ezkit.c +8 -0
index 728cda4..cc80c5b 100644
@@ -1094,6 +1094,13 @@ static struct platform_device bfin_device_gpiokeys = {
 #if IS_ENABLED(CONFIG_INPUT_BFIN_ROTARY)
 #include <linux/platform_data/bfin_rotary.h>
 
+static const u16 per_cnt[] = {
+	P_CNT_CUD,
+	P_CNT_CDG,
+	P_CNT_CZM,
+	0
+};
+
 static struct bfin_rotary_platform_data bfin_rotary_data = {
 	/*.rotary_up_key     = KEY_UP,*/
 	/*.rotary_down_key   = KEY_DOWN,*/
@@ -1102,6 +1109,7 @@ static struct bfin_rotary_platform_data bfin_rotary_data = {
 	.debounce	   = 10,	/* 0..17 */
 	.mode		   = ROT_QUAD_ENC | ROT_DEBE,
 	.pm_wakeup	   = 1,
+	.pin_list	   = per_cnt,
 };
 
 static struct resource bfin_rotary_resources[] = {
drivers/input/misc/bfin_rotary.c +3 -9
index 8f6c7cd..dd62fc9 100644
@@ -16,13 +16,6 @@
 
 #include <asm/portmux.h>
 
-static const u16 per_cnt[] = {
-	P_CNT_CUD,
-	P_CNT_CDG,
-	P_CNT_CZM,
-	0
-};
-
 struct bfin_rot {
 	struct input_dev *input;
 	int irq;
@@ -102,7 +95,7 @@ static int bfin_rotary_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	error = peripheral_request_list(per_cnt, dev_name(&pdev->dev));
+	error = peripheral_request_list(pdata->pin_list, dev_name(&pdev->dev));
 	if (error) {
 		dev_err(&pdev->dev, "requesting peripherals failed\n");
 		return error;
@@ -197,6 +190,7 @@ out1:
 
 static int bfin_rotary_remove(struct platform_device *pdev)
 {
+	struct bfin_rotary_platform_data *pdata = dev_get_platdata(&pdev->dev);
 	struct bfin_rot *rotary = platform_get_drvdata(pdev);
 
 	bfin_write_CNT_CONFIG(0);
@@ -204,7 +198,7 @@ static int bfin_rotary_remove(struct platform_device *pdev)
 
 	free_irq(rotary->irq, pdev);
 	input_unregister_device(rotary->input);
-	peripheral_free_list(per_cnt);
+	peripheral_free_list(pdata->pin_list);
 
 	kfree(rotary);
 
include/linux/platform_data/bfin_rotary.h +1 -0
index 8895a75..9882937 100644
@@ -40,6 +40,7 @@ struct bfin_rotary_platform_data {
 	unsigned short debounce;	/* 0..17 */
 	unsigned short mode;
 	unsigned short pm_wakeup;
+	unsigned short *pin_list;
 };
 
 /* CNT_CONFIG bitmasks */
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v3 3/3 bfin_rotary: replace bfin specific MMR function with generic IO function

From: Sonic Zhang <[email protected]>

- use readw and writew to access rotary MMRs
- remap rotary register physical address into kernel space in probe

v2-changes:
- replace kzalloc with devm_kzalloc
- replace request_irq with devm_request_irq
- remove memory free and irq free from the device remove function

v3-changes:
- move managed resources to a separate patch

---
 drivers/input/misc/bfin_rotary.c |   53 ++++++++++++++++++++++++--------------
 1 file changed, 34 insertions(+), 19 deletions(-)
drivers/input/misc/bfin_rotary.c +34 -19
index dd62fc9..defddca 100644
@@ -7,6 +7,7 @@
 
 #include <linux/module.h>
 #include <linux/interrupt.h>
+#include <linux/io.h>
 #include <linux/irq.h>
 #include <linux/pm.h>
 #include <linux/platform_device.h>
@@ -16,8 +17,18 @@
 
 #include <asm/portmux.h>
 
+#define CNT_CONFIG_OFF		0	/* CNT Config Offset */
+#define CNT_IMASK_OFF		4	/* CNT Interrupt Mask Offset */
+#define CNT_STATUS_OFF		8	/* CNT Status Offset */
+#define CNT_COMMAND_OFF		12	/* CNT Command Offset */
+#define CNT_DEBOUNCE_OFF	16	/* CNT Debounce Offset */
+#define CNT_COUNTER_OFF		20	/* CNT Counter Offset */
+#define CNT_MAX_OFF		24	/* CNT Maximum Count Offset */
+#define CNT_MIN_OFF		28	/* CNT Minimum Count Offset */
+
 struct bfin_rot {
 	struct input_dev *input;
+	void __iomem *base;
 	int irq;
 	unsigned int up_key;
 	unsigned int down_key;
@@ -56,14 +67,14 @@ static irqreturn_t bfin_rotary_isr(int irq, void *dev_id)
 	struct bfin_rot *rotary = platform_get_drvdata(pdev);
 	int delta;
 
-	switch (bfin_read_CNT_STATUS()) {
+	switch (readw(rotary->base + CNT_STATUS_OFF)) {
 
 	case ICII:
 		break;
 
 	case UCII:
 	case DCII:
-		delta = bfin_read_CNT_COUNTER();
+		delta = readl(rotary->base + CNT_COUNTER_OFF);
 		if (delta)
 			report_rotary_event(rotary, delta);
 		break;
@@ -76,8 +87,8 @@ static irqreturn_t bfin_rotary_isr(int irq, void *dev_id)
 		break;
 	}
 
-	bfin_write_CNT_COMMAND(W1LCNT_ZERO);	/* Clear COUNTER */
-	bfin_write_CNT_STATUS(-1);	/* Clear STATUS */
+	writew(W1LCNT_ZERO, rotary->base + CNT_COMMAND_OFF); /* Clear COUNTER */
+	writew(-1, rotary->base + CNT_STATUS_OFF); /* Clear STATUS */
 
 	return IRQ_HANDLED;
 }
@@ -161,17 +172,21 @@ static int bfin_rotary_probe(struct platform_device *pdev)
 	}
 
 	if (pdata->rotary_button_key)
-		bfin_write_CNT_IMASK(CZMIE);
+		writew(CZMIE, rotary->base + CNT_IMASK_OFF);
 
 	if (pdata->mode & ROT_DEBE)
-		bfin_write_CNT_DEBOUNCE(pdata->debounce & DPRESCALE);
+		writew(pdata->debounce & DPRESCALE,
+			rotary->base + CNT_DEBOUNCE_OFF);
 
 	if (pdata->mode)
-		bfin_write_CNT_CONFIG(bfin_read_CNT_CONFIG() |
-					(pdata->mode & ~CNTE));
+		writew(readw(rotary->base + CNT_CONFIG_OFF) |
+			(pdata->mode & ~CNTE),
+			rotary->base + CNT_CONFIG_OFF);
 
-	bfin_write_CNT_IMASK(bfin_read_CNT_IMASK() | UCIE | DCIE);
-	bfin_write_CNT_CONFIG(bfin_read_CNT_CONFIG() | CNTE);
+	writew(readw(rotary->base + CNT_IMASK_OFF) | UCIE | DCIE,
+		rotary->base + CNT_IMASK_OFF);
+	writew(readw(rotary->base + CNT_CONFIG_OFF) | CNTE,
+		rotary->base + CNT_CONFIG_OFF);
 
 	platform_set_drvdata(pdev, rotary);
 	device_init_wakeup(&pdev->dev, 1);
@@ -193,8 +208,8 @@ static int bfin_rotary_remove(struct platform_device *pdev)
 	struct bfin_rotary_platform_data *pdata = dev_get_platdata(&pdev->dev);
 	struct bfin_rot *rotary = platform_get_drvdata(pdev);
 
-	bfin_write_CNT_CONFIG(0);
-	bfin_write_CNT_IMASK(0);
+	writew(0, rotary->base + CNT_CONFIG_OFF);
+	writew(0, rotary->base + CNT_IMASK_OFF);
 
 	free_irq(rotary->irq, pdev);
 	input_unregister_device(rotary->input);
@@ -211,9 +226,9 @@ static int bfin_rotary_suspend(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	struct bfin_rot *rotary = platform_get_drvdata(pdev);
 
-	rotary->cnt_config = bfin_read_CNT_CONFIG();
-	rotary->cnt_imask = bfin_read_CNT_IMASK();
-	rotary->cnt_debounce = bfin_read_CNT_DEBOUNCE();
+	rotary->cnt_config = readw(rotary->base + CNT_CONFIG_OFF);
+	rotary->cnt_imask = readw(rotary->base + CNT_IMASK_OFF);
+	rotary->cnt_debounce = readw(rotary->base + CNT_DEBOUNCE_OFF);
 
 	if (device_may_wakeup(&pdev->dev))
 		enable_irq_wake(rotary->irq);
@@ -226,15 +241,15 @@ static int bfin_rotary_resume(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	struct bfin_rot *rotary = platform_get_drvdata(pdev);
 
-	bfin_write_CNT_DEBOUNCE(rotary->cnt_debounce);
-	bfin_write_CNT_IMASK(rotary->cnt_imask);
-	bfin_write_CNT_CONFIG(rotary->cnt_config & ~CNTE);
+	writew(rotary->cnt_debounce, rotary->base + CNT_DEBOUNCE_OFF);
+	writew(rotary->cnt_imask, rotary->base + CNT_IMASK_OFF);
+	writew(rotary->cnt_config & ~CNTE, rotary->base + CNT_CONFIG_OFF);
 
 	if (device_may_wakeup(&pdev->dev))
 		disable_irq_wake(rotary->irq);
 
 	if (rotary->cnt_config & CNTE)
-		bfin_write_CNT_CONFIG(rotary->cnt_config);
+		writew(rotary->cnt_config, rotary->base + CNT_CONFIG_OFF);
 
 	return 0;
 }
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 1/1 bfin_rotary: convert to use managed resources

In reply to Sonic Zhang

From: Sonic Zhang <[email protected]>

- remap rotary register physical address into kernel space in probe
- replace kzalloc with devm_kzalloc
- replace request_irq with devm_request_irq
- remove memory free and irq free from the device remove function
- use devm_input_allocate_device

---
 arch/blackfin/mach-bf527/boards/ad7160eval.c |    5 ++
 arch/blackfin/mach-bf527/boards/ezkit.c      |    5 ++
 arch/blackfin/mach-bf548/boards/ezkit.c      |    5 ++
 arch/blackfin/mach-bf609/boards/ezkit.c      |    5 ++
 drivers/input/misc/bfin_rotary.c             |   64 ++++++++++++++------------
 5 files changed, 54 insertions(+), 30 deletions(-)
arch/blackfin/mach-bf527/boards/ad7160eval.c +5 -0
index 029a050..68f2a8a 100644
@@ -688,6 +688,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = {
 
 static struct resource bfin_rotary_resources[] = {
 	{
+		.start = CNT_CONFIG,
+		.end   = CNT_CONFIG + 0xff,
+		.flags = IORESOURCE_MEM,
+	},
+	{
 		.start = IRQ_CNT,
 		.end = IRQ_CNT,
 		.flags = IORESOURCE_IRQ,
arch/blackfin/mach-bf527/boards/ezkit.c +5 -0
index cc80c5b..d4219e8 100644
@@ -1114,6 +1114,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = {
 
 static struct resource bfin_rotary_resources[] = {
 	{
+		.start = CNT_CONFIG,
+		.end   = CNT_CONFIG + 0xff,
+		.flags = IORESOURCE_MEM,
+	},
+	{
 		.start = IRQ_CNT,
 		.end = IRQ_CNT,
 		.flags = IORESOURCE_IRQ,
arch/blackfin/mach-bf548/boards/ezkit.c +5 -0
index 8f70f83..4204b98 100644
@@ -173,6 +173,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = {
 
 static struct resource bfin_rotary_resources[] = {
 	{
+		.start = CNT_CONFIG,
+		.end   = CNT_CONFIG + 0xff,
+		.flags = IORESOURCE_MEM,
+	},
+	{
 		.start = IRQ_CNT,
 		.end = IRQ_CNT,
 		.flags = IORESOURCE_IRQ,
arch/blackfin/mach-bf609/boards/ezkit.c +5 -0
index f9dc64d..7f9fc27 100644
@@ -88,6 +88,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = {
 
 static struct resource bfin_rotary_resources[] = {
 	{
+		.start = CNT_CONFIG,
+		.end   = CNT_CONFIG + 0xff,
+		.flags = IORESOURCE_MEM,
+	},
+	{
 		.start = IRQ_CNT,
 		.end = IRQ_CNT,
 		.flags = IORESOURCE_IRQ,
drivers/input/misc/bfin_rotary.c +34 -30

113 lines not on this page · raw message

Signature · 1 line
1.7.9.5
maintainer
#5 lore raw
In reply to Sonic Zhang

Hi Sonic,

drivers/input/misc/bfin_rotary.c static int bfin_rotary_probe(struct platform_device *pdev) · line 98

Quoted 6 lines · Sonic Zhang
drivers/input/misc/bfin_rotary.c +1 -1
@@ -102,7 +95,7 @@ static int bfin_rotary_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	error = peripheral_request_list(per_cnt, dev_name(&pdev->dev));
+	error = peripheral_request_list(pdata->pin_list, dev_name(&pdev->dev));

I do not think the driver will be happy with pdata->oin_list == NULL here.

drivers/input/misc/bfin_rotary.c out1: · line 193

Quoted 8 lines
drivers/input/misc/bfin_rotary.c +1 -0
 	if (error) {
 		dev_err(&pdev->dev, "requesting peripherals failed\n");
 		return error;
@@ -197,6 +190,7 @@ out1:
 
 static int bfin_rotary_remove(struct platform_device *pdev)
 {
+	struct bfin_rotary_platform_data *pdata = dev_get_platdata(&pdev->dev);

Why do you need this change?

drivers/input/misc/bfin_rotary.c static int bfin_rotary_remove(struct platform_device *pdev) · line 201

Quoted 9 lines
drivers/input/misc/bfin_rotary.c +1 -1
 	struct bfin_rot *rotary = platform_get_drvdata(pdev);
 
 	bfin_write_CNT_CONFIG(0);
@@ -204,7 +198,7 @@ static int bfin_rotary_remove(struct platform_device *pdev)
 
 	free_irq(rotary->irq, pdev);
 	input_unregister_device(rotary->input);
-	peripheral_free_list(per_cnt);
+	peripheral_free_list(pdata->pin_list);

Same here: NULL will cause severe indigestion.

Thanks.

Signature · 1 line
Dmitry
maintainer
#2 lore raw

Re: [PATCH v3 3/3] bfin_rotary: replace bfin specific MMR function with generic IO function

In reply to Sonic Zhang
Quoted 36 lines · Sonic Zhang

From: Sonic Zhang <[email protected]>

- use readw and writew to access rotary MMRs
- remap rotary register physical address into kernel space in probe

v2-changes:
- replace kzalloc with devm_kzalloc
- replace request_irq with devm_request_irq
- remove memory free and irq free from the device remove function

v3-changes:
- move managed resources to a separate patch

---
 drivers/input/misc/bfin_rotary.c |   53 ++++++++++++++++++++++++--------------
 1 file changed, 34 insertions(+), 19 deletions(-)
drivers/input/misc/bfin_rotary.c +3 -0
index dd62fc9..defddca 100644
@@ -7,6 +7,7 @@
 
 #include <linux/module.h>
 #include <linux/interrupt.h>
+#include <linux/io.h>
 #include <linux/irq.h>
 #include <linux/pm.h>
 #include <linux/platform_device.h>
@@ -16,8 +17,18 @@
 
 #include <asm/portmux.h>
 
+#define CNT_CONFIG_OFF		0	/* CNT Config Offset */
+#define CNT_IMASK_OFF		4	/* CNT Interrupt Mask Offset */

drivers/input/misc/bfin_rotary.c line 31

Quoted 10 lines
drivers/input/misc/bfin_rotary.c +8 -0
+#define CNT_STATUS_OFF		8	/* CNT Status Offset */
+#define CNT_COMMAND_OFF		12	/* CNT Command Offset */
+#define CNT_DEBOUNCE_OFF	16	/* CNT Debounce Offset */
+#define CNT_COUNTER_OFF		20	/* CNT Counter Offset */
+#define CNT_MAX_OFF		24	/* CNT Maximum Count Offset */
+#define CNT_MIN_OFF		28	/* CNT Minimum Count Offset */
+
 struct bfin_rot {
 	struct input_dev *input;
+	void __iomem *base;

Who is populating this member? Remember, patches must be complete.

Thanks.

Quoted 106 lines
drivers/input/misc/bfin_rotary.c +23 -19
 	int irq;
 	unsigned int up_key;
 	unsigned int down_key;
@@ -56,14 +67,14 @@ static irqreturn_t bfin_rotary_isr(int irq, void *dev_id)
 	struct bfin_rot *rotary = platform_get_drvdata(pdev);
 	int delta;
 
-	switch (bfin_read_CNT_STATUS()) {
+	switch (readw(rotary->base + CNT_STATUS_OFF)) {
 
 	case ICII:
 		break;
 
 	case UCII:
 	case DCII:
-		delta = bfin_read_CNT_COUNTER();
+		delta = readl(rotary->base + CNT_COUNTER_OFF);
 		if (delta)
 			report_rotary_event(rotary, delta);
 		break;
@@ -76,8 +87,8 @@ static irqreturn_t bfin_rotary_isr(int irq, void *dev_id)
 		break;
 	}
 
-	bfin_write_CNT_COMMAND(W1LCNT_ZERO);	/* Clear COUNTER */
-	bfin_write_CNT_STATUS(-1);	/* Clear STATUS */
+	writew(W1LCNT_ZERO, rotary->base + CNT_COMMAND_OFF); /* Clear COUNTER */
+	writew(-1, rotary->base + CNT_STATUS_OFF); /* Clear STATUS */
 
 	return IRQ_HANDLED;
 }
@@ -161,17 +172,21 @@ static int bfin_rotary_probe(struct platform_device *pdev)
 	}
 
 	if (pdata->rotary_button_key)
-		bfin_write_CNT_IMASK(CZMIE);
+		writew(CZMIE, rotary->base + CNT_IMASK_OFF);
 
 	if (pdata->mode & ROT_DEBE)
-		bfin_write_CNT_DEBOUNCE(pdata->debounce & DPRESCALE);
+		writew(pdata->debounce & DPRESCALE,
+			rotary->base + CNT_DEBOUNCE_OFF);
 
 	if (pdata->mode)
-		bfin_write_CNT_CONFIG(bfin_read_CNT_CONFIG() |
-					(pdata->mode & ~CNTE));
+		writew(readw(rotary->base + CNT_CONFIG_OFF) |
+			(pdata->mode & ~CNTE),
+			rotary->base + CNT_CONFIG_OFF);
 
-	bfin_write_CNT_IMASK(bfin_read_CNT_IMASK() | UCIE | DCIE);
-	bfin_write_CNT_CONFIG(bfin_read_CNT_CONFIG() | CNTE);
+	writew(readw(rotary->base + CNT_IMASK_OFF) | UCIE | DCIE,
+		rotary->base + CNT_IMASK_OFF);
+	writew(readw(rotary->base + CNT_CONFIG_OFF) | CNTE,
+		rotary->base + CNT_CONFIG_OFF);
 
 	platform_set_drvdata(pdev, rotary);
 	device_init_wakeup(&pdev->dev, 1);
@@ -193,8 +208,8 @@ static int bfin_rotary_remove(struct platform_device *pdev)
 	struct bfin_rotary_platform_data *pdata = dev_get_platdata(&pdev->dev);
 	struct bfin_rot *rotary = platform_get_drvdata(pdev);
 
-	bfin_write_CNT_CONFIG(0);
-	bfin_write_CNT_IMASK(0);
+	writew(0, rotary->base + CNT_CONFIG_OFF);
+	writew(0, rotary->base + CNT_IMASK_OFF);
 
 	free_irq(rotary->irq, pdev);
 	input_unregister_device(rotary->input);
@@ -211,9 +226,9 @@ static int bfin_rotary_suspend(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	struct bfin_rot *rotary = platform_get_drvdata(pdev);
 
-	rotary->cnt_config = bfin_read_CNT_CONFIG();
-	rotary->cnt_imask = bfin_read_CNT_IMASK();
-	rotary->cnt_debounce = bfin_read_CNT_DEBOUNCE();
+	rotary->cnt_config = readw(rotary->base + CNT_CONFIG_OFF);
+	rotary->cnt_imask = readw(rotary->base + CNT_IMASK_OFF);
+	rotary->cnt_debounce = readw(rotary->base + CNT_DEBOUNCE_OFF);
 
 	if (device_may_wakeup(&pdev->dev))
 		enable_irq_wake(rotary->irq);
@@ -226,15 +241,15 @@ static int bfin_rotary_resume(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	struct bfin_rot *rotary = platform_get_drvdata(pdev);
 
-	bfin_write_CNT_DEBOUNCE(rotary->cnt_debounce);
-	bfin_write_CNT_IMASK(rotary->cnt_imask);
-	bfin_write_CNT_CONFIG(rotary->cnt_config & ~CNTE);
+	writew(rotary->cnt_debounce, rotary->base + CNT_DEBOUNCE_OFF);
+	writew(rotary->cnt_imask, rotary->base + CNT_IMASK_OFF);
+	writew(rotary->cnt_config & ~CNTE, rotary->base + CNT_CONFIG_OFF);
 
 	if (device_may_wakeup(&pdev->dev))
 		disable_irq_wake(rotary->irq);
 
 	if (rotary->cnt_config & CNTE)
-		bfin_write_CNT_CONFIG(rotary->cnt_config);
+		writew(rotary->cnt_config, rotary->base + CNT_CONFIG_OFF);
 
 	return 0;
 }
Signature · 1 line
1.7.9.5
Signature · 1 line
Dmitry
maintainer
#4 lore raw

Re: [PATCH] bfin_rotary: convert to use managed resources

In reply to Sonic Zhang
Quoted 192 lines · Sonic Zhang

From: Sonic Zhang <[email protected]>

- remap rotary register physical address into kernel space in probe
- replace kzalloc with devm_kzalloc
- replace request_irq with devm_request_irq
- remove memory free and irq free from the device remove function
- use devm_input_allocate_device

---
 arch/blackfin/mach-bf527/boards/ad7160eval.c |    5 ++
 arch/blackfin/mach-bf527/boards/ezkit.c      |    5 ++
 arch/blackfin/mach-bf548/boards/ezkit.c      |    5 ++
 arch/blackfin/mach-bf609/boards/ezkit.c      |    5 ++
 drivers/input/misc/bfin_rotary.c             |   64 ++++++++++++++------------
 5 files changed, 54 insertions(+), 30 deletions(-)
arch/blackfin/mach-bf527/boards/ad7160eval.c +5 -0
index 029a050..68f2a8a 100644
@@ -688,6 +688,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = {
 
 static struct resource bfin_rotary_resources[] = {
 	{
+		.start = CNT_CONFIG,
+		.end   = CNT_CONFIG + 0xff,
+		.flags = IORESOURCE_MEM,
+	},
+	{
 		.start = IRQ_CNT,
 		.end = IRQ_CNT,
 		.flags = IORESOURCE_IRQ,
arch/blackfin/mach-bf527/boards/ezkit.c +5 -0
index cc80c5b..d4219e8 100644
@@ -1114,6 +1114,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = {
 
 static struct resource bfin_rotary_resources[] = {
 	{
+		.start = CNT_CONFIG,
+		.end   = CNT_CONFIG + 0xff,
+		.flags = IORESOURCE_MEM,
+	},
+	{
 		.start = IRQ_CNT,
 		.end = IRQ_CNT,
 		.flags = IORESOURCE_IRQ,
arch/blackfin/mach-bf548/boards/ezkit.c +5 -0
index 8f70f83..4204b98 100644
@@ -173,6 +173,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = {
 
 static struct resource bfin_rotary_resources[] = {
 	{
+		.start = CNT_CONFIG,
+		.end   = CNT_CONFIG + 0xff,
+		.flags = IORESOURCE_MEM,
+	},
+	{
 		.start = IRQ_CNT,
 		.end = IRQ_CNT,
 		.flags = IORESOURCE_IRQ,
arch/blackfin/mach-bf609/boards/ezkit.c +5 -0
index f9dc64d..7f9fc27 100644
@@ -88,6 +88,11 @@ static struct bfin_rotary_platform_data bfin_rotary_data = {
 
 static struct resource bfin_rotary_resources[] = {
 	{
+		.start = CNT_CONFIG,
+		.end   = CNT_CONFIG + 0xff,
+		.flags = IORESOURCE_MEM,
+	},
+	{
 		.start = IRQ_CNT,
 		.end = IRQ_CNT,
 		.flags = IORESOURCE_IRQ,
drivers/input/misc/bfin_rotary.c +34 -26
index defddca..3bc0018 100644
@@ -95,11 +95,38 @@ static irqreturn_t bfin_rotary_isr(int irq, void *dev_id)
 
 static int bfin_rotary_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct bfin_rotary_platform_data *pdata = dev_get_platdata(&pdev->dev);
 	struct bfin_rot *rotary;
+	struct resource *res;
 	struct input_dev *input;
 	int error;
 
+	rotary = devm_kzalloc(dev, sizeof(struct bfin_rot), GFP_KERNEL);
+	if (!rotary) {
+		dev_err(dev, "fail to malloc bfin_rot\n");
+		return -ENOMEM;
+	}
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	rotary->base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(rotary->base))
+		return PTR_ERR(rotary->base);
+
+	rotary->irq = platform_get_irq(pdev, 0);
+	if (rotary->irq < 0) {
+		dev_err(dev, "No rotary IRQ specified\n");
+		return -ENOENT;
+	}
+
+	error = devm_request_irq(dev, rotary->irq, bfin_rotary_isr,
+			    0, dev_name(&pdev->dev), pdev);
+	if (error) {
+		dev_err(dev, "unable to claim irq %d; error %d\n",
+			rotary->irq, error);
+		return error;
+	}
+
 	/* Basic validation */
 	if ((pdata->rotary_up_key && !pdata->rotary_down_key) ||
 	    (!pdata->rotary_up_key && pdata->rotary_down_key)) {
@@ -108,15 +135,14 @@ static int bfin_rotary_probe(struct platform_device *pdev)
 
 	error = peripheral_request_list(pdata->pin_list, dev_name(&pdev->dev));
 	if (error) {
-		dev_err(&pdev->dev, "requesting peripherals failed\n");
+		dev_err(dev, "requesting peripherals failed\n");
 		return error;
 	}
 
-	rotary = kzalloc(sizeof(struct bfin_rot), GFP_KERNEL);
-	input = input_allocate_device();
-	if (!rotary || !input) {
+	input = devm_input_allocate_device(dev);
+	if (!input) {
 		error = -ENOMEM;
-		goto out1;
+		goto out;
 	}
 
 	rotary->input = input;
@@ -126,10 +152,6 @@ static int bfin_rotary_probe(struct platform_device *pdev)
 	rotary->button_key = pdata->rotary_button_key;
 	rotary->rel_code = pdata->rotary_rel_code;
 
-	error = rotary->irq = platform_get_irq(pdev, 0);
-	if (error < 0)
-		goto out1;
-
 	input->name = pdev->name;
 	input->phys = "bfin-rotary/input0";
 	input->dev.parent = &pdev->dev;
@@ -155,20 +177,10 @@ static int bfin_rotary_probe(struct platform_device *pdev)
 		__set_bit(rotary->button_key, input->keybit);
 	}
 
-	error = request_irq(rotary->irq, bfin_rotary_isr,
-			    0, dev_name(&pdev->dev), pdev);
-	if (error) {
-		dev_err(&pdev->dev,
-			"unable to claim irq %d; error %d\n",
-			rotary->irq, error);
-		goto out1;
-	}
-
 	error = input_register_device(input);
 	if (error) {
-		dev_err(&pdev->dev,
-			"unable to register input device (%d)\n", error);
-		goto out2;
+		dev_err(dev, "unable to register input device (%d)\n", error);
+		goto out;
 	}
 
 	if (pdata->rotary_button_key)
@@ -193,11 +205,7 @@ static int bfin_rotary_probe(struct platform_device *pdev)
 
 	return 0;
 
-out2:
-	free_irq(rotary->irq, pdev);
-out1:
-	input_free_device(input);
-	kfree(rotary);
+out:
 	peripheral_free_list(per_cnt);
 
 	return error;

drivers/input/misc/bfin_rotary.c static int bfin_rotary_remove(struct platform_device *pdev) · line 222

Quoted 6 lines
drivers/input/misc/bfin_rotary.c +0 -2
@@ -211,12 +219,8 @@ static int bfin_rotary_remove(struct platform_device *pdev)
 	writew(0, rotary->base + CNT_CONFIG_OFF);
 	writew(0, rotary->base + CNT_IMASK_OFF);
 
-	free_irq(rotary->irq, pdev);
-	input_unregister_device(rotary->input);
 	peripheral_free_list(pdata->pin_list);

This causes pins be freed while interrupt is still active. I suggest you use devm_add_action() to integrate freeing of pins into the rest of devm* unwind sequence.

Quoted 9 lines
drivers/input/misc/bfin_rotary.c +0 -2
-	kfree(rotary);
-
 	return 0;
 }
 
Signature · 1 line
1.7.9.5

Thanks.

Signature · 1 line
Dmitry
#6 lore raw
In reply to Dmitry Torokhov

Hi Dmitry,

Quoted 7 lines · Dmitry Torokhov

Hi Sonic,

Quoted 4 lines · Sonic Zhang
drivers/input/misc/bfin_rotary.c +0 -0
@@ -102,7 +95,7 @@ static int bfin_rotary_probe(struct platform_device *pdev)
              return -EINVAL;
      }
 
Quoted 5 lines

drivers/input/misc/bfin_rotary.c static int bfin_rotary_probe(struct platform_device *pdev) · line 98

Quoted 2 lines
drivers/input/misc/bfin_rotary.c +1 -1
-     error = peripheral_request_list(per_cnt, dev_name(&pdev->dev));
+     error = peripheral_request_list(pdata->pin_list, dev_name(&pdev->dev));

I do not think the driver will be happy with pdata->oin_list == NULL here.

When pinctrl API is used in bf609 and bf548, peripheral_requst and peripheral_free macros are defined empty in arch/blackfin/include/asm/pinmux.h. So, pdata->oin_list == NULL is never mind. I can add a null array point check to peripheral_request_list() and peripheral_free_list() in a different patch for Blackfin arch code.

#ifdef CONFIG_PINCTRL

#define peripheral_request(per, label) (0)
#define peripheral_free(per)
#define peripheral_request_list(per, label) (0)
#define peripheral_free_list(per)

#else

Quoted 11 lines

drivers/input/misc/bfin_rotary.c out1: · line 193

Quoted 9 lines
drivers/input/misc/bfin_rotary.c +1 -0
      if (error) {
              dev_err(&pdev->dev, "requesting peripherals failed\n");
              return error;
@@ -197,6 +190,7 @@ out1:
 
 static int bfin_rotary_remove(struct platform_device *pdev)
 {
+     struct bfin_rotary_platform_data *pdata = dev_get_platdata(&pdev->dev);

Why do you need this change?

The pdata struct is used to pass pin_list array to peripheral_free_list().

Quoted 6 lines
Quoted 6 lines
drivers/input/misc/bfin_rotary.c +0 -0
      struct bfin_rot *rotary = platform_get_drvdata(pdev);
 
      bfin_write_CNT_CONFIG(0);
@@ -204,7 +198,7 @@ static int bfin_rotary_remove(struct platform_device *pdev)
 
Quoted 7 lines

drivers/input/misc/bfin_rotary.c static int bfin_rotary_remove(struct platform_device *pdev) · line 201

Quoted 4 lines
drivers/input/misc/bfin_rotary.c +1 -1
      free_irq(rotary->irq, pdev);
      input_unregister_device(rotary->input);
-     peripheral_free_list(per_cnt);
+     peripheral_free_list(pdata->pin_list);

Same here: NULL will cause severe indigestion.

See my comment up.

Regards,

Sonic

#7 lore raw
In reply to Dmitry Torokhov

Hi Dmitry,

Quoted 7 lines · Dmitry Torokhov

Hi Sonic,

Quoted 4 lines · Sonic Zhang
drivers/input/misc/bfin_rotary.c +0 -0
@@ -102,7 +95,7 @@ static int bfin_rotary_probe(struct platform_device *pdev)
              return -EINVAL;
      }
 
Quoted 5 lines

drivers/input/misc/bfin_rotary.c static int bfin_rotary_probe(struct platform_device *pdev) · line 98

Quoted 2 lines
drivers/input/misc/bfin_rotary.c +1 -1
-     error = peripheral_request_list(per_cnt, dev_name(&pdev->dev));
+     error = peripheral_request_list(pdata->pin_list, dev_name(&pdev->dev));

I do not think the driver will be happy with pdata->oin_list == NULL here.

I forgot one more replacement of variable per_cnt in bfin_rotary_probe. I will update.

Sonic