central.c 6.0 KB
Newer Older
D
David S. Miller 已提交
1
/* central.c: Central FHC driver for Sunfire/Starfire/Wildfire.
L
Linus Torvalds 已提交
2
 *
3
 * Copyright (C) 1997, 1999, 2008 David S. Miller (davem@davemloft.net)
L
Linus Torvalds 已提交
4 5 6 7
 */

#include <linux/kernel.h>
#include <linux/types.h>
8
#include <linux/slab.h>
9
#include <linux/export.h>
L
Linus Torvalds 已提交
10 11
#include <linux/string.h>
#include <linux/init.h>
12 13
#include <linux/of_device.h>
#include <linux/platform_device.h>
L
Linus Torvalds 已提交
14 15

#include <asm/fhc.h>
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#include <asm/upa.h>

struct clock_board {
	void __iomem		*clock_freq_regs;
	void __iomem		*clock_regs;
	void __iomem		*clock_ver_reg;
	int			num_slots;
	struct resource		leds_resource;
	struct platform_device	leds_pdev;
};

struct fhc {
	void __iomem		*pregs;
	bool			central;
	bool			jtag_master;
	int			board_num;
	struct resource		leds_resource;
	struct platform_device	leds_pdev;
};

36
static int clock_board_calc_nslots(struct clock_board *p)
37 38
{
	u8 reg = upa_readb(p->clock_regs + CLOCK_STAT1) & 0xc0;
L
Linus Torvalds 已提交
39

40 41 42
	switch (reg) {
	case 0x40:
		return 16;
L
Linus Torvalds 已提交
43

44 45
	case 0xc0:
		return 8;
L
Linus Torvalds 已提交
46

47 48 49 50 51 52 53 54 55 56 57 58 59
	case 0x80:
		reg = 0;
		if (p->clock_ver_reg)
			reg = upa_readb(p->clock_ver_reg);
		if (reg) {
			if (reg & 0x80)
				return 4;
			else
				return 5;
		}
		/* Fallthrough */
	default:
		return 4;
60
	}
L
Linus Torvalds 已提交
61 62
}

63
static int clock_board_probe(struct platform_device *op)
L
Linus Torvalds 已提交
64
{
65 66
	struct clock_board *p = kzalloc(sizeof(*p), GFP_KERNEL);
	int err = -ENOMEM;
L
Linus Torvalds 已提交
67

68 69 70
	if (!p) {
		printk(KERN_ERR "clock_board: Cannot allocate struct clock_board\n");
		goto out;
L
Linus Torvalds 已提交
71 72
	}

73 74 75 76 77 78 79
	p->clock_freq_regs = of_ioremap(&op->resource[0], 0,
					resource_size(&op->resource[0]),
					"clock_board_freq");
	if (!p->clock_freq_regs) {
		printk(KERN_ERR "clock_board: Cannot map clock_freq_regs\n");
		goto out_free;
	}
L
Linus Torvalds 已提交
80

81 82 83 84 85 86 87
	p->clock_regs = of_ioremap(&op->resource[1], 0,
				   resource_size(&op->resource[1]),
				   "clock_board_regs");
	if (!p->clock_regs) {
		printk(KERN_ERR "clock_board: Cannot map clock_regs\n");
		goto out_unmap_clock_freq_regs;
	}
L
Linus Torvalds 已提交
88

89 90 91 92 93 94 95 96 97
	if (op->resource[2].flags) {
		p->clock_ver_reg = of_ioremap(&op->resource[2], 0,
					      resource_size(&op->resource[2]),
					      "clock_ver_reg");
		if (!p->clock_ver_reg) {
			printk(KERN_ERR "clock_board: Cannot map clock_ver_reg\n");
			goto out_unmap_clock_regs;
		}
	}
L
Linus Torvalds 已提交
98

99
	p->num_slots = clock_board_calc_nslots(p);
L
Linus Torvalds 已提交
100

101 102
	p->leds_resource.start = (unsigned long)
		(p->clock_regs + CLOCK_CTRL);
103
	p->leds_resource.end = p->leds_resource.start;
104
	p->leds_resource.name = "leds";
L
Linus Torvalds 已提交
105

106
	p->leds_pdev.name = "sunfire-clockboard-leds";
107
	p->leds_pdev.id = -1;
108 109 110
	p->leds_pdev.resource = &p->leds_resource;
	p->leds_pdev.num_resources = 1;
	p->leds_pdev.dev.parent = &op->dev;
L
Linus Torvalds 已提交
111

112 113 114 115 116
	err = platform_device_register(&p->leds_pdev);
	if (err) {
		printk(KERN_ERR "clock_board: Could not register LEDS "
		       "platform device\n");
		goto out_unmap_clock_ver_reg;
L
Linus Torvalds 已提交
117 118
	}

119 120
	printk(KERN_INFO "clock_board: Detected %d slot Enterprise system.\n",
	       p->num_slots);
L
Linus Torvalds 已提交
121

122 123 124
	err = 0;
out:
	return err;
L
Linus Torvalds 已提交
125

126 127 128 129
out_unmap_clock_ver_reg:
	if (p->clock_ver_reg)
		of_iounmap(&op->resource[2], p->clock_ver_reg,
			   resource_size(&op->resource[2]));
130

131 132 133
out_unmap_clock_regs:
	of_iounmap(&op->resource[1], p->clock_regs,
		   resource_size(&op->resource[1]));
L
Linus Torvalds 已提交
134

135 136 137
out_unmap_clock_freq_regs:
	of_iounmap(&op->resource[0], p->clock_freq_regs,
		   resource_size(&op->resource[0]));
L
Linus Torvalds 已提交
138

139 140 141
out_free:
	kfree(p);
	goto out;
L
Linus Torvalds 已提交
142 143
}

