Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6a59d64c authored by Trent Piepho's avatar Trent Piepho Committed by Mauro Carvalho Chehab
Browse files

V4L/DVB (6021): cx88: Copy board information into card state



The cx88 driver state stored the ID of the board type in core->board.  Every
time the driver need to get some information about the board configuration, it
uses the board number as an index into board configuration array.

This patch changes it so that the board number is in core->boardnr, and
core->board is a copy of the board configuration information.  This allows
access to board information without the extra indirection.  e.g.
cx88_boards[core->board].mpeg becomes core->board.mpeg.

This has a number of advantages:
- The code is simpler to write.

- It compiles to be smaller and faster, without needing the extra array lookup
  to get at the board information.

- The cx88_boards array no longer needs to be exported to all cx88 modules.

- The boards array can be made const

- It should be possible to avoid keeping the (large) cx88_boards array around
  after the module is loaded.

- If module parameters or eeprom info override some board configuration
  setting, it's not necessary to modify the boards array, which would
  affect all boards of the same type.

Signed-off-by: default avatarTrent Piepho <xyzzy@speakeasy.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent b09a79f5
Loading
Loading
Loading
Loading
+9 −9
Original line number Original line Diff line number Diff line
@@ -734,14 +734,14 @@ static int vidioc_querycap (struct file *file, void *priv,
	struct cx88_core  *core = dev->core;
	struct cx88_core  *core = dev->core;


	strcpy(cap->driver, "cx88_blackbird");
	strcpy(cap->driver, "cx88_blackbird");
	strlcpy(cap->card, cx88_boards[core->board].name,sizeof(cap->card));
	strlcpy(cap->card, core->board.name, sizeof(cap->card));
	sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
	sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
	cap->version = CX88_VERSION_CODE;
	cap->version = CX88_VERSION_CODE;
	cap->capabilities =
	cap->capabilities =
		V4L2_CAP_VIDEO_CAPTURE |
		V4L2_CAP_VIDEO_CAPTURE |
		V4L2_CAP_READWRITE     |
		V4L2_CAP_READWRITE     |
		V4L2_CAP_STREAMING;
		V4L2_CAP_STREAMING;
	if (UNSET != core->tuner_type)
	if (UNSET != core->board.tuner_type)
		cap->capabilities |= V4L2_CAP_TUNER;
		cap->capabilities |= V4L2_CAP_TUNER;
	return 0;
	return 0;
}
}
@@ -990,7 +990,7 @@ static int vidioc_g_frequency (struct file *file, void *priv,
	struct cx8802_fh  *fh   = priv;
	struct cx8802_fh  *fh   = priv;
	struct cx88_core  *core = fh->dev->core;
	struct cx88_core  *core = fh->dev->core;


	if (unlikely(UNSET == core->tuner_type))
	if (unlikely(UNSET == core->board.tuner_type))
		return -EINVAL;
		return -EINVAL;


	f->type = V4L2_TUNER_ANALOG_TV;
	f->type = V4L2_TUNER_ANALOG_TV;
@@ -1028,7 +1028,7 @@ static int vidioc_g_tuner (struct file *file, void *priv,
	struct cx88_core  *core = ((struct cx8802_fh *)priv)->dev->core;
	struct cx88_core  *core = ((struct cx8802_fh *)priv)->dev->core;
	u32 reg;
	u32 reg;


	if (unlikely(UNSET == core->tuner_type))
	if (unlikely(UNSET == core->board.tuner_type))
		return -EINVAL;
		return -EINVAL;
	if (0 != t->index)
	if (0 != t->index)
		return -EINVAL;
		return -EINVAL;
@@ -1049,7 +1049,7 @@ static int vidioc_s_tuner (struct file *file, void *priv,
{
{
	struct cx88_core  *core = ((struct cx8802_fh *)priv)->dev->core;
	struct cx88_core  *core = ((struct cx8802_fh *)priv)->dev->core;


	if (UNSET == core->tuner_type)
	if (UNSET == core->board.tuner_type)
		return -EINVAL;
		return -EINVAL;
	if (0 != t->index)
	if (0 != t->index)
		return -EINVAL;
		return -EINVAL;
@@ -1246,7 +1246,7 @@ static int cx8802_blackbird_advise_acquire(struct cx8802_driver *drv)
	struct cx88_core *core = drv->core;
	struct cx88_core *core = drv->core;
	int err = 0;
	int err = 0;


	switch (core->board) {
	switch (core->boardnr) {
	case CX88_BOARD_HAUPPAUGE_HVR1300:
	case CX88_BOARD_HAUPPAUGE_HVR1300:
		/* By default, core setup will leave the cx22702 out of reset, on the bus.
		/* By default, core setup will leave the cx22702 out of reset, on the bus.
		 * We left the hardware on power up with the cx22702 active.
		 * We left the hardware on power up with the cx22702 active.
@@ -1268,7 +1268,7 @@ static int cx8802_blackbird_advise_release(struct cx8802_driver *drv)
	struct cx88_core *core = drv->core;
	struct cx88_core *core = drv->core;
	int err = 0;
	int err = 0;


	switch (core->board) {
	switch (core->boardnr) {
	case CX88_BOARD_HAUPPAUGE_HVR1300:
	case CX88_BOARD_HAUPPAUGE_HVR1300:
		/* Exit leaving the cx23416 on the bus */
		/* Exit leaving the cx23416 on the bus */
		break;
		break;
@@ -1316,13 +1316,13 @@ static int cx8802_blackbird_probe(struct cx8802_driver *drv)


	dprintk( 1, "%s\n", __FUNCTION__);
	dprintk( 1, "%s\n", __FUNCTION__);
	dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
	dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
		core->board,
		core->boardnr,
		core->name,
		core->name,
		core->pci_bus,
		core->pci_bus,
		core->pci_slot);
		core->pci_slot);


	err = -ENODEV;
	err = -ENODEV;
	if (!(cx88_boards[core->board].mpeg & CX88_MPEG_BLACKBIRD))
	if (!(core->board.mpeg & CX88_MPEG_BLACKBIRD))
		goto fail_core;
		goto fail_core;


	dev->width = 720;
	dev->width = 720;
+12 −15
Original line number Original line Diff line number Diff line
@@ -30,7 +30,7 @@
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
/* board config info                                                  */
/* board config info                                                  */


struct cx88_board cx88_boards[] = {
const struct cx88_board cx88_boards[] = {
	[CX88_BOARD_UNKNOWN] = {
	[CX88_BOARD_UNKNOWN] = {
		.name		= "UNKNOWN/GENERIC",
		.name		= "UNKNOWN/GENERIC",
		.tuner_type     = UNSET,
		.tuner_type     = UNSET,
@@ -1687,12 +1687,12 @@ static void leadtek_eeprom(struct cx88_core *core, u8 *eeprom_data)
		return;
		return;
	}
	}


	core->has_radio  = 1;
	core->board.tuner_type = (eeprom_data[6] == 0x13) ?
	core->tuner_type = (eeprom_data[6] == 0x13) ? 43 : 38;
		TUNER_PHILIPS_FM1236_MK3 : TUNER_PHILIPS_FM1216ME_MK3;


	printk(KERN_INFO "%s: Leadtek Winfast 2000XP Expert config: "
	printk(KERN_INFO "%s: Leadtek Winfast 2000XP Expert config: "
	       "tuner=%d, eeprom[0]=0x%02x\n",
	       "tuner=%d, eeprom[0]=0x%02x\n",
	       core->name, core->tuner_type, eeprom_data[0]);
	       core->name, core->board.tuner_type, eeprom_data[0]);
}
}


static void hauppauge_eeprom(struct cx88_core *core, u8 *eeprom_data)
static void hauppauge_eeprom(struct cx88_core *core, u8 *eeprom_data)
@@ -1700,9 +1700,9 @@ static void hauppauge_eeprom(struct cx88_core *core, u8 *eeprom_data)
	struct tveeprom tv;
	struct tveeprom tv;


	tveeprom_hauppauge_analog(&core->i2c_client, &tv, eeprom_data);
	tveeprom_hauppauge_analog(&core->i2c_client, &tv, eeprom_data);
	core->tuner_type = tv.tuner_type;
	core->board.tuner_type = tv.tuner_type;
	core->tuner_formats = tv.tuner_formats;
	core->tuner_formats = tv.tuner_formats;
	core->has_radio  = tv.has_radio;
	core->board.radio.type = tv.has_radio ? CX88_RADIO : 0;


	/* Make sure we support the board model */
	/* Make sure we support the board model */
	switch (tv.model)
	switch (tv.model)
@@ -1792,8 +1792,9 @@ static void gdi_eeprom(struct cx88_core *core, u8 *eeprom_data)
	       name ? name : "unknown");
	       name ? name : "unknown");
	if (NULL == name)
	if (NULL == name)
		return;
		return;
	core->tuner_type = gdi_tuner[eeprom_data[0x0d]].id;
	core->board.tuner_type = gdi_tuner[eeprom_data[0x0d]].id;
	core->has_radio  = gdi_tuner[eeprom_data[0x0d]].fm;
	core->board.radio.type = gdi_tuner[eeprom_data[0x0d]].fm ?
		CX88_RADIO : 0;
}
}


/* ----------------------------------------------------------------------- */
/* ----------------------------------------------------------------------- */
@@ -1860,7 +1861,7 @@ void cx88_card_list(struct cx88_core *core, struct pci_dev *pci)


void cx88_card_setup_pre_i2c(struct cx88_core *core)
void cx88_card_setup_pre_i2c(struct cx88_core *core)
{
{
	switch (core->board) {
	switch (core->boardnr) {
	case CX88_BOARD_HAUPPAUGE_HVR1300:
	case CX88_BOARD_HAUPPAUGE_HVR1300:
		/* Bring the 702 demod up before i2c scanning/attach or devices are hidden */
		/* Bring the 702 demod up before i2c scanning/attach or devices are hidden */
		/* We leave here with the 702 on the bus */
		/* We leave here with the 702 on the bus */
@@ -1883,7 +1884,7 @@ void cx88_card_setup(struct cx88_core *core)
		tveeprom_read(&core->i2c_client,eeprom,sizeof(eeprom));
		tveeprom_read(&core->i2c_client,eeprom,sizeof(eeprom));
	}
	}


	switch (core->board) {
	switch (core->boardnr) {
	case CX88_BOARD_HAUPPAUGE:
	case CX88_BOARD_HAUPPAUGE:
	case CX88_BOARD_HAUPPAUGE_ROSLYN:
	case CX88_BOARD_HAUPPAUGE_ROSLYN:
		if (0 == core->i2c_rc)
		if (0 == core->i2c_rc)
@@ -1927,7 +1928,7 @@ void cx88_card_setup(struct cx88_core *core)
		msleep(1);
		msleep(1);
		cx_set(MO_GP0_IO, 0x00000101);
		cx_set(MO_GP0_IO, 0x00000101);
		if (0 == core->i2c_rc &&
		if (0 == core->i2c_rc &&
		    core->board == CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID)
		    core->boardnr == CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID)
			dvico_fusionhdtv_hybrid_init(core);
			dvico_fusionhdtv_hybrid_init(core);
		break;
		break;
	case CX88_BOARD_KWORLD_DVB_T:
	case CX88_BOARD_KWORLD_DVB_T:
@@ -1965,14 +1966,10 @@ void cx88_card_setup(struct cx88_core *core)
		}
		}
		break;
		break;
	}
	}
	if (cx88_boards[core->board].radio.type == CX88_RADIO)
		core->has_radio = 1;
}
}


