Deleted Added
sdiff udiff text old ( 51658 ) new ( 51694 )
full compact
1/* $FreeBSD: head/sys/dev/bktr/bktr_core.c 51694 1999-09-26 22:06:20Z roger $ */
2
3/*
4 * This is part of the Driver for Video Capture Cards (Frame grabbers)
5 * and TV Tuner cards using the Brooktree Bt848, Bt848A, Bt849A, Bt878, Bt879
6 * chipset.
7 * Copyright Roger Hardiman and Amancio Hasty.
8 *
9 * bktr_core : This deals with the Bt848/849/878/879 PCI Frame Grabber,
10 * Handles all the open, close, ioctl and read userland calls.
11 * Sets the Bt848 registers and generates RISC pograms.
12 * Controls the i2c bus and GPIO interface.
13 * Contains the interface to the kernel.
14 * (eg probe/attach and open/close/ioctl)
15 *
16 */
17
18 /*
19 The Brooktree BT848 Driver driver is based upon Mark Tinguely and
20 Jim Lowe's driver for the Matrox Meteor PCI card . The
21 Philips SAA 7116 and SAA 7196 are very different chipsets than
22 the BT848.
23
24 The original copyright notice by Mark and Jim is included mostly
25 to honor their fantastic work in the Matrox Meteor driver!
26
27 */
28
29/*
30 * 1. Redistributions of source code must retain the
31 * Copyright (c) 1997 Amancio Hasty, 1999 Roger Hardiman
32 * All rights reserved.
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
36 * are met:
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by Amancio Hasty and
45 * Roger Hardiman
46 * 4. The name of the author may not be used to endorse or promote products
47 * derived from this software without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
50 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
51 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
52 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
53 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES

--- 35 unchanged lines hidden (view full) ---

89 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
90 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
91 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
92 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
93 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
94 * POSSIBILITY OF SUCH DAMAGE.
95 */
96
97
98#ifdef __FreeBSD__
99#include "bktr.h"
100#include "opt_bktr.h"
101#include "opt_devfs.h"
102#endif /* __FreeBSD__ */
103
104#if defined(__NetBSD__) || defined(__OpenBSD__)
105#include "bktr.h"

--- 5 unchanged lines hidden (view full) ---

111 || (defined(__bsdi__)) \
112 || (defined(__OpenBSD__)) \
113 || (defined(__NetBSD__)) \
114 )
115
116#include <sys/param.h>
117#include <sys/systm.h>
118#include <sys/conf.h>
119#include <sys/kernel.h>
120#include <sys/signalvar.h>
121#include <sys/vnode.h>
122
123#include <vm/vm.h>
124#include <vm/vm_kern.h>
125#include <vm/pmap.h>
126#include <vm/vm_extern.h>
127
128/*******************/
129/* *** FreeBSD *** */
130/*******************/
131#ifdef __FreeBSD__
132
133#if (__FreeBSD_version >=400000) || (NSMBUS > 0)
134#include <sys/bus.h> /* used by smbus and newbus */
135#endif
136
137#include <machine/clock.h> /* for DELAY */
138#include <pci/pcivar.h>
139
140#include <machine/ioctl_meteor.h>
141#include <machine/ioctl_bt848.h> /* extensions to ioctl_meteor.h */
142#include <dev/bktr/bktr_reg.h>
143#include <dev/bktr/bktr_tuner.h>
144#include <dev/bktr/bktr_card.h>
145#include <dev/bktr/bktr_audio.h>
146#include <dev/bktr/bktr_core.h>
147#include <dev/bktr/bktr_os.h>
148
149#if (NSMBUS > 0)
150#include <dev/bktr/bktr_i2c.h>
151#include <dev/smbus/smbconf.h>
152#include <dev/iicbus/iiconf.h>
153#include "smbus_if.h"
154#include "iicbus_if.h"
155#endif
156
157
158#if (__FreeBSD__ == 2)
159typedef unsigned int uintptr_t;
160#endif
161#endif /* __FreeBSD__ */
162
163
164/****************/
165/* *** BSDI *** */
166/****************/
167#ifdef __bsdi__