144
static const struct of_device_id clock_board_match[] = {
145 146 147 148 149 150
	{
		.name = "clock-board",
	},
	{},
};

151
static struct platform_driver clock_board_driver = {
152
	.probe		= clock_board_probe,
153 154 155 156
	.driver = {
		.name = "clock_board",
		.owner = THIS_MODULE,
		.of_match_table = clock_board_match,
157 158 159
	},
};

160
static int fhc_probe(struct platform_device *op)
L
Linus Torvalds 已提交
161
{
162 163 164
	struct fhc *p = kzalloc(sizeof(*p), GFP_KERNEL);
	int err = -ENOMEM;
	u32 reg;
L
Linus Torvalds 已提交
165

166 167 168
	if (!p) {
		printk(KERN_ERR "fhc: Cannot allocate struct fhc\n");
		goto out;
L
Linus Torvalds 已提交
169 170
	}

171
	if (!strcmp(op->dev.of_node->parent->name, "central"))
172
		p->central = true;
L
Linus Torvalds 已提交
173

174 175 176 177 178 179
	p->pregs = of_ioremap(&op->resource[0], 0,
			      resource_size(&op->resource[0]),
			      "fhc_pregs");
	if (!p->pregs) {
		printk(KERN_ERR "fhc: Cannot map pregs\n");
		goto out_free;
180
	}
L
Linus Torvalds 已提交
181

182 183 184 185
	if (p->central) {
		reg = upa_readl(p->pregs + FHC_PREGS_BSR);
		p->board_num = ((reg >> 16) & 1) | ((reg >> 12) & 0x0e);
	} else {
186
		p->board_num = of_getintprop_default(op->dev.of_node, "board#", -1);
187 188 189 190 191 192 193
		if (p->board_num == -1) {
			printk(KERN_ERR "fhc: No board# property\n");
			goto out_unmap_pregs;
		}
		if (upa_readl(p->pregs + FHC_PREGS_JCTRL) & FHC_JTAG_CTRL_MENAB)
			p->jtag_master = true;
	}
L
Linus Torvalds 已提交
194

195 196 197
	if (!p->central) {
		p->leds_resource.start = (unsigned long)
			(p->pregs + FHC_PREGS_CTRL);
198
		p->leds_resource.end = p->leds_resource.start;
199 200 201
		p->leds_resource.name = "leds";

		p->leds_pdev.name = "sunfire-fhc-leds";
202
		p->leds_pdev.id = p->board_num;
203 204 205 206 207 208 209 210 211 212 213 214
		p->leds_pdev.resource = &p->leds_resource;
		p->leds_pdev.num_resources = 1;
		p->leds_pdev.dev.parent = &op->dev;

		err = platform_device_register(&p->leds_pdev);
		if (err) {
			printk(KERN_ERR "fhc: Could not register LEDS "
			       "platform device\n");
			goto out_unmap_pregs;
		}
	}
	reg = upa_readl(p->pregs + FHC_PREGS_CTRL);
L
Linus Torvalds 已提交
215

216 217
	if (!p->central)
		reg |= FHC_CONTROL_IXIST;
L
Linus Torvalds 已提交
218

219 220 221
	reg &= ~(FHC_CONTROL_AOFF |
		 FHC_CONTROL_BOFF |
		 FHC_CONTROL_SLINE);
L
Linus Torvalds 已提交
222

223 224
	upa_writel(reg, p->pregs + FHC_PREGS_CTRL);
	upa_readl(p->pregs + FHC_PREGS_CTRL);
L
Linus Torvalds 已提交
225

226 227 228 229 230 231 232 233 234
	reg = upa_readl(p->pregs + FHC_PREGS_ID);
	printk(KERN_INFO "fhc: Board #%d, Version[%x] PartID[%x] Manuf[%x] %s\n",
	       p->board_num,
	       (reg & FHC_ID_VERS) >> 28,
	       (reg & FHC_ID_PARTID) >> 12,
	       (reg & FHC_ID_MANUF) >> 1,
	       (p->jtag_master ?
		"(JTAG Master)" :
		(p->central ? "(Central)" : "")));
L
Linus Torvalds 已提交
235

236
	err = 0;
L
Linus Torvalds 已提交
237

238 239
out:
	return err;
L
Linus Torvalds 已提交
240

241 242
out_unmap_pregs:
	of_iounmap(&op->resource[0], p->pregs, resource_size(&op->resource[0]));
L
Linus Torvalds 已提交
243

244 245 246
out_free:
	kfree(p);
	goto out;
L
Linus Torvalds 已提交
247 248
}

249
static const struct of_device_id fhc_match[] = {
250 251 252 253 254 255
	{
		.name = "fhc",
	},
	{},
};

256
static struct platform_driver fhc_driver = {
257
	.probe		= fhc_probe,
258 259 260 261
	.driver = {
		.name = "fhc",
		.owner = THIS_MODULE,
		.of_match_table = fhc_match,
262 263 264 265
	},
};

static int __init sunfire_init(void)
L
Linus Torvalds 已提交
266
{
267 268
	(void) platform_driver_register(&fhc_driver);
	(void) platform_driver_register(&clock_board_driver);
269
	return 0;
L
Linus Torvalds 已提交
270
}
271

272
fs_initcall(sunfire_init);