Skip to contentSkip to conversation

Finding 'orphaned' i2c drivers

DISCUSSION Daniel Mack 3 participants 9 messages Feb 23, 2009 7 messages not in the archive I2C subsystem host drivers

lore
Share & tools
lore
#0 lore raw

Hi,

what's the suggested way of implementing an i2c drver which does not have any other interfaces to the outside world than just the i2c device it is communicating with? More specificly, I implemented a driver for a Maxim clock generator and would like to use a proprietary interface with it from a alsa-soc module. I just can't find a sane way to access the driver's instance from there. It does exist somewhere in the linux device tree, but is there a simple function that iterates over it and returns it to me by name? Reading include/linux/device.h didn't point me to anything that could fit.

Excuse me this is a stupid question, but I can't find any useful information about that anywhere.

Thanks,
Daniel

#2 lore raw
In reply to a message not in the archive
Quoted 11 lines · Daniel Mack

Hi,

what's the suggested way of implementing an i2c drver which does not have any other interfaces to the outside world than just the i2c device it is communicating with? More specifically, I implemented a driver for a Maxim clock generator and would like to use a proprietary interface with it from a alsa-soc module. I just can't find a sane way to access the driver's instance from there. It does exist somewhere in the linux device tree, but is there a simple function that iterates over it and returns it to me by name? Reading include/linux/device.h didn't point me to anything that could fit.

The max9485? Which codec are you using it with? I tried submitting the attached driver for the chip but Jean said it was too simple of a driver.

I use it like this:

static int dspeak01_fabric_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)

{
	uint rate, select;
	int ret;
	struct snd_soc_pcm_runtime *rtd = substream->private_data;
    struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;

	printk("dspeak01_fabric_hw_params\n");

	switch (params_rate(params)) {
	case 11025:
	case 22050:
	case 44100:
	case 88200:
	case 176400:
		rate = 22579200;
		select = MAX9485_225792;
		break;
	default:
		rate = 24576000;
		select = MAX9485_245760;
		break;
	}
	max9485_set(fabric.clock, select | MAX9485_CLK_OUT_2);

	ret = cpu_dai->ops.set_sysclk(cpu_dai, MPC52xx_CLK_CELLSLAVE, rate,
SND_SOC_CLOCK_OUT);
	if (ret < 0)
		return ret;

	return 0;
}
Quoted 12 lines

Excuse me this is a stupid question, but I can't find any useful information about that anywhere.

Thanks,
Daniel

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Jon Smirl
[email protected]
#4 lore raw
In reply to a message not in the archive

Hi,

Quoted 11 lines · Jon Smirl
Quoted 9 lines · Daniel Mack

what's the suggested way of implementing an i2c drver which does not have any other interfaces to the outside world than just the i2c device it is communicating with? More specifically, I implemented a driver for a Maxim clock generator and would like to use a proprietary interface with it from a alsa-soc module. I just can't find a sane way to access the driver's instance from there. It does exist somewhere in the linux device tree, but is there a simple function that iterates over it and returns it to me by name? Reading include/linux/device.h didn't point me to anything that could fit.

Quoted 3 lines

The max9485? Which codec are you using it with? I tried submitting the attached driver for the chip but Jean said it was too simple of a driver.

Yes, it's the same one.

Quoted 19 lines

I use it like this:

static int dspeak01_fabric_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)

{
	uint rate, select;
	int ret;
	struct snd_soc_pcm_runtime *rtd = substream->private_data;
    struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;

	printk("dspeak01_fabric_hw_params\n");

	switch (params_rate(params)) {
	case 11025:
	case 22050:
	case 44100:
	case 88200:
	case 176400:
		rate = 22579200;
Quoted 8 lines
		select = MAX9485_225792;
		break;
	default:
		rate = 24576000;
		select = MAX9485_245760;
		break;
	}
	max9485_set(fabric.clock, select | MAX9485_CLK_OUT_2);

I still don't see where you got the pointer from you are using here, and that's my whole question.

Your driver looks very much like the one I wrote, though ;)

Daniel

