Find the answer to your Linux question:
Results 1 to 3 of 3
Hi folks, I am new to Linux driver development. I am in the process of adding SPI driver support to an existing driver. A driver, supplied by a vendor, is ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2009
    Location
    Nashua, NH
    Posts
    5

    question about adding SPI driver support


    Hi folks,
    I am new to Linux driver development. I am in the process of adding SPI driver support to an existing driver.

    A driver, supplied by a vendor, is a network (MAC/PHY) driver. It abstracts the specific interface to the actual MAC/PHY chip since the vendor sells several versions of the chip; i.e.: a SPI version and a parallel bus version. We are using the SPI version.

    Their driver does almost everything its supposed to do Ethernet-wise, but does not do anything SPI-wise.

    I need to add, to the existing driver, SPI support. I've read a lot about the mechanics of registering a driver, probe, init, etc.

    Can you register a driver (such as SPI) from within another driver?

    Is the following legal?

    status = spi_register_driver(&ks8851_spi_driver);
    if (status)
    return ENOMEM;

    The SPI controller is already instantiated/configured (is that the correct wording?) in our ..../mach-board/board-xxxx.c file
    .
    .
    { /*Ether controller */
    .modalias = "ksz8851snl", // Micrel
    .chip_select = 2,
    .max_speed_hz = 20 * 1000 * 1000, // Micrel
    .bus_num = 0,
    .irq = AT91_PIN_PA0,
    .mode = ((0x3 << 16) & (0xff << 16))| ((0x1 << 24) & (0xff << 24))
    },
    .
    .

    Can someone point me to an example of code that adds a SPI driver to an existing device driver?

    Remember, I am a Linux newbie, so please be gentle..... <grin>
    Thanks,
    Steve

  2. #2
    Just Joined!
    Join Date
    Mar 2009
    Location
    Norway
    Posts
    67
    Quote Originally Posted by saz25 View Post
    Can you register a driver (such as SPI) from within another driver?
    From within another SPI-driver, or just any driver? All SPI-drivers are drivers, and need to register as spi-driver...

    Try:
    git grep "spi_register_driver

    in the kernel source dir an find other examples, IMHO, that's normally the best way to determine 'best practice'

    Quote Originally Posted by saz25 View Post
    Is the following legal?

    status = spi_register_driver(&ks8851_spi_driver);
    Code:
    if (status)
         return ENOMEM;
    No, sorry.

    First off, at least you should return -ENOMEM as positive return is used to indicate the number of things. I.e. sscanf return the number of characters processed. Negative values indicate error.

    Secondly, how sure are you that the status, not being 0, indicate out of memory? Why not just do a
    Code:
    if (status)
         return status;
    ?
    Quote Originally Posted by saz25 View Post
    The SPI controller is already instantiated/configured (is that the correct wording?) in our ..../mach-board/board-xxxx.c file
    .
    .
    { /*Ether controller */
    .modalias = "ksz8851snl", // Micrel
    .chip_select = 2,
    .max_speed_hz = 20 * 1000 * 1000, // Micrel
    .bus_num = 0,
    .irq = AT91_PIN_PA0,
    .mode = ((0x3 << 16) & (0xff << 16))| ((0x1 << 24) & (0xff << 24))
    },
    .
    .

    Can someone point me to an example of code that adds a SPI driver to an existing device driver?
    grep the source. You probably know roughly what you're looking for

    Look at drivers/spi/
    and Documentation/spi

    Quote Originally Posted by saz25 View Post
    Remember, I am a Linux newbie, so please be gentle..... <grin>
    Thanks,
    Steve
    We're all newbies in some area or another

  3. #3
    Just Joined!
    Join Date
    Mar 2009
    Location
    Nashua, NH
    Posts
    5
    Hi,
    Thanks for the suggestions. I will certainly look into those.

    As for my driver, its a driver for a MAC/PHY chip written by someone else as a net_driver. This issue is that I need to access the internal MAC/PHY registers which are accessible only via SPI. So I need (I assume) to register a spi_driver from within a net_driver. I assume thats legal. Correct?

    The folks who write the net_driver wrote the code to be interface independent as they make several variations of the chip. One is a SPI interface and other chips use other interfaces.

    thanks,
    Steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •