forked from luck/tmp_suning_uos_patched
sh: heartbeat driver update.
Add some flags for the heartbeat driver, and kill off some duplication in the bit positions for the boards that don't have special cases. This also allows for variable access widths and inversion. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
This commit is contained in:
parent
2eb0303c2c
commit
8786c952c1
|
@ -19,6 +19,7 @@
|
|||
#include <asm/machvec.h>
|
||||
#include <asm/r7780rp.h>
|
||||
#include <asm/clock.h>
|
||||
#include <asm/heartbeat.h>
|
||||
#include <asm/io.h>
|
||||
|
||||
static struct resource r8a66597_usb_host_resources[] = {
|
||||
|
@ -108,16 +109,23 @@ static struct platform_device cf_ide_device = {
|
|||
},
|
||||
};
|
||||
|
||||
static unsigned char heartbeat_bit_pos[] = { 2, 1, 0, 3, 6, 5, 4, 7 };
|
||||
|
||||
static struct resource heartbeat_resources[] = {
|
||||
[0] = {
|
||||
.start = PA_OBLED,
|
||||
.end = PA_OBLED + ARRAY_SIZE(heartbeat_bit_pos) - 1,
|
||||
.end = PA_OBLED + 8 - 1,
|
||||
.flags = IORESOURCE_MEM,
|
||||
},
|
||||
};
|
||||
|
||||
#ifndef CONFIG_SH_R7785RP
|
||||
static unsigned char heartbeat_bit_pos[] = { 2, 1, 0, 3, 6, 5, 4, 7 };
|
||||
|
||||
static struct heartbeat_data heartbeat_data = {
|
||||
.bit_pos = heartbeat_bit_pos,
|
||||
.nr_bits = ARRAY_SIZE(heartbeat_bit_pos),
|
||||
};
|
||||
#endif
|
||||
|
||||
static struct platform_device heartbeat_device = {
|
||||
.name = "heartbeat",
|
||||
.id = -1,
|
||||
|
@ -125,7 +133,7 @@ static struct platform_device heartbeat_device = {
|
|||
/* R7785RP has a slightly more sensible FPGA.. */
|
||||
#ifndef CONFIG_SH_R7785RP
|
||||
.dev = {
|
||||
.platform_data = heartbeat_bit_pos,
|
||||
.platform_data = heartbeat_data,
|
||||
},
|
||||
#endif
|
||||
.num_resources = ARRAY_SIZE(heartbeat_resources),
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <asm/se7206.h>
|
||||
#include <asm/io.h>
|
||||
#include <asm/machvec.h>
|
||||
#include <asm/heartbeat.h>
|
||||
|
||||
static struct resource smc91x_resources[] = {
|
||||
[0] = {
|
||||
|
@ -37,6 +38,11 @@ static struct platform_device smc91x_device = {
|
|||
|
||||
static unsigned char heartbeat_bit_pos[] = { 8, 9, 10, 11, 12, 13, 14, 15 };
|
||||
|
||||
static struct heartbeat_data heartbeat_data = {
|
||||
.bit_pos = heartbeat_bit_pos,
|
||||
.nr_bits = ARRAY_SIZE(heartbeat_bit_pos),
|
||||
};
|
||||
|
||||
static struct resource heartbeat_resources[] = {
|
||||
[0] = {
|
||||
.start = PA_LED,
|
||||
|
@ -49,7 +55,7 @@ static struct platform_device heartbeat_device = {
|
|||
.name = "heartbeat",
|
||||
.id = -1,
|
||||
.dev = {
|
||||
.platform_data = heartbeat_bit_pos,
|
||||
.platform_data = heartbeat_data,
|
||||
},
|
||||
.num_resources = ARRAY_SIZE(heartbeat_resources),
|
||||
.resource = heartbeat_resources,
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <asm/se.h>
|
||||
#include <asm/io.h>
|
||||
#include <asm/smc37c93x.h>
|
||||
#include <asm/heartbeat.h>
|
||||
|
||||
void init_se_IRQ(void);
|
||||
|
||||
|
@ -90,6 +91,11 @@ static struct platform_device cf_ide_device = {
|
|||
|
||||
static unsigned char heartbeat_bit_pos[] = { 8, 9, 10, 11, 12, 13, 14, 15 };
|
||||
|
||||
static struct heartbeat_data heartbeat_data = {
|
||||
.bit_pos = heartbeat_bit_pos,
|
||||
.nr_bits = ARRAY_SIZE(heartbeat_bit_pos),
|
||||
};
|
||||
|
||||
static struct resource heartbeat_resources[] = {
|
||||
[0] = {
|
||||
.start = PA_LED,
|
||||
|
@ -102,7 +108,7 @@ static struct platform_device heartbeat_device = {
|
|||
.name = "heartbeat",
|
||||
.id = -1,
|
||||
.dev = {
|
||||
.platform_data = heartbeat_bit_pos,
|
||||
.platform_data = heartbeat_data,
|
||||
},
|
||||
.num_resources = ARRAY_SIZE(heartbeat_resources),
|
||||
.resource = heartbeat_resources,
|
||||
|
|
|
@ -18,12 +18,10 @@
|
|||
#include <asm/io.h>
|
||||
|
||||
/* Heartbeat */
|
||||
static unsigned char heartbeat_bit_pos[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||
|
||||
static struct resource heartbeat_resources[] = {
|
||||
[0] = {
|
||||
.start = PA_LED,
|
||||
.end = PA_LED + ARRAY_SIZE(heartbeat_bit_pos) - 1,
|
||||
.end = PA_LED + 8 - 1,
|
||||
.flags = IORESOURCE_MEM,
|
||||
},
|
||||
};
|
||||
|
@ -31,9 +29,6 @@ static struct resource heartbeat_resources[] = {
|
|||
static struct platform_device heartbeat_device = {
|
||||
.name = "heartbeat",
|
||||
.id = -1,
|
||||
.dev = {
|
||||
.platform_data = heartbeat_bit_pos,
|
||||
},
|
||||
.num_resources = ARRAY_SIZE(heartbeat_resources),
|
||||
.resource = heartbeat_resources,
|
||||
};
|
||||
|
@ -109,7 +104,7 @@ static void __init se7722_setup(char **cmdline_p)
|
|||
ctrl_outl(0x00051001, MSTPCR0);
|
||||
ctrl_outl(0x00000000, MSTPCR1);
|
||||
/* KEYSC, VOU, BEU, CEU, VEU, VPU, LCDC */
|
||||
ctrl_outl(0xffffbfC0, MSTPCR2);
|
||||
ctrl_outl(0xffffbfC0, MSTPCR2);
|
||||
|
||||
ctrl_outw(0x0000, PORT_PECR); /* PORT E 1 = IRQ5 ,E 0 = BS */
|
||||
ctrl_outw(0x1000, PORT_PJCR); /* PORT J 1 = IRQ1,J 0 =IRQ0 */
|
||||
|
|
|
@ -13,9 +13,15 @@
|
|||
#include <asm/machvec.h>
|
||||
#include <asm/se7751.h>
|
||||
#include <asm/io.h>
|
||||
#include <asm/heartbeat.h>
|
||||
|
||||
static unsigned char heartbeat_bit_pos[] = { 8, 9, 10, 11, 12, 13, 14, 15 };
|
||||
|
||||
static struct heartbeat_data heartbeat_data = {
|
||||
.bit_pos = heartbeat_bit_pos,
|
||||
.nr_bits = ARRAY_SIZE(heartbeat_bit_pos),
|
||||
};
|
||||
|
||||
static struct resource heartbeat_resources[] = {
|
||||
[0] = {
|
||||
.start = PA_LED,
|
||||
|
@ -28,7 +34,7 @@ static struct platform_device heartbeat_device = {
|
|||
.name = "heartbeat",
|
||||
.id = -1,
|
||||
.dev = {
|
||||
.platform_data = heartbeat_bit_pos,
|
||||
.platform_data = heartbeat_data,
|
||||
},
|
||||
.num_resources = ARRAY_SIZE(heartbeat_resources),
|
||||
.resource = heartbeat_resources,
|
||||
|
|
|
@ -16,12 +16,10 @@
|
|||
#include <asm/io.h>
|
||||
|
||||
/* Heartbeat */
|
||||
static unsigned char heartbeat_bit_pos[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||
|
||||
static struct resource heartbeat_resources[] = {
|
||||
[0] = {
|
||||
.start = PA_LED,
|
||||
.end = PA_LED + ARRAY_SIZE(heartbeat_bit_pos) - 1,
|
||||
.end = PA_LED + 8 - 1,
|
||||
.flags = IORESOURCE_MEM,
|
||||
},
|
||||
};
|
||||
|
@ -29,9 +27,6 @@ static struct resource heartbeat_resources[] = {
|
|||
static struct platform_device heartbeat_device = {
|
||||
.name = "heartbeat",
|
||||
.id = -1,
|
||||
.dev = {
|
||||
.platform_data = heartbeat_bit_pos,
|
||||
},
|
||||
.num_resources = ARRAY_SIZE(heartbeat_resources),
|
||||
.resource = heartbeat_resources,
|
||||
};
|
||||
|
|
|
@ -24,24 +24,44 @@
|
|||
#include <linux/sched.h>
|
||||
#include <linux/timer.h>
|
||||
#include <linux/io.h>
|
||||
#include <asm/heartbeat.h>
|
||||
|
||||
#define DRV_NAME "heartbeat"
|
||||
#define DRV_VERSION "0.1.0"
|
||||
#define DRV_VERSION "0.1.1"
|
||||
|
||||
struct heartbeat_data {
|
||||
void __iomem *base;
|
||||
unsigned char bit_pos[8];
|
||||
struct timer_list timer;
|
||||
};
|
||||
static unsigned char default_bit_pos[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
|
||||
|
||||
static inline void heartbeat_toggle_bit(struct heartbeat_data *hd,
|
||||
unsigned bit, unsigned int inverted)
|
||||
{
|
||||
unsigned int new;
|
||||
|
||||
new = (1 << hd->bit_pos[bit]);
|
||||
if (inverted)
|
||||
new = ~new;
|
||||
|
||||
switch (hd->regsize) {
|
||||
case 32:
|
||||
iowrite32(new, hd->base);
|
||||
break;
|
||||
case 16:
|
||||
iowrite16(new, hd->base);
|
||||
break;
|
||||
default:
|
||||
iowrite8(new, hd->base);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void heartbeat_timer(unsigned long data)
|
||||
{
|
||||
struct heartbeat_data *hd = (struct heartbeat_data *)data;
|
||||
static unsigned bit = 0, up = 1;
|
||||
|
||||
ctrl_outw(1 << hd->bit_pos[bit], (unsigned long)hd->base);
|
||||
heartbeat_toggle_bit(hd, bit, hd->flags & HEARTBEAT_INVERTED);
|
||||
|
||||
bit += up;
|
||||
if ((bit == 0) || (bit == ARRAY_SIZE(hd->bit_pos)-1))
|
||||
if ((bit == 0) || (bit == (hd->nr_bits)-1))
|
||||
up = -up;
|
||||
|
||||
mod_timer(&hd->timer, jiffies + (110 - ((300 << FSHIFT) /
|
||||
|
@ -64,21 +84,31 @@ static int heartbeat_drv_probe(struct platform_device *pdev)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
hd = kmalloc(sizeof(struct heartbeat_data), GFP_KERNEL);
|
||||
if (unlikely(!hd))
|
||||
return -ENOMEM;
|
||||
|
||||
if (pdev->dev.platform_data) {
|
||||
memcpy(hd->bit_pos, pdev->dev.platform_data,
|
||||
ARRAY_SIZE(hd->bit_pos));
|
||||
hd = pdev->dev.platform_data;
|
||||
} else {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(hd->bit_pos); i++)
|
||||
hd->bit_pos[i] = i;
|
||||
hd = kzalloc(sizeof(struct heartbeat_data), GFP_KERNEL);
|
||||
if (unlikely(!hd))
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
hd->base = (void __iomem *)(unsigned long)res->start;
|
||||
hd->base = ioremap_nocache(res->start, res->end - res->start + 1);
|
||||
if (!unlikely(hd->base)) {
|
||||
dev_err(&pdev->dev, "ioremap failed\n");
|
||||
|
||||
if (!pdev->dev.platform_data)
|
||||
kfree(hd);
|
||||
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
if (!hd->nr_bits) {
|
||||
hd->bit_pos = default_bit_pos;
|
||||
hd->nr_bits = ARRAY_SIZE(default_bit_pos);
|
||||
}
|
||||
|
||||
if (!hd->regsize)
|
||||
hd->regsize = 8; /* default access size */
|
||||
|
||||
setup_timer(&hd->timer, heartbeat_timer, (unsigned long)hd);
|
||||
platform_set_drvdata(pdev, hd);
|
||||
|
@ -91,10 +121,12 @@ static int heartbeat_drv_remove(struct platform_device *pdev)
|
|||
struct heartbeat_data *hd = platform_get_drvdata(pdev);
|
||||
|
||||
del_timer_sync(&hd->timer);
|
||||
iounmap(hd->base);
|
||||
|
||||
platform_set_drvdata(pdev, NULL);
|
||||
|
||||
kfree(hd);
|
||||
if (!pdev->dev.platform_data)
|
||||
kfree(hd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
17
include/asm-sh/heartbeat.h
Normal file
17
include/asm-sh/heartbeat.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef __ASM_SH_HEARTBEAT_H
|
||||
#define __ASM_SH_HEARTBEAT_H
|
||||
|
||||
#include <linux/timer.h>
|
||||
|
||||
#define HEARTBEAT_INVERTED (1 << 0)
|
||||
|
||||
struct heartbeat_data {
|
||||
void __iomem *base;
|
||||
unsigned char *bit_pos;
|
||||
unsigned int nr_bits;
|
||||
struct timer_list timer;
|
||||
unsigned int regsize;
|
||||
unsigned long flags;
|
||||
};
|
||||
|
||||
#endif /* __ASM_SH_HEARTBEAT_H */
|
Loading…
Reference in New Issue
Block a user