#11 lore raw
In reply to a message not in the archive
Quoted 7 lines · Daniel Mack

it is communicating with? More specificly, I implemented a driver for a Maxim clock generator and would like to use a proprietary interface with it from a alsa-soc module. I just can't find a sane way to access the driver's instance from there. It does exist somewhere in the linux device tree, but is there a simple function that iterates over it and returns it to me by name? Reading include/linux/device.h didn't point me to anything that could fit.

You probably want to either have the device register with the ASoC core and discover it that way or have the driver be part of your machine driver (as the neo1973 driver does for the external amplifier).

#13 lore raw
In reply to a message not in the archive
Quoted 10 lines · Mark Brown
Quoted 7 lines · Daniel Mack

it is communicating with? More specificly, I implemented a driver for a Maxim clock generator and would like to use a proprietary interface with it from a alsa-soc module. I just can't find a sane way to access the driver's instance from there. It does exist somewhere in the linux device tree, but is there a simple function that iterates over it and returns it to me by name? Reading include/linux/device.h didn't point me to anything that could fit.

Quoted 3 lines

You probably want to either have the device register with the ASoC core and discover it that way or have the driver be part of your machine driver (as the neo1973 driver does for the external amplifier).

Ok, I might miss a general thing here. All I do is add a driver which is loaded via the module_init() mechanism and registers itself for that specific device by name.

In the board support file, I add a list of i2c_board_infos by calling i2s_register_board_info() and then the driver is magically instanciated in some lower layer.

The question is: how do I access this instance at a later point? Without messing around with static pointers, of course.

Daniel

#15 lore raw
In reply to a message not in the archive
Quoted 2 lines · Daniel Mack

The question is: how do I access this instance at a later point? Without messing around with static pointers, of course.

You're going to need to do something which is specific to your application - it's not a problem for the I2C layer, all it's doing is providing the lower level bus access for the device. The upper level API offered by your driver is something that depends on what services your driver is implementing.

As I said in my previous e-mail you should probably either register with ASoC core and get at the device that way or do something like what the neo1973 driver is doing in your machine driver.

#6 lore raw
In reply to a message not in the archive
Quoted 48 lines · Daniel Mack

Hi,

Quoted 11 lines · Jon Smirl
Quoted 9 lines · Daniel Mack

what's the suggested way of implementing an i2c drver which does not have any other interfaces to the outside world than just the i2c device it is communicating with? More specifically, I implemented a driver for a Maxim clock generator and would like to use a proprietary interface with it from a alsa-soc module. I just can't find a sane way to access the driver's instance from there. It does exist somewhere in the linux device tree, but is there a simple function that iterates over it and returns it to me by name? Reading include/linux/device.h didn't point me to anything that could fit.

Quoted 3 lines

The max9485? Which codec are you using it with? I tried submitting the attached driver for the chip but Jean said it was too simple of a driver.

Yes, it's the same one.

Quoted 19 lines

I use it like this:

static int dspeak01_fabric_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)

{
      uint rate, select;
      int ret;
      struct snd_soc_pcm_runtime *rtd = substream->private_data;
    struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;

      printk("dspeak01_fabric_hw_params\n");

      switch (params_rate(params)) {
      case 11025:
      case 22050:
      case 44100:
      case 88200:
      case 176400:
              rate = 22579200;
Quoted 8 lines
              select = MAX9485_225792;
              break;
      default:
              rate = 24576000;
              select = MAX9485_245760;
              break;
      }
      max9485_set(fabric.clock, select | MAX9485_CLK_OUT_2);
Quoted 2 lines

I still don't see where you got the pointer from you are using here, and that's my whole question.

I'm on PowerPC, we have device tree.

		i2c@3d00 {
			#address-cells = <1>;
			#size-cells = <0>;
			compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
			cell-index = <0>;
			reg = <0x3d00 0x40>;
			interrupts = <0x2 0xf 0x0>;
			interrupt-parent = <&mpc5200_pic>;
			fsl5200-clocking;

			tas0:codec@1b {
				compatible = "ti,tas5504";
				reg = <0x1b>;
			};
			clock0:clock@68 {
				compatible = "maxim,max9485";
				reg = <0x68>;
			};
		};

		fabric { /* audio fabric hardware */
			compatible = "dspeak01-fabric";
			clock-handle = <&clock0>;
		};
Quoted 6 lines

Your driver looks very much like the one I wrote, though ;)