--- 52 unchanged lines hidden (view full) ---

220#define VBI_DATA_SIZE (VBI_LINE_SIZE * MAX_VBI_LINES * 2)
221#define VBI_BUFFER_SIZE (VBI_DATA_SIZE * VBI_BUFFER_ITEMS)
222
223
224/* Defines for fields */
225#define ODD_F 0x01
226#define EVEN_F 0x02
227
228
229/*
230 * Parameters describing size of transmitted image.
231 */
232
233static struct format_params format_params[] = {
234/* # define BT848_IFORM_F_AUTO (0x0) - don't matter. */
235 { 525, 26, 480, 910, 135, 754, 640, 780, 30, 0x68, 0x5d, BT848_IFORM_X_AUTO,
236 12, 1600 },
237/* # define BT848_IFORM_F_NTSCM (0x1) */

--- 78 unchanged lines hidden (view full) ---

316#define METEOR_PIXFMT_TABLE_SIZE ( sizeof(meteor_pixfmt_table) / \
317 sizeof(meteor_pixfmt_table[0]) )
318
319
320#define BSWAP (BT848_COLOR_CTL_BSWAP_ODD | BT848_COLOR_CTL_BSWAP_EVEN)
321#define WSWAP (BT848_COLOR_CTL_WSWAP_ODD | BT848_COLOR_CTL_WSWAP_EVEN)
322
323
324
325/* sync detect threshold */
326#if 0
327#define SYNC_LEVEL (BT848_ADC_RESERVED | \
328 BT848_ADC_CRUSH) /* threshold ~125 mV */
329#else
330#define SYNC_LEVEL (BT848_ADC_RESERVED | \
331 BT848_ADC_SYNC_T) /* threshold ~75 mV */
332#endif
333
334
335
336
337/* debug utility for holding previous INT_STAT contents */
338#define STATUS_SUM
339static u_long status_sum = 0;
340
341/*
342 * defines to make certain bit-fiddles understandable
343 */
344#define FIFO_ENABLED BT848_DMA_CTL_FIFO_EN

--- 7 unchanged lines hidden (view full) ---

352
353#define BIT_SEVEN_HIGH (1<<7)
354#define BIT_EIGHT_HIGH (1<<8)
355
356#define I2C_BITS (BT848_INT_RACK | BT848_INT_I2CDONE)
357#define TDEC_BITS (BT848_INT_FDSR | BT848_INT_FBUS)
358
359
360
361static int oformat_meteor_to_bt( u_long format );
362
363static u_int pixfmt_swap_flags( int pixfmt );
364
365/*
366 * bt848 RISC programming routines.
367 */
368#ifdef BT848_DUMP

--- 12 unchanged lines hidden (view full) ---

