Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 2 | * linux/drivers/video/pmagb-b-fb.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 4 | * PMAGB-B TURBOchannel Smart Frame Buffer (SFB) card support, |
| 5 | * derived from: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * "HP300 Topcat framebuffer support (derived from macfb of all things) |
| 7 | * Phil Blundell <philb@gnu.org> 1998", the original code can be |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 8 | * found in the file hpfb.c in the same directory. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 10 | * DECstation related code Copyright (C) 1999, 2000, 2001 by |
| 11 | * Michael Engel <engel@unix-ag.org>, |
| 12 | * Karsten Merker <merker@linuxtag.org> and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * Harald Koerfgen. |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 14 | * Copyright (c) 2005, 2006 Maciej W. Rozycki |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 16 | * This file is subject to the terms and conditions of the GNU General |
| 17 | * Public License. See the file COPYING in the main directory of this |
| 18 | * archive for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 21 | #include <linux/compiler.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/delay.h> |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 23 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/fb.h> |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 25 | #include <linux/init.h> |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/module.h> |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 28 | #include <linux/tc.h> |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 29 | #include <linux/types.h> |
| 30 | |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 31 | #include <asm/io.h> |
| 32 | #include <asm/system.h> |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <video/pmagb-b-fb.h> |
| 35 | |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 36 | |
| 37 | struct pmagbbfb_par { |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 38 | volatile void __iomem *mmio; |
| 39 | volatile void __iomem *smem; |
| 40 | volatile u32 __iomem *sfb; |
| 41 | volatile u32 __iomem *dac; |
| 42 | unsigned int osc0; |
| 43 | unsigned int osc1; |
| 44 | int slot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 48 | static struct fb_var_screeninfo pmagbbfb_defined __initdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | .bits_per_pixel = 8, |
| 50 | .red.length = 8, |
| 51 | .green.length = 8, |
| 52 | .blue.length = 8, |
| 53 | .activate = FB_ACTIVATE_NOW, |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 54 | .height = -1, |
| 55 | .width = -1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | .accel_flags = FB_ACCEL_NONE, |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 57 | .sync = FB_SYNC_ON_GREEN, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | .vmode = FB_VMODE_NONINTERLACED, |
| 59 | }; |
| 60 | |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 61 | static struct fb_fix_screeninfo pmagbbfb_fix __initdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | .id = "PMAGB-BA", |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 63 | .smem_len = (2048 * 1024), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | .type = FB_TYPE_PACKED_PIXELS, |
| 65 | .visual = FB_VISUAL_PSEUDOCOLOR, |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 66 | .mmio_len = PMAGB_B_FBMEM, |
| 67 | }; |
| 68 | |
| 69 | |
| 70 | static inline void sfb_write(struct pmagbbfb_par *par, unsigned int reg, u32 v) |
| 71 | { |
| 72 | writel(v, par->sfb + reg / 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 75 | static inline u32 sfb_read(struct pmagbbfb_par *par, unsigned int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 77 | return readl(par->sfb + reg / 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 80 | static inline void dac_write(struct pmagbbfb_par *par, unsigned int reg, u8 v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 82 | writeb(v, par->dac + reg / 4); |
| 83 | } |
| 84 | |
| 85 | static inline u8 dac_read(struct pmagbbfb_par *par, unsigned int reg) |
| 86 | { |
| 87 | return readb(par->dac + reg / 4); |
| 88 | } |
| 89 | |
| 90 | static inline void gp0_write(struct pmagbbfb_par *par, u32 v) |
| 91 | { |
| 92 | writel(v, par->mmio + PMAGB_B_GP0); |
| 93 | } |
| 94 | |
| 95 | |
| 96 | /* |
| 97 | * Set the palette. |
| 98 | */ |
| 99 | static int pmagbbfb_setcolreg(unsigned int regno, unsigned int red, |
| 100 | unsigned int green, unsigned int blue, |
| 101 | unsigned int transp, struct fb_info *info) |
| 102 | { |
| 103 | struct pmagbbfb_par *par = info->par; |
| 104 | |
Krzysztof Helt | 2f39038 | 2009-12-15 16:46:25 -0800 | [diff] [blame] | 105 | if (regno >= info->cmap.len) |
| 106 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | red >>= 8; /* The cmap fields are 16 bits */ |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 109 | green >>= 8; /* wide, but the hardware colormap */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | blue >>= 8; /* registers are only 8 bits wide */ |
| 111 | |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 112 | mb(); |
| 113 | dac_write(par, BT459_ADDR_LO, regno); |
| 114 | dac_write(par, BT459_ADDR_HI, 0x00); |
| 115 | wmb(); |
| 116 | dac_write(par, BT459_CMAP, red); |
| 117 | wmb(); |
| 118 | dac_write(par, BT459_CMAP, green); |
| 119 | wmb(); |
| 120 | dac_write(par, BT459_CMAP, blue); |
| 121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | static struct fb_ops pmagbbfb_ops = { |
| 126 | .owner = THIS_MODULE, |
| 127 | .fb_setcolreg = pmagbbfb_setcolreg, |
| 128 | .fb_fillrect = cfb_fillrect, |
| 129 | .fb_copyarea = cfb_copyarea, |
| 130 | .fb_imageblit = cfb_imageblit, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 133 | |
| 134 | /* |
| 135 | * Turn the hardware cursor off. |
| 136 | */ |
| 137 | static void __init pmagbbfb_erase_cursor(struct fb_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 139 | struct pmagbbfb_par *par = info->par; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 141 | mb(); |
| 142 | dac_write(par, BT459_ADDR_LO, 0x00); |
| 143 | dac_write(par, BT459_ADDR_HI, 0x03); |
| 144 | wmb(); |
| 145 | dac_write(par, BT459_DATA, 0x00); |
| 146 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 148 | /* |
| 149 | * Set up screen parameters. |
| 150 | */ |
| 151 | static void __init pmagbbfb_screen_setup(struct fb_info *info) |
| 152 | { |
| 153 | struct pmagbbfb_par *par = info->par; |
| 154 | |
| 155 | info->var.xres = ((sfb_read(par, SFB_REG_VID_HOR) >> |
| 156 | SFB_VID_HOR_PIX_SHIFT) & SFB_VID_HOR_PIX_MASK) * 4; |
| 157 | info->var.xres_virtual = info->var.xres; |
| 158 | info->var.yres = (sfb_read(par, SFB_REG_VID_VER) >> |
| 159 | SFB_VID_VER_SL_SHIFT) & SFB_VID_VER_SL_MASK; |
| 160 | info->var.yres_virtual = info->var.yres; |
| 161 | info->var.left_margin = ((sfb_read(par, SFB_REG_VID_HOR) >> |
| 162 | SFB_VID_HOR_BP_SHIFT) & |
| 163 | SFB_VID_HOR_BP_MASK) * 4; |
| 164 | info->var.right_margin = ((sfb_read(par, SFB_REG_VID_HOR) >> |
| 165 | SFB_VID_HOR_FP_SHIFT) & |
| 166 | SFB_VID_HOR_FP_MASK) * 4; |
| 167 | info->var.upper_margin = (sfb_read(par, SFB_REG_VID_VER) >> |
| 168 | SFB_VID_VER_BP_SHIFT) & SFB_VID_VER_BP_MASK; |
| 169 | info->var.lower_margin = (sfb_read(par, SFB_REG_VID_VER) >> |
| 170 | SFB_VID_VER_FP_SHIFT) & SFB_VID_VER_FP_MASK; |
| 171 | info->var.hsync_len = ((sfb_read(par, SFB_REG_VID_HOR) >> |
| 172 | SFB_VID_HOR_SYN_SHIFT) & |
| 173 | SFB_VID_HOR_SYN_MASK) * 4; |
| 174 | info->var.vsync_len = (sfb_read(par, SFB_REG_VID_VER) >> |
| 175 | SFB_VID_VER_SYN_SHIFT) & SFB_VID_VER_SYN_MASK; |
| 176 | |
| 177 | info->fix.line_length = info->var.xres; |
| 178 | }; |
| 179 | |
| 180 | /* |
| 181 | * Determine oscillator configuration. |
| 182 | */ |
| 183 | static void __init pmagbbfb_osc_setup(struct fb_info *info) |
| 184 | { |
| 185 | static unsigned int pmagbbfb_freqs[] __initdata = { |
Maciej W. Rozycki | 572c04b | 2006-12-08 02:40:21 -0800 | [diff] [blame] | 186 | 130808, 119843, 104000, 92980, 74370, 72800, |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 187 | 69197, 66000, 65000, 50350, 36000, 32000, 25175 |
| 188 | }; |
| 189 | struct pmagbbfb_par *par = info->par; |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 190 | struct tc_bus *tbus = to_tc_dev(info->device)->bus; |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 191 | u32 count0 = 8, count1 = 8, counttc = 16 * 256 + 8; |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 192 | u32 freq0, freq1, freqtc = tc_get_speed(tbus) / 250; |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 193 | int i, j; |
| 194 | |
| 195 | gp0_write(par, 0); /* select Osc0 */ |
| 196 | for (j = 0; j < 16; j++) { |
| 197 | mb(); |
| 198 | sfb_write(par, SFB_REG_TCCLK_COUNT, 0); |
| 199 | mb(); |
| 200 | for (i = 0; i < 100; i++) { /* nominally max. 20.5us */ |
| 201 | if (sfb_read(par, SFB_REG_TCCLK_COUNT) == 0) |
| 202 | break; |
| 203 | udelay(1); |
| 204 | } |
| 205 | count0 += sfb_read(par, SFB_REG_VIDCLK_COUNT); |
| 206 | } |
| 207 | |
| 208 | gp0_write(par, 1); /* select Osc1 */ |
| 209 | for (j = 0; j < 16; j++) { |
| 210 | mb(); |
| 211 | sfb_write(par, SFB_REG_TCCLK_COUNT, 0); |
| 212 | |
| 213 | for (i = 0; i < 100; i++) { /* nominally max. 20.5us */ |
| 214 | if (sfb_read(par, SFB_REG_TCCLK_COUNT) == 0) |
| 215 | break; |
| 216 | udelay(1); |
| 217 | } |
| 218 | count1 += sfb_read(par, SFB_REG_VIDCLK_COUNT); |
| 219 | } |
| 220 | |
| 221 | freq0 = (freqtc * count0 + counttc / 2) / counttc; |
| 222 | par->osc0 = freq0; |
| 223 | if (freq0 >= pmagbbfb_freqs[0] - (pmagbbfb_freqs[0] + 32) / 64 && |
| 224 | freq0 <= pmagbbfb_freqs[0] + (pmagbbfb_freqs[0] + 32) / 64) |
| 225 | par->osc0 = pmagbbfb_freqs[0]; |
| 226 | |
| 227 | freq1 = (par->osc0 * count1 + count0 / 2) / count0; |
| 228 | par->osc1 = freq1; |
Tobias Klauser | d1ae418 | 2006-03-27 01:17:39 -0800 | [diff] [blame] | 229 | for (i = 0; i < ARRAY_SIZE(pmagbbfb_freqs); i++) |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 230 | if (freq1 >= pmagbbfb_freqs[i] - |
| 231 | (pmagbbfb_freqs[i] + 128) / 256 && |
| 232 | freq1 <= pmagbbfb_freqs[i] + |
| 233 | (pmagbbfb_freqs[i] + 128) / 256) { |
| 234 | par->osc1 = pmagbbfb_freqs[i]; |
| 235 | break; |
| 236 | } |
| 237 | |
| 238 | if (par->osc0 - par->osc1 <= (par->osc0 + par->osc1 + 256) / 512 || |
| 239 | par->osc1 - par->osc0 <= (par->osc0 + par->osc1 + 256) / 512) |
| 240 | par->osc1 = 0; |
| 241 | |
| 242 | gp0_write(par, par->osc1 != 0); /* reselect OscX */ |
| 243 | |
| 244 | info->var.pixclock = par->osc1 ? |
| 245 | (1000000000 + par->osc1 / 2) / par->osc1 : |
| 246 | (1000000000 + par->osc0 / 2) / par->osc0; |
| 247 | }; |
| 248 | |
| 249 | |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 250 | static int __init pmagbbfb_probe(struct device *dev) |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 251 | { |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 252 | struct tc_dev *tdev = to_tc_dev(dev); |
| 253 | resource_size_t start, len; |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 254 | struct fb_info *info; |
| 255 | struct pmagbbfb_par *par; |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 256 | char freq0[12], freq1[12]; |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 257 | u32 vid_base; |
Maciej W. Rozycki | 840bc9b | 2007-10-16 01:29:36 -0700 | [diff] [blame] | 258 | int err; |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 259 | |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 260 | info = framebuffer_alloc(sizeof(struct pmagbbfb_par), dev); |
Maciej W. Rozycki | 840bc9b | 2007-10-16 01:29:36 -0700 | [diff] [blame] | 261 | if (!info) { |
Kay Sievers | 7ad33e7 | 2009-03-24 16:38:21 -0700 | [diff] [blame] | 262 | printk(KERN_ERR "%s: Cannot allocate memory\n", dev_name(dev)); |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 263 | return -ENOMEM; |
Maciej W. Rozycki | 840bc9b | 2007-10-16 01:29:36 -0700 | [diff] [blame] | 264 | } |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 265 | |
| 266 | par = info->par; |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 267 | dev_set_drvdata(dev, info); |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 268 | |
Maciej W. Rozycki | 840bc9b | 2007-10-16 01:29:36 -0700 | [diff] [blame] | 269 | if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) { |
| 270 | printk(KERN_ERR "%s: Cannot allocate color map\n", |
Kay Sievers | 7ad33e7 | 2009-03-24 16:38:21 -0700 | [diff] [blame] | 271 | dev_name(dev)); |
Maciej W. Rozycki | 840bc9b | 2007-10-16 01:29:36 -0700 | [diff] [blame] | 272 | err = -ENOMEM; |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 273 | goto err_alloc; |
Maciej W. Rozycki | 840bc9b | 2007-10-16 01:29:36 -0700 | [diff] [blame] | 274 | } |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | info->fbops = &pmagbbfb_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | info->fix = pmagbbfb_fix; |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 278 | info->var = pmagbbfb_defined; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | info->flags = FBINFO_DEFAULT; |
| 280 | |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 281 | /* Request the I/O MEM resource. */ |
| 282 | start = tdev->resource.start; |
| 283 | len = tdev->resource.end - start + 1; |
Kay Sievers | 7ad33e7 | 2009-03-24 16:38:21 -0700 | [diff] [blame] | 284 | if (!request_mem_region(start, len, dev_name(dev))) { |
| 285 | printk(KERN_ERR "%s: Cannot reserve FB region\n", |
| 286 | dev_name(dev)); |
Maciej W. Rozycki | 840bc9b | 2007-10-16 01:29:36 -0700 | [diff] [blame] | 287 | err = -EBUSY; |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 288 | goto err_cmap; |
Maciej W. Rozycki | 840bc9b | 2007-10-16 01:29:36 -0700 | [diff] [blame] | 289 | } |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 290 | |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 291 | /* MMIO mapping setup. */ |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 292 | info->fix.mmio_start = start; |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 293 | par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len); |
Maciej W. Rozycki | 840bc9b | 2007-10-16 01:29:36 -0700 | [diff] [blame] | 294 | if (!par->mmio) { |
Kay Sievers | 7ad33e7 | 2009-03-24 16:38:21 -0700 | [diff] [blame] | 295 | printk(KERN_ERR "%s: Cannot map MMIO\n", dev_name(dev)); |
Maciej W. Rozycki | 840bc9b | 2007-10-16 01:29:36 -0700 | [diff] [blame] | 296 | err = -ENOMEM; |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 297 | goto err_resource; |
Maciej W. Rozycki | 840bc9b | 2007-10-16 01:29:36 -0700 | [diff] [blame] | 298 | } |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 299 | par->sfb = par->mmio + PMAGB_B_SFB; |
| 300 | par->dac = par->mmio + PMAGB_B_BT459; |
| 301 | |
| 302 | /* Frame buffer mapping setup. */ |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 303 | info->fix.smem_start = start + PMAGB_B_FBMEM; |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 304 | par->smem = ioremap_nocache(info->fix.smem_start, info->fix.smem_len); |
Maciej W. Rozycki | 840bc9b | 2007-10-16 01:29:36 -0700 | [diff] [blame] | 305 | if (!par->smem) { |
Kay Sievers | 7ad33e7 | 2009-03-24 16:38:21 -0700 | [diff] [blame] | 306 | printk(KERN_ERR "%s: Cannot map FB\n", dev_name(dev)); |
Maciej W. Rozycki | 840bc9b | 2007-10-16 01:29:36 -0700 | [diff] [blame] | 307 | err = -ENOMEM; |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 308 | goto err_mmio_map; |
Maciej W. Rozycki | 840bc9b | 2007-10-16 01:29:36 -0700 | [diff] [blame] | 309 | } |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 310 | vid_base = sfb_read(par, SFB_REG_VID_BASE); |
| 311 | info->screen_base = (void __iomem *)par->smem + vid_base * 0x1000; |
| 312 | info->screen_size = info->fix.smem_len - 2 * vid_base * 0x1000; |
| 313 | |
| 314 | pmagbbfb_erase_cursor(info); |
| 315 | pmagbbfb_screen_setup(info); |
| 316 | pmagbbfb_osc_setup(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Maciej W. Rozycki | 840bc9b | 2007-10-16 01:29:36 -0700 | [diff] [blame] | 318 | err = register_framebuffer(info); |
| 319 | if (err < 0) { |
| 320 | printk(KERN_ERR "%s: Cannot register framebuffer\n", |
Kay Sievers | 7ad33e7 | 2009-03-24 16:38:21 -0700 | [diff] [blame] | 321 | dev_name(dev)); |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 322 | goto err_smem_map; |
Maciej W. Rozycki | 840bc9b | 2007-10-16 01:29:36 -0700 | [diff] [blame] | 323 | } |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 324 | |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 325 | get_device(dev); |
| 326 | |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 327 | snprintf(freq0, sizeof(freq0), "%u.%03uMHz", |
| 328 | par->osc0 / 1000, par->osc0 % 1000); |
| 329 | snprintf(freq1, sizeof(freq1), "%u.%03uMHz", |
| 330 | par->osc1 / 1000, par->osc1 % 1000); |
| 331 | |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 332 | pr_info("fb%d: %s frame buffer device at %s\n", |
Kay Sievers | 7ad33e7 | 2009-03-24 16:38:21 -0700 | [diff] [blame] | 333 | info->node, info->fix.id, dev_name(dev)); |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 334 | pr_info("fb%d: Osc0: %s, Osc1: %s, Osc%u selected\n", |
| 335 | info->node, freq0, par->osc1 ? freq1 : "disabled", |
| 336 | par->osc1 != 0); |
| 337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | return 0; |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 339 | |
| 340 | |
| 341 | err_smem_map: |
| 342 | iounmap(par->smem); |
| 343 | |
| 344 | err_mmio_map: |
| 345 | iounmap(par->mmio); |
| 346 | |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 347 | err_resource: |
| 348 | release_mem_region(start, len); |
| 349 | |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 350 | err_cmap: |
| 351 | fb_dealloc_cmap(&info->cmap); |
| 352 | |
| 353 | err_alloc: |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 354 | framebuffer_release(info); |
Maciej W. Rozycki | 840bc9b | 2007-10-16 01:29:36 -0700 | [diff] [blame] | 355 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 358 | static int __exit pmagbbfb_remove(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | { |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 360 | struct tc_dev *tdev = to_tc_dev(dev); |
| 361 | struct fb_info *info = dev_get_drvdata(dev); |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 362 | struct pmagbbfb_par *par = info->par; |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 363 | resource_size_t start, len; |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 364 | |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 365 | put_device(dev); |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 366 | unregister_framebuffer(info); |
| 367 | iounmap(par->smem); |
| 368 | iounmap(par->mmio); |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 369 | start = tdev->resource.start; |
| 370 | len = tdev->resource.end - start + 1; |
| 371 | release_mem_region(start, len); |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 372 | fb_dealloc_cmap(&info->cmap); |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 373 | framebuffer_release(info); |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 374 | return 0; |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | |
| 378 | /* |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 379 | * Initialize the framebuffer. |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 380 | */ |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 381 | static const struct tc_device_id pmagbbfb_tc_table[] = { |
| 382 | { "DEC ", "PMAGB-BA" }, |
| 383 | { } |
| 384 | }; |
| 385 | MODULE_DEVICE_TABLE(tc, pmagbbfb_tc_table); |
| 386 | |
| 387 | static struct tc_driver pmagbbfb_driver = { |
| 388 | .id_table = pmagbbfb_tc_table, |
| 389 | .driver = { |
| 390 | .name = "pmagbbfb", |
| 391 | .bus = &tc_bus_type, |
| 392 | .probe = pmagbbfb_probe, |
| 393 | .remove = __exit_p(pmagbbfb_remove), |
| 394 | }, |
| 395 | }; |
| 396 | |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 397 | static int __init pmagbbfb_init(void) |
| 398 | { |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 399 | #ifndef MODULE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | if (fb_get_options("pmagbbfb", NULL)) |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 401 | return -ENXIO; |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 402 | #endif |
| 403 | return tc_register_driver(&pmagbbfb_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 406 | static void __exit pmagbbfb_exit(void) |
| 407 | { |
Maciej W. Rozycki | 9084b00 | 2007-02-05 16:28:29 -0800 | [diff] [blame] | 408 | tc_unregister_driver(&pmagbbfb_driver); |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | module_init(pmagbbfb_init); |
Ralf Baechle | 7901c79 | 2005-09-03 15:56:11 -0700 | [diff] [blame] | 413 | module_exit(pmagbbfb_exit); |
| 414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | MODULE_LICENSE("GPL"); |