Daniel

Signature · 2 lines
Jon Smirl
[email protected]
#8 lore raw
In reply to a message not in the archive
Quoted 70 lines · Jon Smirl
Quoted 48 lines · Daniel Mack

Hi,

Quoted 11 lines · Jon Smirl
Quoted 9 lines · Daniel Mack

what's the suggested way of implementing an i2c drver which does not have any other interfaces to the outside world than just the i2c device it is communicating with? More specifically, I implemented a driver for a Maxim clock generator and would like to use a proprietary interface with it from a alsa-soc module. I just can't find a sane way to access the driver's instance from there. It does exist somewhere in the linux device tree, but is there a simple function that iterates over it and returns it to me by name? Reading include/linux/device.h didn't point me to anything that could fit.

Quoted 3 lines

The max9485? Which codec are you using it with? I tried submitting the attached driver for the chip but Jean said it was too simple of a driver.

Yes, it's the same one.

Quoted 19 lines

I use it like this:

static int dspeak01_fabric_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params)

{
      uint rate, select;
      int ret;
      struct snd_soc_pcm_runtime *rtd = substream->private_data;
    struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;

      printk("dspeak01_fabric_hw_params\n");

      switch (params_rate(params)) {
      case 11025:
      case 22050:
      case 44100:
      case 88200:
      case 176400:
              rate = 22579200;
Quoted 8 lines
              select = MAX9485_225792;
              break;
      default:
              rate = 24576000;
              select = MAX9485_245760;
              break;
      }
      max9485_set(fabric.clock, select | MAX9485_CLK_OUT_2);
Quoted 2 lines

I still don't see where you got the pointer from you are using here, and that's my whole question.

I'm on PowerPC, we have device tree.

               i2c@3d00 {
                       #address-cells = <1>;
                       #size-cells = <0>;
                       compatible = "fsl,mpc5200b-i2c","fsl,mpc5200-i2c","fsl-i2c";
                       cell-index = <0>;
                       reg = <0x3d00 0x40>;
                       interrupts = <0x2 0xf 0x0>;
                       interrupt-parent = <&mpc5200_pic>;
                       fsl5200-clocking;

                       tas0:codec@1b {
                               compatible = "ti,tas5504";
                               reg = <0x1b>;
                       };
                       clock0:clock@68 {
                               compatible = "maxim,max9485";
Quoted 9 lines
                               reg = <0x68>;
                       };
               };

               fabric { /* audio fabric hardware */
                       compatible = "dspeak01-fabric";
                       clock-handle = <&clock0>;
               };

In the fabric driver I use clock-handle and call
struct i2c_client *of_find_i2c_device_by_node(struct device_node *node) {

To get the driver of the i2c device.

Quoted 14 lines
Quoted 7 lines

Your driver looks very much like the one I wrote, though ;)

Daniel

--
Jon Smirl
[email protected]

Signature · 2 lines
Jon Smirl
[email protected]
#10 lore raw
In reply to a message not in the archive

This is the last piece....

static int __devinit dspeak01_fabric_probe(struct of_device *op,
const struct of_device_id *match)

{
	const phandle *handle;
	struct device_node *clock_node;
	unsigned int len;

	handle = of_get_property(op->node, "clock-handle", &len);
	if (!handle || len < sizeof(handle))
		return -ENODEV;

	clock_node = of_find_node_by_phandle(*handle);
	if (!clock_node)
		return -ENODEV;

	fabric.clock = of_find_i2c_device_by_node(clock_node);
	if (!fabric.clock)
		return -ENODEV;

	of_snd_soc_register_machine("DSPEAK01", &dspeak01_fabric_ops);
	return 0;
}
Signature · 2 lines
Jon Smirl
[email protected]