381 int rows, int interlace );
382static void build_dma_prog( bktr_ptr_t bktr, char i_flag );
383
384static bool_t getline(bktr_reg_t *, int);
385static bool_t notclipped(bktr_reg_t * , int , int);
386static bool_t split(bktr_reg_t *, volatile u_long **, int, u_long, int,
387 volatile u_char ** , int );
388
389static void start_capture( bktr_ptr_t bktr, unsigned type );
390static void set_fps( bktr_ptr_t bktr, u_short fps );
391
392
393
394/*
395 * Remote Control Functions
396 */
397static void remote_read(bktr_ptr_t bktr, struct bktr_remote *remote);
398
399
400/*
401 * ioctls common to both video & tuner.
402 */
403static int common_ioctl( bktr_ptr_t bktr, bt848_ptr_t bt848,
404 int cmd, caddr_t arg );
405
406
407#if ((!defined(__FreeBSD__)) || (NSMBUS == 0) )
408/*
409 * i2c primatives for low level control of i2c bus. Added for MSP34xx control
410 */
411static void i2c_start( bktr_ptr_t bktr);
412static void i2c_stop( bktr_ptr_t bktr);
413static int i2c_write_byte( bktr_ptr_t bktr, unsigned char data);
414static int i2c_read_byte( bktr_ptr_t bktr, unsigned char *data, int last );
415#endif
416
417
418
419/*
420 * the common attach code, used by all OS versions.
421 */
422void
423common_bktr_attach( bktr_ptr_t bktr, int unit, u_long pci_id, u_int rev )
424{
425 bt848_ptr_t bt848;
426 vm_offset_t buf;
427
428 bt848 = bktr->base;
429
430/***************************************/

--- 83 unchanged lines hidden (view full) ---

514 bktr->clr_on_start = FALSE;
515
516 /* defaults for the tuner section of the card */
517 bktr->tflags = TUNER_INITALIZED;
518 bktr->tuner.frequency = 0;
519 bktr->tuner.channel = 0;
520 bktr->tuner.chnlset = DEFAULT_CHNLSET;
521 bktr->tuner.afc = 0;
522 bktr->tuner.radio_mode = 0;
523 bktr->audio_mux_select = 0;
524 bktr->audio_mute_state = FALSE;
525 bktr->bt848_card = -1;
526 bktr->bt848_tuner = -1;
527 bktr->reverse_mute = -1;
528
529 probeCard( bktr, TRUE, unit );
530
531 /* Initialise any MSP34xx or TDA98xx audio chips */
532 init_audio_devices( bktr );
533
534}
535
536
537/* Copy the vbi lines from 'vbidata' into the circular buffer, 'vbibuffer'.
538 * The circular buffer holds 'n' fixed size data blocks.
539 * vbisize is the number of bytes in the circular buffer
540 * vbiread is the point we reading data out of the circular buffer

--- 8 unchanged lines hidden (view full) ---

549
550 /* Copy the VBI data into the next free slot in the buffer. */
551 /* 'dest' is the point in vbibuffer where we want to insert new data */
552 dest = (unsigned char *)bktr->vbibuffer + bktr->vbiinsert;
553 memcpy(dest, (unsigned char*)bktr->vbidata, VBI_DATA_SIZE);
554
555 /* Write the VBI sequence number to the end of the vbi data */
556 /* This is used by the AleVT teletext program */
557 seq_dest = (unsigned int *)((unsigned char *)bktr->vbibuffer
558 + bktr->vbiinsert
559 + (VBI_DATA_SIZE - sizeof(bktr->vbi_sequence_number)));
560 *seq_dest = bktr->vbi_sequence_number;
561
562 /* And increase the VBI sequence number */
563 /* This can wrap around */
564 bktr->vbi_sequence_number++;
565
566

--- 9 unchanged lines hidden (view full) ---

