AW: spidev.c driver on the ppc8247 (kernel 2.6.27.19)

Stepanov, Sergej Sergej.Stepanov at ids.de
Fri Mar 20 20:37:01 EST 2009


Hi Daniel,

sorry, my example was incomplete...

for a fast you can add in your platform file something like this:

..........................
#ifdef CONFIG_SPI_IDS8247
#include <linux/spi/spi.h>
#include <linux/spi/mmc_spi.h>
#include <linux/mmc/host.h>
#endif
........

#ifdef CONFIG_SPI_IDS8247

#define GPIO_CS (224+22)
static void ids8247_spi_activate_cs(u8 cs, u8 polarity)
{
	pr_debug("%s %d %d\n", __func__, cs, polarity);
	//gpio_set_value(GPIO_CS, (int)polarity);
}

static void ids8247_spi_deactivate_cs(u8 cs, u8 polarity)
{
	pr_debug("%s %d %d\n", __func__, cs, polarity);
	//gpio_set_value(GPIO_CS, (int)(!polarity));
}

static struct mmc_spi_platform_data ids8247_mmc_pdata = {
	.ocr_mask = MMC_VDD_32_33,
};

static struct spi_board_info ids8247_spi_boardinfo = {
	.bus_num = 0,
	.chip_select = 0,
	.max_speed_hz = 20000000,
	.modalias = "mmc_spi",
	.platform_data = &ids8247_mmc_pdata,
};
static __init int ids8247_spi_setup(void)
{
	int ret = 0;
	struct platform_device *spi_dev;
	struct resource r[3];
	struct device_node *np = NULL;
	struct fsl_spi_platform_data spi_data;

	/*if (!gpio_get_value(GPIO_CS))
		return;
	*/
	if( (np = of_find_compatible_node(NULL, "spi", "platform-mapped")) ==0 )
		return 0;

	//fsl_get_sys_freq();
	memset(&spi_data, 0, sizeof(struct fsl_spi_platform_data));
	spi_data.activate_cs = ids8247_spi_activate_cs;
	spi_data.deactivate_cs = ids8247_spi_deactivate_cs;
	spi_data.bus_num = 0;
	spi_data.max_chipselect = 1;
	memset(r, 0, sizeof(struct resource)*3);

	ret = of_address_to_resource(np, 0, &r[0]);
	if (ret)
		goto spi_err;

	ret = of_address_to_resource(np, 1, &r[1]);
	if (ret)
		goto spi_err;

	ret = of_irq_to_resource(np, 0, &r[2]);
	if (ret == NO_IRQ)
		goto spi_err;

	spi_data.qe_mode = 0;
	spi_data.sysclk = 24750000;

	spi_dev = platform_device_register_simple("ids8247_spi", 0, &r[0], 3);
	if (IS_ERR(spi_dev)) {
		ret = PTR_ERR(spi_dev);
		return ret;
	}
	ret = platform_device_add_data(spi_dev,
				       &spi_data,
				       sizeof(struct fsl_spi_platform_data));
	if(ret) {
		platform_device_unregister(spi_dev);
		return ret;
	}
	of_node_put(np);
	return spi_register_board_info(&ids8247_spi_boardinfo, 1);
spi_err:
	of_node_put(np);
	return -1;
}
arch_initcall(ids8247_spi_setup);
#endif /* CONFIG_SPI_IDS8247 */
..........

Sorry, i know it looks very dirty...

Regards
Sergej.

________________________________________
Von: Daniel Ng [daniel.ng1234 at gmail.com]
Gesendet: Freitag, 20. März 2009 02:19
An: Stepanov, Sergej
Cc: linuxppc-dev at ozlabs.org
Betreff: Re: spidev.c driver on the ppc8247 (kernel 2.6.27.19)

On Thu, Mar 19, 2009 at 7:32 PM, Daniel Ng <daniel.ng1234 at gmail.com> wrote:
>
> So, I tried to call spidev_probe() directly from the probe() function
> of my SPI Controller driver. However in this case spidev_probe()
> failed because its call to device_create_drvdata() failed with error
> code ENODEV. Why would this be?
>
> This is how I make the call from my SPI Controller driver:
>
> spidev_probe(to_spi_device(&ofdev->dev));
>
> And this is the relevant code in spidev_probe():
>
> dev = device_create_drvdata(spidev_class, &spi->dev, spidev->devt,
> spidev, "spidev%d.%d",
>                               /*spi->master->bus_num*/0, spi->chip_select);

It looks like spidev_class was uninitialised because spidev_init() had
not yet been called. To force spidev_init() to be called before my SPI
Controller's driver initialisation, I just used:

subsys_initcall(spidev_init);

This seems to do the job...



More information about the Linuxppc-dev mailing list