/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */


EXPORT_SYMBOL(cx88_boards);

/*
/*
 * Local variables:
 * Local variables:
 * c-basic-offset: 8
 * c-basic-offset: 8
+20 −25
Original line number Original line Diff line number Diff line
@@ -738,7 +738,7 @@ int cx88_set_scale(struct cx88_core *core, unsigned int width, unsigned int heig
		value |= (1 << 15);
		value |= (1 << 15);
		value |= (1 << 16);
		value |= (1 << 16);
	}
	}
	if (INPUT(core->input)->type == CX88_VMUX_SVIDEO)
	if (INPUT(core->input).type == CX88_VMUX_SVIDEO)
		value |= (1 << 13) | (1 << 5);
		value |= (1 << 13) | (1 << 5);
	if (V4L2_FIELD_INTERLACED == field)
	if (V4L2_FIELD_INTERLACED == field)
		value |= (1 << 3); // VINT (interlaced vertical scaling)
		value |= (1 << 3); // VINT (interlaced vertical scaling)
@@ -833,7 +833,7 @@ static int set_tvaudio(struct cx88_core *core)
{
{
	v4l2_std_id norm = core->tvnorm;
	v4l2_std_id norm = core->tvnorm;


	if (CX88_VMUX_TELEVISION != INPUT(core->input)->type)
	if (CX88_VMUX_TELEVISION != INPUT(core->input).type)
		return 0;
		return 0;


	if (V4L2_STD_PAL_BG & norm) {
	if (V4L2_STD_PAL_BG & norm) {
@@ -1067,7 +1067,7 @@ struct video_device *cx88_vdev_init(struct cx88_core *core,
	vfd->dev     = &pci->dev;
	vfd->dev     = &pci->dev;
	vfd->release = video_device_release;
	vfd->release = video_device_release;
	snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
	snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
		 core->name, type, cx88_boards[core->board].name);
		 core->name, type, core->board.name);
	return vfd;
	return vfd;
}
}


@@ -1130,39 +1130,34 @@ struct cx88_core* cx88_core_get(struct pci_dev *pci)
	core->bmmio = (u8 __iomem *)core->lmmio;
	core->bmmio = (u8 __iomem *)core->lmmio;


	/* board config */
	/* board config */
	core->board = UNSET;
	core->boardnr = UNSET;
	if (card[core->nr] < cx88_bcount)
	if (card[core->nr] < cx88_bcount)
		core->board = card[core->nr];
		core->boardnr = card[core->nr];
	for (i = 0; UNSET == core->board  &&  i < cx88_idcount; i++)
	for (i = 0; UNSET == core->boardnr  &&  i < cx88_idcount; i++)
		if (pci->subsystem_vendor == cx88_subids[i].subvendor &&
		if (pci->subsystem_vendor == cx88_subids[i].subvendor &&
		    pci->subsystem_device == cx88_subids[i].subdevice)
		    pci->subsystem_device == cx88_subids[i].subdevice)
			core->board = cx88_subids[i].card;
			core->boardnr = cx88_subids[i].card;
	if (UNSET == core->board) {
	if (UNSET == core->boardnr) {
		core->board = CX88_BOARD_UNKNOWN;
		core->boardnr = CX88_BOARD_UNKNOWN;
		cx88_card_list(core,pci);
		cx88_card_list(core,pci);
	}
	}

	memcpy(&core->board, &cx88_boards[core->boardnr], sizeof(core->board));

	printk(KERN_INFO "CORE %s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
	printk(KERN_INFO "CORE %s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
		core->name,pci->subsystem_vendor,
		core->name,pci->subsystem_vendor,
		pci->subsystem_device,cx88_boards[core->board].name,
		pci->subsystem_device, core->board.name,
		core->board, card[core->nr] == core->board ?
		core->boardnr, card[core->nr] == core->boardnr ?
		"insmod option" : "autodetected");
		"insmod option" : "autodetected");


	core->tuner_type = tuner[core->nr];
	if (tuner[core->nr] != UNSET)
	core->radio_type = radio[core->nr];
		core->board.tuner_type = tuner[core->nr];
	if (UNSET == core->tuner_type)
	if (radio[core->nr] != UNSET)
		core->tuner_type = cx88_boards[core->board].tuner_type;
		core->board.radio_type = radio[core->nr];
	if (UNSET == core->radio_type)
		core->radio_type = cx88_boards[core->board].radio_type;
	if (!core->tuner_addr)
		core->tuner_addr = cx88_boards[core->board].tuner_addr;
	if (!core->radio_addr)
		core->radio_addr = cx88_boards[core->board].radio_addr;


	printk(KERN_INFO "TV tuner %d at 0x%02x, Radio tuner %d at 0x%02x\n",
	printk(KERN_INFO "TV tuner %d at 0x%02x, Radio tuner %d at 0x%02x\n",
		core->tuner_type, core->tuner_addr<<1,
		core->board.tuner_type, core->board.tuner_addr<<1,
		core->radio_type, core->radio_addr<<1);
		core->board.radio_type, core->board.radio_addr<<1);

	core->tda9887_conf = cx88_boards[core->board].tda9887_conf;


	/* init hardware */
	/* init hardware */
	cx88_reset(core);
	cx88_reset(core);
