igma.c revision 1.1.2.1 1 /* $NetBSD: igma.c,v 1.1.2.1 2014/08/10 06:54:54 tls Exp $ */
2
3 /*
4 * Copyright (c) 2014 Michael van Elst
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 /*
20 * Intel Graphic Media Accelerator
21 */
22
23 #include <sys/cdefs.h>
24 __KERNEL_RCSID(0, "$NetBSD: igma.c,v 1.1.2.1 2014/08/10 06:54:54 tls Exp $");
25
26 #include "vga.h"
27
28 #include <sys/param.h>
29 #include <sys/systm.h>
30 #include <sys/device.h>
31 #include <sys/bus.h>
32
33 #include <dev/pci/pcireg.h>
34 #include <dev/pci/pcivar.h>
35 #include <dev/pci/pcidevs.h>
36 #include <dev/pci/pciio.h>
37
38 #include <dev/i2c/i2cvar.h>
39 #include <dev/i2c/i2c_bitbang.h>
40 #include <dev/i2c/ddcvar.h>
41
42 #include <dev/videomode/videomode.h>
43 #include <dev/videomode/edidvar.h>
44
45 #include <dev/wscons/wsdisplayvar.h>
46
47 #if NVGA > 0
48 #include <dev/ic/mc6845reg.h>
49 #include <dev/ic/pcdisplayvar.h>
50 #include <dev/ic/vgareg.h>
51 #include <dev/ic/vgavar.h>
52 #endif
53
54 #include <dev/pci/igmareg.h>
55 #include <dev/pci/igmavar.h>
56
57 #include "igmafb.h"
58
59 struct igma_softc;
60 struct igma_i2c {
61 kmutex_t ii_lock;
62 struct igma_softc *ii_sc;
63 bus_addr_t ii_reg;
64 struct i2c_controller ii_i2c;
65 const char *ii_name;
66 u_int32_t ii_dir;
67 };
68
69 struct igma_softc {
70 device_t sc_dev;
71 struct igma_chip sc_chip;
72 struct igma_i2c sc_ii[GMBUS_NUM_PORTS];
73 };
74
75 static int igma_match(device_t, cfdata_t, void *);
76 static void igma_attach(device_t, device_t, void *);
77 static int igma_print(void *, const char *);
78
79 static void igma_i2c_attach(struct igma_softc *);
80
81 CFATTACH_DECL_NEW(igma, sizeof(struct igma_softc),
82 igma_match, igma_attach, NULL, NULL);
83
84 static int igma_i2c_acquire_bus(void *, int);
85 static void igma_i2c_release_bus(void *, int);
86 static int igma_i2c_send_start(void *, int);
87 static int igma_i2c_send_stop(void *, int);
88 static int igma_i2c_initiate_xfer(void *, i2c_addr_t, int);
89 static int igma_i2c_read_byte(void *, uint8_t *, int);
90 static int igma_i2c_write_byte(void *, uint8_t, int);
91 static void igma_i2cbb_set_bits(void *, uint32_t);
92 static void igma_i2cbb_set_dir(void *, uint32_t);
93 static uint32_t igma_i2cbb_read(void *);
94
95 static void igma_reg_barrier(const struct igma_chip *, int);
96 static u_int32_t igma_reg_read(const struct igma_chip *, int);
97 static void igma_reg_write(const struct igma_chip *, int, u_int32_t);
98 static u_int8_t igma_vga_read(const struct igma_chip *, int);
99 static void igma_vga_write(const struct igma_chip *, int , u_int8_t);
100 #if 0
101 static u_int8_t igma_crtc_read(const struct igma_chip *, int);
102 static void igma_crtc_write(const struct igma_chip *, int, u_int8_t);
103 #endif
104
105 static const struct i2c_bitbang_ops igma_i2cbb_ops = {
106 igma_i2cbb_set_bits,
107 igma_i2cbb_set_dir,
108 igma_i2cbb_read,
109 { 1, 2, 0, 1 }
110 };
111
112 static const struct igma_chip_ops igma_bus_ops = {
113 igma_reg_barrier,
114 igma_reg_read,
115 igma_reg_write,
116 igma_vga_read,
117 igma_vga_write,
118 #if 0
119 igma_crtc_read,
120 igma_crtc_write,
121 #endif
122 };
123
124 static struct igma_product {
125 u_int16_t product;
126 int gentype;
127 int num_pipes;
128 } const igma_products[] = {
129 /* i830 */
130 { PCI_PRODUCT_INTEL_82830MP_IV, 200,2 },
131 /* i845g */
132 { PCI_PRODUCT_INTEL_82845G_IGD, 200,2 },
133 /* i85x */
134 { PCI_PRODUCT_INTEL_82855GM_IGD, 200,2 },
135 // 0x358e ?
136 /* i865g */
137 { PCI_PRODUCT_INTEL_82865_IGD, 200,2 },
138 /* i915g */
139 { PCI_PRODUCT_INTEL_82915G_IGD, 200,2 },
140 { PCI_PRODUCT_INTEL_E7221_IGD, 200,2 },
141 /* i915gm */
142 { PCI_PRODUCT_INTEL_82915GM_IGD, 300,2 },
143 /* i945g */
144 { PCI_PRODUCT_INTEL_82945P_IGD, 300,2 },
145 /* i945gm */
146 { PCI_PRODUCT_INTEL_82945GM_IGD, 300,2 },
147 { PCI_PRODUCT_INTEL_82945GM_IGD_1, 300,2 },
148 { PCI_PRODUCT_INTEL_82945GME_IGD, 300,2 },
149 /* i965g */
150 { PCI_PRODUCT_INTEL_82946GZ_IGD, 300,2 },
151 { PCI_PRODUCT_INTEL_82G35_IGD, 300,2 },
152 { PCI_PRODUCT_INTEL_82G35_IGD_1, 300,2 },
153 { PCI_PRODUCT_INTEL_82965Q_IGD, 300,2 },
154 { PCI_PRODUCT_INTEL_82965Q_IGD_1, 300,2 },
155 { PCI_PRODUCT_INTEL_82965G_IGD, 300,2 },
156 { PCI_PRODUCT_INTEL_82965G_IGD_1, 300,2 },
157 /* g33 */
158 { PCI_PRODUCT_INTEL_82G33_IGD, 300,2 },
159 { PCI_PRODUCT_INTEL_82G33_IGD_1, 300,2 },
160 { PCI_PRODUCT_INTEL_82Q33_IGD, 300,2 },
161 { PCI_PRODUCT_INTEL_82Q33_IGD_1, 300,2 },
162 { PCI_PRODUCT_INTEL_82Q35_IGD, 300,2 },
163 { PCI_PRODUCT_INTEL_82Q35_IGD_1, 300,2 },
164 /* pineview */
165 { PCI_PRODUCT_INTEL_PINEVIEW_IGD, 350,2 },
166 { PCI_PRODUCT_INTEL_PINEVIEW_M_IGD, 350,2 },
167 /* i965gm */
168 { PCI_PRODUCT_INTEL_82965PM_IGD, 400,2 },
169 { PCI_PRODUCT_INTEL_82965PM_IGD_1, 400,2 },
170 { PCI_PRODUCT_INTEL_82965GME_IGD, 400,2 },
171 /* gm45 */
172 { PCI_PRODUCT_INTEL_82GM45_IGD, 450,2 },
173 { PCI_PRODUCT_INTEL_82GM45_IGD_1, 450,2 },
174 /* g45 */
175 { PCI_PRODUCT_INTEL_82IGD_E_IGD, 450,2 },
176 { PCI_PRODUCT_INTEL_82Q45_IGD, 450,2 },
177 { PCI_PRODUCT_INTEL_82G45_IGD, 450,2 },
178 { PCI_PRODUCT_INTEL_82G41_IGD, 450,2 },
179 { PCI_PRODUCT_INTEL_82B43_IGD, 450,2 },
180 // 0x2e92 ?
181 /* ironlake d */
182 { PCI_PRODUCT_INTEL_IRONLAKE_D_IGD, 500,2 },
183 /* ironlake m */
184 { PCI_PRODUCT_INTEL_IRONLAKE_M_IGD, 500,2 },
185 /* sandy bridge */
186 { PCI_PRODUCT_INTEL_SANDYBRIDGE_IGD, 600,2 },
187 { PCI_PRODUCT_INTEL_SANDYBRIDGE_IGD_1, 600,2 },
188 { PCI_PRODUCT_INTEL_SANDYBRIDGE_IGD_2, 600,2 },
189 /* sandy bridge m */
190 { PCI_PRODUCT_INTEL_SANDYBRIDGE_M_IGD, 600,2 },
191 { PCI_PRODUCT_INTEL_SANDYBRIDGE_M_IGD_1, 600,2 },
192 { PCI_PRODUCT_INTEL_SANDYBRIDGE_M_IGD_2, 600,2 },
193 /* sandy bridge s */
194 { PCI_PRODUCT_INTEL_SANDYBRIDGE_S_IGD, 600,2 },
195 /* ivy bridge */
196 { PCI_PRODUCT_INTEL_IVYBRIDGE_IGD, 700,3 },
197 { PCI_PRODUCT_INTEL_IVYBRIDGE_IGD_1, 700,3 },
198 /* ivy bridge m */
199 { PCI_PRODUCT_INTEL_IVYBRIDGE_M_IGD, 700,3 },
200 { PCI_PRODUCT_INTEL_IVYBRIDGE_M_IGD_1, 700,3 },
201 /* ivy bridge s */
202 { PCI_PRODUCT_INTEL_IVYBRIDGE_S_IGD, 700,3 },
203 { PCI_PRODUCT_INTEL_IVYBRIDGE_S_IGD_1, 700,3 },
204 #if 0
205 /* valleyview d */
206 /* valleyview m */
207 { PCI_PRODUCT_INTEL_HASWELL_IGD_1, 800,3 },
208 /* haswell d */
209 { PCI_PRODUCT_INTEL_HASWELL_IGD, 800,3 },
210 { PCI_PRODUCT_INTEL_HASWELL_IGD_1, 800,3 },
211 /* haswell m */
212 /* broadwell d */
213 /* broadwell m */
214 #endif
215 };
216
217 static int
218 igma_newpch_match(const struct pci_attach_args *pa)
219 {
220 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEL)
221 return 0;
222 switch (0xff00 & PCI_PRODUCT(pa->pa_id)) {
223 case 0x3b00: /* ibex peak */
224 case 0x1c00: /* cougar point */
225 case 0x1e00: /* panther point */
226 case 0x8c00: /* lynx point */
227 case 0x9c00: /* lynx point lp */
228 return 1;
229 }
230
231 return 0;
232 }
233
234 static const struct igma_product *
235 igma_lookup(const struct pci_attach_args *pa)
236 {
237 const struct igma_product *ip;
238 int i;
239
240 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEL)
241 return NULL;
242 for (i=0; i < __arraycount(igma_products); ++i) {
243 ip = &igma_products[i];
244 if (PCI_PRODUCT(pa->pa_id) == ip->product)
245 return ip;
246 }
247 return NULL;
248 }
249
250 static void
251 igma_product_to_chip(const struct pci_attach_args *pa, struct igma_chip *cd)
252 {
253 const struct igma_product *ip;
254 struct pci_attach_args PA;
255
256 ip = igma_lookup(pa);
257 KASSERT(ip != NULL);
258
259 cd->ops = &igma_bus_ops;
260 cd->num_gmbus = 6;
261 cd->num_pipes = ip->num_pipes;
262 cd->quirks = 0;
263 cd->backlight_factor = 1;
264
265 cd->gpio_offset = OLD_GPIOA;
266 cd->vga_cntrl = PCH_VGA_CNTRL;
267 cd->backlight_cntrl = OLD_BLC_PWM_CTL;
268 cd->backlight_cntrl2 = OLD_BLC_PWM_CTL2;
269
270 PA = *pa;
271 if (pci_find_device(&PA, igma_newpch_match)) {
272 cd->gpio_offset = PCH_GPIOA;
273 cd->vga_cntrl = CPU_VGA_CNTRL;
274 cd->backlight_cntrl = CPU_BLC_PWM_CTL;
275 cd->backlight_cntrl2 = CPU_BLC_PWM_CTL2;
276 }
277
278 switch (ip->gentype) {
279 case 200:
280 cd->backlight_factor = 2;
281 break;
282 case 300:
283 case 350:
284 cd->backlight_factor = 2;
285 cd->quirks |= IGMA_PFITDISABLE_QUIRK;
286 break;
287 case 450:
288 cd->pri_cntrl = PRI_CTRL_NOTRICKLE;
289 cd->quirks |= IGMA_PLANESTART_QUIRK;
290 break;
291 default:
292 cd->pri_cntrl = 0;
293 break;
294 }
295 }
296
297 static void
298 igma_adjust_chip(struct igma_softc *sc, struct igma_chip *cd)
299 {
300 const struct igma_chip_ops *co = cd->ops;
301 u_int32_t reg;
302
303 reg = co->read_reg(cd, cd->vga_cntrl);
304 if (reg & VGA_PIPE_B_SELECT)
305 cd->use_pipe = 1;
306 }
307
308 static int
309 igma_print(void *aux, const char *pnp)
310 {
311 if (pnp)
312 aprint_normal("drm at %s", pnp);
313 return (UNCONF);
314 }
315
316 static int
317 igma_match(device_t parent, cfdata_t match, void *aux)
318 {
319 struct pci_attach_args *pa = (struct pci_attach_args *)aux;
320 const struct igma_product *ip;
321
322 if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY)
323 return 0;
324
325 ip = igma_lookup(pa);
326 if (ip != NULL)
327 return 100;
328
329 return 0;
330 }
331
332 static void
333 igma_attach(device_t parent, device_t self, void *aux)
334 {
335 struct igma_softc *sc = device_private(self);
336 const struct pci_attach_args *pa = (struct pci_attach_args *)aux;
337 struct igma_attach_args iaa;
338 bus_space_tag_t gttmmt, gmt, regt;
339 bus_space_handle_t gttmmh, gmh, regh;
340 bus_addr_t gttmmb, gmb;
341
342 pci_aprint_devinfo(pa, NULL);
343
344 sc->sc_dev = self;
345
346 /* Initialize according to chip type */
347 igma_product_to_chip(pa, &sc->sc_chip);
348
349 if (pci_mapreg_map(pa, PCI_BAR0, PCI_MAPREG_TYPE_MEM,
350 BUS_SPACE_MAP_LINEAR,
351 >tmmt, >tmmh, >tmmb, NULL)) {
352 aprint_error_dev(sc->sc_dev, "unable to map GTTMM\n");
353 return;
354 }
355 sc->sc_chip.mmiot = gttmmt;
356 if (bus_space_subregion(gttmmt, gttmmh, 0, 2*1024*1024,
357 &sc->sc_chip.mmioh)) {
358 aprint_error_dev(sc->sc_dev, "unable to submap MMIO\n");
359 return;
360 }
361 sc->sc_chip.gttt = gttmmt;
362 if (bus_space_subregion(gttmmt, gttmmh, 2*1024*1024, 2*1024*1024,
363 &sc->sc_chip.gtth)) {
364 aprint_error_dev(sc->sc_dev, "unable to submap GTT\n");
365 return;
366 }
367
368 if (pci_mapreg_map(pa, PCI_BAR2, PCI_MAPREG_TYPE_MEM,
369 BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE,
370 &gmt, &gmh, &gmb, NULL)) {
371 aprint_error_dev(sc->sc_dev, "unable to map aperture\n");
372 return;
373 }
374 sc->sc_chip.gmt = gmt;
375 sc->sc_chip.gmh = gmh;
376 sc->sc_chip.gmb = gmb;
377
378 if (pci_mapreg_map(pa, PCI_BAR4, PCI_MAPREG_TYPE_IO, 0,
379 ®t, ®h, NULL, NULL)) {
380 aprint_error_dev(sc->sc_dev, "unable to map IO registers\n");
381 return;
382 }
383
384 #if NVGA > 0
385 iaa.iaa_console = vga_cndetach() ? true : false;
386 #else
387 iaa.iaa_console = 0;
388 #endif
389 sc->sc_chip.vgat = regt;
390 if (bus_space_map(regt, 0x3c0, 0x10, 0, &sc->sc_chip.vgah)) {
391 aprint_error_dev(sc->sc_dev, "unable to map VGA registers\n");
392 return;
393 }
394
395 /* Check hardware for more information */
396 igma_adjust_chip(sc, &sc->sc_chip);
397
398 aprint_normal("%s: VGA_CNTRL: 0x%x\n",device_xname(sc->sc_dev),
399 sc->sc_chip.vga_cntrl);
400 aprint_normal("%s: GPIO_OFFSET: 0x%x\n",device_xname(sc->sc_dev),
401 sc->sc_chip.gpio_offset);
402 aprint_normal("%s: BACKLIGHT_CTRL: 0x%x\n",device_xname(sc->sc_dev),
403 sc->sc_chip.backlight_cntrl);
404 aprint_normal("%s: BACKLIGHT_CTRL2: 0x%x\n",device_xname(sc->sc_dev),
405 sc->sc_chip.backlight_cntrl2);
406
407 #if NIGMAFB > 0
408 strcpy(iaa.iaa_name, "igmafb");
409 iaa.iaa_chip = sc->sc_chip;
410 config_found_ia(sc->sc_dev, "igmabus", &iaa, igma_print);
411 #endif
412
413 igma_i2c_attach(sc);
414 }
415
416 static void
417 igma_i2c_attach(struct igma_softc *sc)
418 {
419 struct igma_i2c *ii;
420 int i;
421 #if 0
422 struct i2cbus_attach_args iba;
423 #endif
424
425 for (i=0; i<sc->sc_chip.num_gmbus; ++i) {
426 ii = &sc->sc_ii[i];
427 ii->ii_sc = sc;
428
429 /* XXX */
430 ii->ii_reg = sc->sc_chip.gpio_offset - PCH_GPIOA;
431 switch (i) {
432 case 0:
433 ii->ii_reg += PCH_GPIOB;
434 ii->ii_name = "ssc";
435 break;
436 case 1:
437 ii->ii_reg += PCH_GPIOA;
438 ii->ii_name = "vga";
439 break;
440 case 2:
441 ii->ii_reg += PCH_GPIOC;
442 ii->ii_name = "panel";
443 break;
444 case 3:
445 ii->ii_reg += PCH_GPIOD;
446 ii->ii_name = "dpc";
447 break;
448 case 4:
449 ii->ii_reg += PCH_GPIOE;
450 ii->ii_name = "dpb";
451 break;
452 case 5:
453 ii->ii_reg += PCH_GPIOF;
454 ii->ii_name = "dpd";
455 break;
456 default:
457 panic("don't know GMBUS %d\n",i);
458 }
459
460 mutex_init(&ii->ii_lock, MUTEX_DEFAULT, IPL_NONE);
461
462 ii->ii_i2c.ic_cookie = ii;
463 ii->ii_i2c.ic_acquire_bus = igma_i2c_acquire_bus;
464 ii->ii_i2c.ic_release_bus = igma_i2c_release_bus;
465 ii->ii_i2c.ic_send_start = igma_i2c_send_start;
466 ii->ii_i2c.ic_send_stop = igma_i2c_send_stop;
467 ii->ii_i2c.ic_initiate_xfer = igma_i2c_initiate_xfer;
468 ii->ii_i2c.ic_read_byte = igma_i2c_read_byte;
469 ii->ii_i2c.ic_write_byte = igma_i2c_write_byte;
470 ii->ii_i2c.ic_exec = NULL;
471
472 #if 0
473 iba.iba_type = I2C_TYPE_SMBUS;
474 iba.iba_tag = &ii->ii_i2c;
475 config_found_ia(sc->sc_dev, "i2cbus", &iba, iicbus_print);
476 #endif
477 }
478 }
479
480 /*
481 * I2C interface
482 */
483
484 static int
485 igma_i2c_acquire_bus(void *cookie, int flags)
486 {
487 struct igma_i2c *ii = cookie;
488 mutex_enter(&ii->ii_lock);
489 return 0;
490 }
491
492 static void
493 igma_i2c_release_bus(void *cookie, int flags)
494 {
495 struct igma_i2c *ii = cookie;
496 mutex_exit(&ii->ii_lock);
497 }
498
499 static int
500 igma_i2c_send_start(void *cookie, int flags)
501 {
502 return i2c_bitbang_send_start(cookie, flags, &igma_i2cbb_ops);
503 }
504
505 static int
506 igma_i2c_send_stop(void *cookie, int flags)
507 {
508 return i2c_bitbang_send_stop(cookie, flags, &igma_i2cbb_ops);
509 }
510
511 static int
512 igma_i2c_initiate_xfer(void *cookie, i2c_addr_t addr, int flags)
513 {
514 return i2c_bitbang_initiate_xfer(cookie, addr, flags, &igma_i2cbb_ops);
515 }
516
517 static int
518 igma_i2c_read_byte(void *cookie, uint8_t *valp, int flags)
519 {
520 return i2c_bitbang_read_byte(cookie, valp, flags, &igma_i2cbb_ops);
521 }
522
523 static int
524 igma_i2c_write_byte(void *cookie, uint8_t val, int flags)
525 {
526 return i2c_bitbang_write_byte(cookie, val, flags, &igma_i2cbb_ops);
527 }
528
529 static void
530 igma_i2cbb_set_bits(void *cookie, uint32_t bits)
531 {
532 struct igma_i2c *ii = cookie;
533 struct igma_softc *sc = ii->ii_sc;
534 const struct igma_chip *cd = &sc->sc_chip;
535 const struct igma_chip_ops *co = cd->ops;
536 uint32_t reg;
537
538 reg = co->read_reg(cd, ii->ii_reg);
539 reg &= GPIO_DATA_PULLUP_DISABLE | GPIO_CLOCK_PULLUP_DISABLE;
540
541 if ((bits | ii->ii_dir) & 1)
542 /* make data input, signal is pulled high */
543 reg |= GPIO_DATA_DIR_IN | GPIO_DATA_DIR_MASK;
544 else
545 /* make data output, signal is driven low */
546 reg |= GPIO_DATA_DIR_OUT | GPIO_DATA_DIR_MASK
547 | GPIO_DATA_VAL_MASK;
548
549 if (bits & 2)
550 /* make clock input, signal is pulled high */
551 reg |= GPIO_CLOCK_DIR_IN | GPIO_CLOCK_DIR_MASK;
552 else
553 /* make clock output, signal is driven low */
554 reg |= GPIO_CLOCK_DIR_OUT | GPIO_CLOCK_DIR_MASK
555 | GPIO_CLOCK_VAL_MASK;
556
557 co->write_reg(cd, ii->ii_reg, reg);
558 #if 1
559 reg = co->read_reg(cd, ii->ii_reg);
560 #else
561 co->barrier(cd, ii->ii_reg);
562 #endif
563 }
564
565 static void
566 igma_i2cbb_set_dir(void *cookie, uint32_t bits)
567 {
568 struct igma_i2c *ii = cookie;
569
570 ii->ii_dir = bits;
571 }
572
573 static uint32_t
574 igma_i2cbb_read(void *cookie)
575 {
576 struct igma_i2c *ii = cookie;
577 struct igma_softc *sc = ii->ii_sc;
578 const struct igma_chip *cd = &sc->sc_chip;
579 const struct igma_chip_ops *co = cd->ops;
580 uint32_t reg;
581 int sda, scl;
582
583 reg = co->read_reg(cd, ii->ii_reg);
584
585 sda = reg & GPIO_DATA_VAL_IN;
586 scl = reg & GPIO_CLOCK_VAL_IN;
587
588 reg = (sda ? 1 : 0) | (scl ? 2 : 0);
589 return reg;
590 }
591
592 static void
593 igma_reg_barrier(const struct igma_chip *cd, int r)
594 {
595 bus_space_barrier(cd->mmiot, cd->mmioh, r, sizeof(u_int32_t),
596 BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE);
597 }
598
599 static u_int32_t
600 igma_reg_read(const struct igma_chip *cd, int r)
601 {
602 return bus_space_read_4(cd->mmiot, cd->mmioh, r);
603 }
604
605 static void
606 igma_reg_write(const struct igma_chip *cd, int r, u_int32_t v)
607 {
608 bus_space_write_4(cd->mmiot, cd->mmioh, r, v);
609 }
610
611 static u_int8_t
612 igma_vga_read(const struct igma_chip *cd, int r)
613 {
614 bus_space_write_1(cd->vgat, cd->vgah, 0x4, r | 0x20);
615 return bus_space_read_1(cd->vgat, cd->vgah, 0x5);
616 }
617
618 static void
619 igma_vga_write(const struct igma_chip *cd, int r, u_int8_t v)
620 {
621 bus_space_write_1(cd->vgat, cd->vgah, 0x4, r | 0x20);
622 bus_space_write_1(cd->vgat, cd->vgah, 0x5, v);
623 }
624
625 #if 0
626 static u_int8_t
627 igma_crtc_read(const struct igma_chip *cd, int r)
628 {
629 bus_space_write_1(cd->crtct, cd->crtch, 0x4, r);
630 return bus_space_read_1(cd->crtct, cd->crtch, 0x5);
631 }
632
633 static void
634 igma_crtc_write(const struct igma_chip *cd, int r, u_int8_t v)
635 {
636 bus_space_write_1(cd->crtct, cd->crtch, 0x4, r);
637 bus_space_write_1(cd->crtct, cd->crtch, 0x5, v);
638 }
639 #endif
640