Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 112986
b: refs/heads/master
c: b28422e
h: refs/heads/master
v: v3
  • Loading branch information
David S. Miller committed Aug 25, 2008
1 parent f518c18 commit 290a849
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 42 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e04180882faf69e896a8131ff3137788dd08b8d3
refs/heads/master: b28422e32b9127ab4178ce05a419069db3d11d19
119 changes: 78 additions & 41 deletions trunk/arch/sparc64/kernel/chmc.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* memctrlr.c: Driver for UltraSPARC-III memory controller.
/* chmc.c: Driver for UltraSPARC-III memory controller.
*
* Copyright (C) 2001, 2007 David S. Miller (davem@davemloft.net)
* Copyright (C) 2001, 2007, 2008 David S. Miller (davem@davemloft.net)
*/

#include <linux/module.h>
Expand All @@ -13,13 +13,25 @@
#include <linux/smp.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <asm/spitfire.h>
#include <asm/chmctrl.h>
#include <asm/cpudata.h>
#include <asm/oplib.h>
#include <asm/prom.h>
#include <asm/head.h>
#include <asm/io.h>

#define DRV_MODULE_NAME "chmc"
#define PFX DRV_MODULE_NAME ": "
#define DRV_MODULE_VERSION "0.2"

MODULE_AUTHOR("David S. Miller (davem@davemloft.net)");
MODULE_DESCRIPTION("UltraSPARC-III memory controller driver");
MODULE_LICENSE("GPL");
MODULE_VERSION(DRV_MODULE_VERSION);

#define CHMCTRL_NDGRPS 2
#define CHMCTRL_NDIMMS 4

Expand Down Expand Up @@ -343,16 +355,25 @@ static void fetch_decode_regs(struct mctrl_info *mp)
read_mcreg(mp, CHMCTRL_DECODE4));
}

static int init_one_mctrl(struct device_node *dp)
static int __devinit chmc_probe(struct of_device *op,
const struct of_device_id *match)
{
struct mctrl_info *mp = kzalloc(sizeof(*mp), GFP_KERNEL);
int portid = of_getintprop_default(dp, "portid", -1);
const struct linux_prom64_registers *regs;
struct device_node *dp = op->node;
struct mctrl_info *mp;
unsigned long ver;
const void *pval;
int len;
int len, portid;

__asm__ ("rdpr %%ver, %0" : "=r" (ver));
if ((ver >> 32UL) == __JALAPENO_ID ||
(ver >> 32UL) == __SERRANO_ID)
return -ENODEV;

mp = kzalloc(sizeof(*mp), GFP_KERNEL);
if (!mp)
return -1;
return -ENOMEM;

portid = of_getintprop_default(dp, "portid", -1);
if (portid == -1)
goto fail;

Expand All @@ -362,18 +383,19 @@ static int init_one_mctrl(struct device_node *dp)
if (!pval)
mp->layout_size = 0;
else {
if (mp->layout_size > sizeof(mp->layout_prop))
if (mp->layout_size > sizeof(mp->layout_prop)) {
printk(KERN_ERR PFX "Unexpected memory-layout property "
"size %d.\n", mp->layout_size);
goto fail;
}
memcpy(&mp->layout_prop, pval, len);
}

regs = of_get_property(dp, "reg", NULL);
if (!regs || regs->reg_size != 0x48)
goto fail;

mp->regs = ioremap(regs->phys_addr, regs->reg_size);
if (mp->regs == NULL)
mp->regs = of_ioremap(&op->resource[0], 0, 0x48, "chmc");
if (!mp->regs) {
printk(KERN_ERR PFX "Could not map registers.\n");
goto fail;
}

if (mp->layout_size != 0UL) {
mp->timing_control1 = read_mcreg(mp, CHMCTRL_TCTRL1);
Expand All @@ -388,54 +410,69 @@ static int init_one_mctrl(struct device_node *dp)
list_add(&mp->list, &mctrl_list);

/* Report the device. */
printk(KERN_INFO "%s: US3 memory controller at %p [%s]\n",
printk(KERN_INFO PFX "UltraSPARC-III memory controller at %s [%s]\n",
dp->full_name,
mp->regs, (mp->layout_size ? "ACTIVE" : "INACTIVE"));
(mp->layout_size ? "ACTIVE" : "INACTIVE"));

dev_set_drvdata(&op->dev, mp);

return 0;

fail:
if (mp) {
if (mp->regs != NULL)
iounmap(mp->regs);
of_iounmap(&op->resource[0], mp->regs, 0x48);
kfree(mp);
}
return -1;
}

static int __init chmc_init(void)
static int __devexit chmc_remove(struct of_device *op)
{
struct device_node *dp;
struct mctrl_info *mp = dev_get_drvdata(&op->dev);

/* This driver is only for cheetah platforms. */
if (tlb_type != cheetah && tlb_type != cheetah_plus)
return -ENODEV;
if (mp) {
list_del(&mp->list);
of_iounmap(&op->resource[0], mp->regs, 0x48);
kfree(mp);
}
return 0;
}

for_each_node_by_name(dp, "memory-controller")
init_one_mctrl(dp);
static struct of_device_id chmc_match[] = {
{
.name = "memory-controller",
},
{},
};
MODULE_DEVICE_TABLE(of, chmc_match);

for_each_node_by_name(dp, "mc-us3")
init_one_mctrl(dp);
static struct of_platform_driver chmc_driver = {
.name = "chmc",
.match_table = chmc_match,
.probe = chmc_probe,
.remove = __devexit_p(chmc_remove),
};

return 0;
static inline bool chmc_platform(void)
{
if (tlb_type == cheetah || tlb_type == cheetah_plus)
return true;
return false;
}

static void __exit chmc_cleanup(void)
static int __init chmc_init(void)
{
struct list_head *head = &mctrl_list;
struct list_head *tmp = head->next;
if (!chmc_platform())
return -ENODEV;

for (;;) {
struct mctrl_info *p =
list_entry(tmp, struct mctrl_info, list);
if (tmp == head)
break;
tmp = tmp->next;
return of_register_driver(&chmc_driver, &of_bus_type);
}

list_del(&p->list);
iounmap(p->regs);
kfree(p);
}
static void __exit chmc_cleanup(void)
{
if (chmc_platform())
of_unregister_driver(&chmc_driver);
}

module_init(chmc_init);
Expand Down

0 comments on commit 290a849

Please sign in to comment.