576
577
578/*
579 * the common interrupt handler.
580 * Returns a 0 or 1 depending on whether the interrupt has handled.
581 * In the OS specific section, bktr_intr() is defined which calls this
582 * common interrupt handler.
583 */
584int
585common_bktr_intr( void *arg )
586{
587 bktr_ptr_t bktr;
588 bt848_ptr_t bt848;
589 u_long bktr_status;
590 u_char dstatus;
591 u_long field;
592 u_long w_field;

--- 257 unchanged lines hidden (view full) ---

850}
851
852
853
854
855/*
856 *
857 */
858extern int bt848_format; /* used to set the default format, PAL or NTSC */
859int
860video_open( bktr_ptr_t bktr )
861{
862 bt848_ptr_t bt848;
863 int frame_rate, video_format=0;
864
865 if (bktr->flags & METEOR_OPEN) /* device is busy */
866 return( EBUSY );
867

--- 93 unchanged lines hidden (view full) ---

961 bktr->capture_area_enabled = FALSE;
962
963 bt848->int_mask = BT848_INT_MYSTERYBIT; /* if you take this out triton
964 based motherboards will
965 operate unreliably */
966 return( 0 );
967}
968
969int
970vbi_open( bktr_ptr_t bktr )
971{
972 if (bktr->vbiflags & VBI_OPEN) /* device is busy */
973 return( EBUSY );
974
975 bktr->vbiflags |= VBI_OPEN;
976
977 /* reset the VBI circular buffer pointers and clear the buffers */

--- 7 unchanged lines hidden (view full) ---

985 bzero((caddr_t) bktr->vbidata, VBI_DATA_SIZE);
986
987 return( 0 );
988}
989
990/*
991 *
992 */
993int
994tuner_open( bktr_ptr_t bktr )
995{
996 if ( !(bktr->tflags & TUNER_INITALIZED) ) /* device not found */
997 return( ENXIO );
998
999 if ( bktr->tflags & TUNER_OPEN ) /* already open */
1000 return( 0 );
1001
1002 bktr->tflags |= TUNER_OPEN;
1003 bktr->tuner.frequency = 0;
1004 bktr->tuner.channel = 0;
1005 bktr->tuner.chnlset = DEFAULT_CHNLSET;
1006 bktr->tuner.afc = 0;
1007 bktr->tuner.radio_mode = 0;
1008
1009 /* enable drivers on the GPIO port that control the MUXes */
1010 bktr->base->gpio_out_en |= bktr->card.gpio_mux_bits;
1011
1012 /* unmute the audio stream */
1013 set_audio( bktr, AUDIO_UNMUTE );
1014
1015 /* Initialise any audio chips, eg MSP34xx or TDA98xx */
1016 init_audio_devices( bktr );
1017
1018 return( 0 );
1019}
1020
1021
1022
1023
1024/*
1025 *
1026 */
1027int
1028video_close( bktr_ptr_t bktr )
1029{
1030 bt848_ptr_t bt848;
1031
1032 bktr->flags &= ~(METEOR_OPEN |
1033 METEOR_SINGLE |
1034 METEOR_CAP_MASK |
1035 METEOR_WANT_MASK);

--- 13 unchanged lines hidden (view full) ---

1049 return( 0 );
1050}
1051
1052
1053/*
1054 * tuner close handle,
1055 * place holder for tuner specific operations on a close.
1056 */
1057int
1058tuner_close( bktr_ptr_t bktr )
1059{
1060 bktr->tflags &= ~TUNER_OPEN;
1061
1062 /* mute the audio by switching the mux */
1063 set_audio( bktr, AUDIO_MUTE );
1064
1065 /* disable drivers on the GPIO port that control the MUXes */
1066 bktr->base->gpio_out_en = bktr->base->gpio_out_en & ~bktr->card.gpio_mux_bits;
1067
1068 return( 0 );
1069}
1070
1071int
1072vbi_close( bktr_ptr_t bktr )
1073{
1074
1075 bktr->vbiflags &= ~VBI_OPEN;
1076
1077 return( 0 );
1078}
1079
1080/*
1081 *
1082 */
1083int
1084video_read(bktr_ptr_t bktr, int unit, dev_t dev, struct uio *uio)
1085{
1086 bt848_ptr_t bt848;
1087 int status;
1088 int count;
1089
1090
1091 bt848 = bktr->base;

--- 40 unchanged lines hidden (view full) ---

1132
1133/*
1134 * Read VBI data from the vbi circular buffer
1135 * The buffer holds vbi data blocks which are the same size
1136 * vbiinsert is the position we will insert the next item into the buffer
1137 * vbistart is the actual position in the buffer we want to read from
1138 * vbisize is the exact number of bytes in the buffer left to read
1139 */
1140int
1141vbi_read(bktr_ptr_t bktr, struct uio *uio, int ioflag)
1142{
1143 int readsize, readsize2;
1144 int status;
1145
1146
1147 while(bktr->vbisize == 0) {
1148 if (ioflag & IO_NDELAY) {

--- 30 unchanged lines hidden (view full) ---

1179
1180 /* Update the number of bytes left to read */
1181 bktr->vbisize -= readsize;
1182
1183 /* Update vbistart */
1184 bktr->vbistart += readsize;
1185 bktr->vbistart = bktr->vbistart % VBI_BUFFER_SIZE; /* wrap around if needed */
1186
1187 return( status );
1188
1189}
1190
1191
1192
1193/*
1194 * video ioctls
1195 */
1196int
1197video_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr )
1198{
1199 bt848_ptr_t bt848;
1200 volatile u_char c_temp;
1201 unsigned int temp;
1202 unsigned int temp_iform;
1203 unsigned int error;
1204 struct meteor_geomet *geo;

--- 587 unchanged lines hidden (view full) ---

1792 }
1793
1794 return( 0 );
1795}
1796
1797/*
1798 * tuner ioctls
1799 */
1800int
1801tuner_ioctl( bktr_ptr_t bktr, int unit, int cmd, caddr_t arg, struct proc* pr )
1802{
1803 bt848_ptr_t bt848;
1804 int tmp_int;
1805 unsigned int temp, temp1;
1806 int offset;
1807 int count;
1808 u_char *buf;

--- 22 unchanged lines hidden (view full) ---

1831 *(int *)arg = bktr->tuner.afc;
1832 /* XXX Perhaps use another bit to indicate AFC success? */
1833 break;
1834#endif /* TUNER_AFC */
1835
1836 case TVTUNER_SETCHNL:
1837 temp_mute( bktr, TRUE );
1838 temp = tv_channel( bktr, (int)*(unsigned long *)arg );
1839 if ( temp < 0 ) {
1840 temp_mute( bktr, FALSE );
1841 return( EINVAL );
1842 }
1843 *(unsigned long *)arg = temp;
1844
1845 /* after every channel change, we must restart the MSP34xx */
1846 /* audio chip to reselect NICAM STEREO or MONO audio */
1847 if ( bktr->card.msp3400c )
1848 msp_autodetect( bktr );
1849
1850 temp_mute( bktr, FALSE );
1851 break;
1852
1853 case TVTUNER_GETCHNL:
1854 *(unsigned long *)arg = bktr->tuner.channel;
1855 break;
1856
1857 case TVTUNER_SETTYPE:
1858 temp = *(unsigned long *)arg;
1859 if ( (temp < CHNLSET_MIN) || (temp > CHNLSET_MAX) )
1860 return( EINVAL );
1861 bktr->tuner.chnlset = temp;
1862 break;
1863
1864 case TVTUNER_GETTYPE:
1865 *(unsigned long *)arg = bktr->tuner.chnlset;
1866 break;
1867
1868 case TVTUNER_GETSTATUS:
1869 temp = get_tuner_status( bktr );
1870 *(unsigned long *)arg = temp & 0xff;
1871 break;
1872
1873 case TVTUNER_SETFREQ:
1874 temp_mute( bktr, TRUE );
1875 temp = tv_freq( bktr, (int)*(unsigned long *)arg, TV_FREQUENCY);
1876 temp_mute( bktr, FALSE );
1877 if ( temp < 0 ) {
1878 temp_mute( bktr, FALSE );
1879 return( EINVAL );
1880 }
1881 *(unsigned long *)arg = temp;
1882
1883 /* after every channel change, we must restart the MSP34xx */
1884 /* audio chip to reselect NICAM STEREO or MONO audio */
1885 if ( bktr->card.msp3400c )
1886 msp_autodetect( bktr );
1887
1888 temp_mute( bktr, FALSE );
1889 break;
1890
1891 case TVTUNER_GETFREQ:
1892 *(unsigned long *)arg = bktr->tuner.frequency;
1893 break;
1894
1895 case TVTUNER_GETCHNLSET:
1896 return tuner_getchnlset((struct bktr_chnlset *)arg);

--- 222 unchanged lines hidden (view full) ---

2119 *(unsigned char *)arg = bktr->tuner.radio_mode;
2120 break;
2121
2122 case RADIO_SETMODE:
2123 bktr->tuner.radio_mode = *(unsigned char *)arg;
2124 break;
2125
2126 case RADIO_GETFREQ:
2127 *(unsigned long *)arg = bktr->tuner.frequency;
2128 break;
2129
2130 case RADIO_SETFREQ:
2131 /* The argument to this ioctl is NOT freq*16. It is
2132 ** freq*100.
2133 */
2134
2135 temp=(int)*(unsigned long *)arg;
2136
2137#ifdef BKTR_RADIO_DEBUG
2138 printf("bktr%d: arg=%d temp=%d\n",unit,(int)*(unsigned long *)arg,temp);
2139#endif
2140
2141#ifndef BKTR_RADIO_NOFREQCHECK
2142 /* According to the spec. sheet the band: 87.5MHz-108MHz */
2143 /* is supported. */
2144 if(temp<8750 || temp>10800) {
2145 printf("bktr%d: Radio frequency out of range\n",unit);
2146 return(EINVAL);
2147 }
2148#endif
2149 temp_mute( bktr, TRUE );
2150 temp = tv_freq( bktr, temp, FM_RADIO_FREQUENCY );
2151 temp_mute( bktr, FALSE );
2152#ifdef BKTR_RADIO_DEBUG
2153 if(temp)
2154 printf("bktr%d: tv_freq returned: %d\n",unit,temp);
2155#endif
2156 if ( temp < 0 )
2157 return( EINVAL );
2158 *(unsigned long *)arg = temp;
2159 break;
2160
2161 /* Luigi's I2CWR ioctl */
2162 case BT848_I2CWR:
2163 par = *(u_long *)arg;
2164 write = (par >> 24) & 0xff ;
2165 i2c_addr = (par >> 16) & 0xff ;
2166 i2c_port = (par >> 8) & 0xff ;
2167 data = (par) & 0xff ;
2168
2169 if (write) {

--- 413 unchanged lines hidden (view full) ---

2583 */
2584static void
2585rgb_vbi_prog( bktr_ptr_t bktr, char i_flag, int cols, int rows, int interlace )
2586{
2587 int i;
2588 bt848_ptr_t bt848;
2589 volatile u_long target_buffer, buffer, target,width;
2590 volatile u_long pitch;
2591 volatile u_long *dma_prog; /* DMA prog is an array of
2592 32 bit RISC instructions */
2593 volatile u_long *loop_point;
2594 struct meteor_pixfmt_internal *pf_int = &pixfmt_table[ bktr->pixfmt ];
2595 u_int Bpp = pf_int->public.Bpp;
2596 unsigned int vbisamples; /* VBI samples per line */
2597 unsigned int vbilines; /* VBI lines per field */
2598 unsigned int num_dwords; /* DWORDS per line */
2599

--- 1084 unchanged lines hidden (view full) ---

3684 BT848_DATA_CTL_I2CSDA)
3685
3686/* Select between old i2c code and new iicbus / smbus code */
3687#if (defined(__FreeBSD__) && (NSMBUS > 0))
3688
3689/*
3690 * The hardware interface is actually SMB commands
3691 */
3692int
3693i2cWrite( bktr_ptr_t bktr, int addr, int byte1, int byte2 )
3694{
3695 char cmd;
3696
3697 if (bktr->id == BROOKTREE_848 ||
3698 bktr->id == BROOKTREE_848A ||
3699 bktr->id == BROOKTREE_849A)
3700 cmd = I2C_COMMAND;

--- 9 unchanged lines hidden (view full) ---

3710 (char)(byte1 & 0xff)))
3711 return (-1);
3712 }
3713
3714 /* return OK */
3715 return( 0 );
3716}
3717
3718int
3719i2cRead( bktr_ptr_t bktr, int addr )
3720{
3721 char result;
3722 char cmd;
3723
3724 if (bktr->id == BROOKTREE_848 ||
3725 bktr->id == BROOKTREE_848A ||
3726 bktr->id == BROOKTREE_849A)

--- 9 unchanged lines hidden (view full) ---

3736
3737#define IICBUS(bktr) ((bktr)->i2c_sc.iicbus)
3738
3739/* The MSP34xx Audio chip require i2c bus writes of up to 5 bytes which the */
3740/* bt848 automated i2c bus controller cannot handle */
3741/* Therefore we need low level control of the i2c bus hardware */
3742
3743/* Write to the MSP registers */
3744void
3745msp_write(bktr_ptr_t bktr, unsigned char dev, unsigned int addr, unsigned int data)
3746{
3747 unsigned char addr_l, addr_h, data_h, data_l ;
3748
3749 addr_h = (addr >>8) & 0xff;
3750 addr_l = addr & 0xff;
3751 data_h = (data >>8) & 0xff;
3752 data_l = data & 0xff;
3753
3754 iicbus_start(IICBUS(bktr), bktr->msp_addr, 0 /* no timeout? */);
3755
3756 iicbus_write_byte(IICBUS(bktr), dev, 0);
3757 iicbus_write_byte(IICBUS(bktr), addr_h, 0);
3758 iicbus_write_byte(IICBUS(bktr), addr_l, 0);
3759 iicbus_write_byte(IICBUS(bktr), data_h, 0);
3760 iicbus_write_byte(IICBUS(bktr), data_l, 0);
3761
3762 iicbus_stop(IICBUS(bktr));
3763
3764 return;
3765}
3766
3767/* Write to the MSP registers */
3768unsigned int
3769msp_read(bktr_ptr_t bktr, unsigned char dev, unsigned int addr)
3770{
3771 unsigned int data;
3772 unsigned char addr_l, addr_h, dev_r;
3773 int read;
3774 u_char data_read[2];
3775
3776 addr_h = (addr >>8) & 0xff;
3777 addr_l = addr & 0xff;
3778 dev_r = dev+1;
3779
3780 /* XXX errors ignored */
3781 iicbus_start(IICBUS(bktr), bktr->msp_addr, 0 /* no timeout? */);
3782
3783 iicbus_write_byte(IICBUS(bktr), dev_r, 0);
3784 iicbus_write_byte(IICBUS(bktr), addr_h, 0);
3785 iicbus_write_byte(IICBUS(bktr), addr_l, 0);
3786
3787 iicbus_repeated_start(IICBUS(bktr), bktr->msp_addr +1, 0 /* no timeout? */);
3788 iicbus_read(IICBUS(bktr), data_read, 2, &read, IIC_LAST_READ, 0);
3789 iicbus_stop(IICBUS(bktr));
3790
3791 data = (data_read[0]<<8) | data_read[1];
3792
3793 return (data);
3794}
3795
3796/* Reset the MSP chip */
3797/* The user can block the reset (which is handy if you initialise the
3798 * MSP audio in another operating system first (eg in Windows)
3799 */
3800void
3801msp_reset( bktr_ptr_t bktr )
3802{
3803
3804#ifndef BKTR_NO_MSP_RESET
3805 /* put into reset mode */
3806 iicbus_start(IICBUS(bktr), bktr->msp_addr, 0 /* no timeout? */);
3807 iicbus_write_byte(IICBUS(bktr), 0x00, 0);
3808 iicbus_write_byte(IICBUS(bktr), 0x80, 0);
3809 iicbus_write_byte(IICBUS(bktr), 0x00, 0);
3810 iicbus_stop(IICBUS(bktr));
3811
3812 /* put back to operational mode */
3813 iicbus_start(IICBUS(bktr), bktr->msp_addr, 0 /* no timeout? */);
3814 iicbus_write_byte(IICBUS(bktr), 0x00, 0);
3815 iicbus_write_byte(IICBUS(bktr), 0x00, 0);
3816 iicbus_write_byte(IICBUS(bktr), 0x00, 0);
3817 iicbus_stop(IICBUS(bktr));
3818#endif
3819 return;
3820}
3821

--- 8 unchanged lines hidden (view full) ---

3830 return;
3831}
3832
3833#else /* defined(__FreeBSD__) && (NSMBUS > 0) */
3834
3835/*
3836 * Program the i2c bus directly
3837 */
3838int
3839i2cWrite( bktr_ptr_t bktr, int addr, int byte1, int byte2 )
3840{
3841 u_long x;
3842 u_long data;
3843 bt848_ptr_t bt848;
3844
3845 bt848 = bktr->base;
3846

--- 29 unchanged lines hidden (view full) ---

3876 /* return OK */
3877 return( 0 );
3878}
3879
3880
3881/*
3882 *
3883 */
3884int
3885i2cRead( bktr_ptr_t bktr, int addr )
3886{
3887 u_long x;
3888 bt848_ptr_t bt848;
3889
3890 bt848 = bktr->base;
3891
3892 /* clear status bits */

--- 122 unchanged lines hidden (view full) ---

4015 }
4016
4017 *data=byte;
4018 return 0;
4019}
4020#undef BITD
4021
4022/* Write to the MSP registers */
4023void msp_write( bktr_ptr_t bktr, unsigned char dev, unsigned int addr, unsigned int data){
4024 unsigned int msp_w_addr = bktr->msp_addr;
4025 unsigned char addr_l, addr_h, data_h, data_l ;
4026 addr_h = (addr >>8) & 0xff;
4027 addr_l = addr & 0xff;
4028 data_h = (data >>8) & 0xff;
4029 data_l = data & 0xff;
4030
4031 i2c_start(bktr);
4032 i2c_write_byte(bktr, msp_w_addr);
4033 i2c_write_byte(bktr, dev);
4034 i2c_write_byte(bktr, addr_h);
4035 i2c_write_byte(bktr, addr_l);
4036 i2c_write_byte(bktr, data_h);
4037 i2c_write_byte(bktr, data_l);
4038 i2c_stop(bktr);
4039}
4040
4041/* Write to the MSP registers */
4042unsigned int msp_read(bktr_ptr_t bktr, unsigned char dev, unsigned int addr){
4043 unsigned int data;
4044 unsigned char addr_l, addr_h, data_1, data_2, dev_r ;
4045 addr_h = (addr >>8) & 0xff;
4046 addr_l = addr & 0xff;
4047 dev_r = dev+1;
4048
4049 i2c_start(bktr);
4050 i2c_write_byte(bktr,bktr->msp_addr);
4051 i2c_write_byte(bktr,dev_r);
4052 i2c_write_byte(bktr,addr_h);
4053 i2c_write_byte(bktr,addr_l);
4054
4055 i2c_start(bktr);
4056 i2c_write_byte(bktr,bktr->msp_addr+1);
4057 i2c_read_byte(bktr,&data_1, 0);
4058 i2c_read_byte(bktr,&data_2, 1);
4059 i2c_stop(bktr);
4060 data = (data_1<<8) | data_2;
4061 return data;
4062}
4063
4064/* Reset the MSP chip */
4065/* The user can block the reset (which is handy if you initialise the
4066 * MSP audio in another operating system first (eg in Windows)
4067 */
4068void msp_reset( bktr_ptr_t bktr ) {
4069
4070#ifndef BKTR_NO_MSP_RESET
4071 /* put into reset mode */
4072 i2c_start(bktr);
4073 i2c_write_byte(bktr, bktr->msp_addr);
4074 i2c_write_byte(bktr, 0x00);
4075 i2c_write_byte(bktr, 0x80);
4076 i2c_write_byte(bktr, 0x00);
4077 i2c_stop(bktr);
4078
4079 /* put back to operational mode */
4080 i2c_start(bktr);
4081 i2c_write_byte(bktr, bktr->msp_addr);
4082 i2c_write_byte(bktr, 0x00);
4083 i2c_write_byte(bktr, 0x00);
4084 i2c_write_byte(bktr, 0x00);
4085 i2c_stop(bktr);
4086#endif
4087 return;
4088
4089}

--- 81 unchanged lines hidden (view full) ---

4171 return( status );
4172}
4173#undef EXTRA_START
4174#undef BITD
4175
4176#endif /* I2C_SOFTWARE_PROBE */
4177
4178
4179#define ABSENT (-1)
4180
4181#endif /* FreeBSD, BSDI, NetBSD, OpenBSD */
4182