+5 −5
Original line number Original line Diff line number Diff line
@@ -378,7 +378,7 @@ static int dvb_register(struct cx8802_dev *dev)
	dev->ts_gen_cntrl = 0x0c;
	dev->ts_gen_cntrl = 0x0c;


	/* init frontend */
	/* init frontend */
	switch (dev->core->board) {
	switch (dev->core->boardnr) {
	case CX88_BOARD_HAUPPAUGE_DVB_T1:
	case CX88_BOARD_HAUPPAUGE_DVB_T1:
		dev->dvb.frontend = dvb_attach(cx22702_attach,
		dev->dvb.frontend = dvb_attach(cx22702_attach,
					       &connexant_refboard_config,
					       &connexant_refboard_config,
@@ -653,7 +653,7 @@ static int cx8802_dvb_advise_acquire(struct cx8802_driver *drv)
	int err = 0;
	int err = 0;
	dprintk( 1, "%s\n", __FUNCTION__);
	dprintk( 1, "%s\n", __FUNCTION__);


	switch (core->board) {
	switch (core->boardnr) {
	case CX88_BOARD_HAUPPAUGE_HVR1300:
	case CX88_BOARD_HAUPPAUGE_HVR1300:
		/* We arrive here with either the cx23416 or the cx22702
		/* We arrive here with either the cx23416 or the cx22702
		 * on the bus. Take the bus from the cx23416 and enable the
		 * on the bus. Take the bus from the cx23416 and enable the
@@ -676,7 +676,7 @@ static int cx8802_dvb_advise_release(struct cx8802_driver *drv)
	int err = 0;
	int err = 0;
	dprintk( 1, "%s\n", __FUNCTION__);
	dprintk( 1, "%s\n", __FUNCTION__);


	switch (core->board) {
	switch (core->boardnr) {
	case CX88_BOARD_HAUPPAUGE_HVR1300:
	case CX88_BOARD_HAUPPAUGE_HVR1300:
		/* Do Nothing, leave the cx22702 on the bus. */
		/* Do Nothing, leave the cx22702 on the bus. */
		break;
		break;
@@ -694,13 +694,13 @@ static int cx8802_dvb_probe(struct cx8802_driver *drv)


	dprintk( 1, "%s\n", __FUNCTION__);
	dprintk( 1, "%s\n", __FUNCTION__);
	dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
	dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
		core->board,
		core->boardnr,
		core->name,
		core->name,
		core->pci_bus,
		core->pci_bus,
		core->pci_slot);
		core->pci_slot);


	err = -ENODEV;
	err = -ENODEV;
	if (!(cx88_boards[core->board].mpeg & CX88_MPEG_DVB))
	if (!(core->board.mpeg & CX88_MPEG_DVB))
		goto fail_core;
		goto fail_core;


	/* If vp3054 isn't enabled, a stub will just return 0 */
	/* If vp3054 isn't enabled, a stub will just return 0 */
+12 −12
Original line number Original line Diff line number Diff line
@@ -108,28 +108,28 @@ static int attach_inform(struct i2c_client *client)
	if (!client->driver->command)
	if (!client->driver->command)
		return 0;
		return 0;


	if (core->radio_type != UNSET) {
	if (core->board.radio_type != UNSET) {
		if ((core->radio_addr==ADDR_UNSET)||(core->radio_addr==client->addr)) {
		if ((core->board.radio_addr==ADDR_UNSET)||(core->board.radio_addr==client->addr)) {
			tun_setup.mode_mask = T_RADIO;
			tun_setup.mode_mask = T_RADIO;
			tun_setup.type = core->radio_type;
			tun_setup.type = core->board.radio_type;
			tun_setup.addr = core->radio_addr;
			tun_setup.addr = core->board.radio_addr;


			client->driver->command (client, TUNER_SET_TYPE_ADDR, &tun_setup);
			client->driver->command (client, TUNER_SET_TYPE_ADDR, &tun_setup);
		}
		}
	}
	}
	if (core->tuner_type != UNSET) {
	if (core->board.tuner_type != UNSET) {
		if ((core->tuner_addr==ADDR_UNSET)||(core->tuner_addr==client->addr)) {
		if ((core->board.tuner_addr==ADDR_UNSET)||(core->board.tuner_addr==client->addr)) {


			tun_setup.mode_mask = T_ANALOG_TV;
			tun_setup.mode_mask = T_ANALOG_TV;
			tun_setup.type = core->tuner_type;
			tun_setup.type = core->board.tuner_type;
			tun_setup.addr = core->tuner_addr;
			tun_setup.addr = core->board.tuner_addr;


			client->driver->command (client,TUNER_SET_TYPE_ADDR, &tun_setup);
			client->driver->command (client,TUNER_SET_TYPE_ADDR, &tun_setup);
		}
		}
	}
	}


	if (core->tda9887_conf)
	if (core->board.tda9887_conf)
		client->driver->command(client, TDA9887_SET_CONFIG, &core->tda9887_conf);
		client->driver->command(client, TDA9887_SET_CONFIG, &core->board.tda9887_conf);
	return 0;
	return 0;
}
}


@@ -204,9 +204,9 @@ int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci)
	memcpy(&core->i2c_algo, &cx8800_i2c_algo_template,
	memcpy(&core->i2c_algo, &cx8800_i2c_algo_template,
	       sizeof(core->i2c_algo));
	       sizeof(core->i2c_algo));


	if (core->tuner_type != TUNER_ABSENT)
	if (core->board.tuner_type != TUNER_ABSENT)
		core->i2c_adap.class |= I2C_CLASS_TV_ANALOG;
		core->i2c_adap.class |= I2C_CLASS_TV_ANALOG;
	if (cx88_boards[core->board].mpeg & CX88_MPEG_DVB)
	if (core->board.mpeg & CX88_MPEG_DVB)
		core->i2c_adap.class |= I2C_CLASS_TV_DIGITAL;
		core->i2c_adap.class |= I2C_CLASS_TV_DIGITAL;


	core->i2c_adap.dev.parent = &pci->dev;
	core->i2c_adap.dev.parent = &pci->dev;
Loading