source: trunk/target/linux/generic/patches-3.2/710-phy-add-mdio_register_board_info.patch @ 30944

Last change on this file since 30944 was 30944, checked in by juhosg, 5 years ago

linux/3.2: build mdio_register_board_info into the kernel if PHYLIB is selected

File size: 4.8 KB
  • drivers/net/phy/mdio_bus.c

    a b  
    3636#include <asm/irq.h> 
    3737#include <asm/uaccess.h> 
    3838 
     39#include "mdio-boardinfo.h" 
     40 
    3941/** 
    4042 * mdiobus_alloc - allocate a mii_bus structure 
    4143 * 
    void mdiobus_free(struct mii_bus *bus) 
    179181} 
    180182EXPORT_SYMBOL(mdiobus_free); 
    181183 
     184static void mdiobus_setup_phydev_from_boardinfo(struct mii_bus *bus, 
     185                                                struct phy_device *phydev, 
     186                                                struct mdio_board_info *bi) 
     187{ 
     188        if (strcmp(bus->id, bi->bus_id) || 
     189            bi->phy_addr != phydev->addr) 
     190                return; 
     191 
     192        phydev->dev.platform_data = (void *) bi->platform_data; 
     193} 
     194 
    182195struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr) 
    183196{ 
    184197        struct phy_device *phydev; 
     198        struct mdio_board_entry *be; 
    185199        int err; 
    186200 
    187201        phydev = get_phy_device(bus, addr); 
    188202        if (IS_ERR(phydev) || phydev == NULL) 
    189203                return phydev; 
    190204 
     205        mutex_lock(&__mdio_board_lock); 
     206        list_for_each_entry(be, &__mdio_board_list, list) 
     207                mdiobus_setup_phydev_from_boardinfo(bus, phydev, 
     208                                                    &be->board_info); 
     209        mutex_unlock(&__mdio_board_lock); 
     210 
    191211        err = phy_device_register(phydev); 
    192212        if (err) { 
    193213                phy_device_free(phydev); 
  • include/linux/phy.h

    a b int __init mdio_bus_init(void); 
    538538void mdio_bus_exit(void); 
    539539 
    540540extern struct bus_type mdio_bus_type; 
     541 
     542struct mdio_board_info { 
     543        const char      *bus_id; 
     544        int             phy_addr; 
     545 
     546        const void      *platform_data; 
     547}; 
     548 
     549#ifdef CONFIG_MDIO_BOARDINFO 
     550int mdiobus_register_board_info(const struct mdio_board_info *info, unsigned n); 
     551#else 
     552static inline int 
     553mdiobus_register_board_info(const struct mdio_board_info *info, unsigned n) 
     554{ 
     555        return 0; 
     556} 
     557#endif 
     558 
    541559#endif /* __PHY_H */ 
  • drivers/net/phy/Kconfig

    a b menuconfig PHYLIB 
    1313 
    1414if PHYLIB 
    1515 
     16config MDIO_BOARDINFO 
     17        bool 
     18        default y 
     19 
    1620config SWCONFIG 
    1721        tristate "Switch configuration API" 
    1822        ---help--- 
  • drivers/net/phy/Makefile

    a b  
    22 
    33libphy-objs                     := phy.o phy_device.o mdio_bus.o 
    44 
     5obj-$(CONFIG_MDIO_BOARDINFO)    += mdio-boardinfo.o 
     6 
    57obj-$(CONFIG_PHYLIB)            += libphy.o 
    68obj-$(CONFIG_SWCONFIG)          += swconfig.o 
    79obj-$(CONFIG_MARVELL_PHY)       += marvell.o 
  • new file drivers/net/phy/mdio-boardinfo.c

    - +  
     1/* 
     2 * mdio-boardinfo.c - collect pre-declarations of PHY devices 
     3 * 
     4 * This program is free software; you can redistribute  it and/or modify it 
     5 * under  the terms of  the GNU General  Public License as published by the 
     6 * Free Software Foundation;  either version 2 of the  License, or (at your 
     7 * option) any later version. 
     8 * 
     9 */ 
     10 
     11#include <linux/kernel.h> 
     12#include <linux/phy.h> 
     13#include <linux/slab.h> 
     14#include <linux/export.h> 
     15#include <linux/mutex.h> 
     16#include <linux/phy.h> 
     17 
     18#include "mdio-boardinfo.h" 
     19 
     20/* 
     21 * These symbols are exported ONLY FOR the mdio_bus component. 
     22 * No other users will be supported. 
     23 */ 
     24 
     25LIST_HEAD(__mdio_board_list); 
     26EXPORT_SYMBOL_GPL(__mdio_board_list); 
     27 
     28DEFINE_MUTEX(__mdio_board_lock); 
     29EXPORT_SYMBOL_GPL(__mdio_board_lock); 
     30 
     31/** 
     32 * mdio_register_board_info - register PHY devices for a given board 
     33 * @info: array of chip descriptors 
     34 * @n: how many descriptors are provided 
     35 * Context: can sleep 
     36 * 
     37 * The board info passed can safely be __initdata ... but be careful of 
     38 * any embedded pointers (platform_data, etc), they're copied as-is. 
     39 */ 
     40int __init 
     41mdiobus_register_board_info(struct mdio_board_info const *info, unsigned n) 
     42{ 
     43        struct mdio_board_entry *be; 
     44        int i; 
     45 
     46        be = kzalloc(n * sizeof(*be), GFP_KERNEL); 
     47        if (!be) 
     48                return -ENOMEM; 
     49 
     50        for (i = 0; i < n; i++, be++, info++) { 
     51                memcpy(&be->board_info, info, sizeof(*info)); 
     52                mutex_lock(&__mdio_board_lock); 
     53                list_add_tail(&be->list, &__mdio_board_list); 
     54                mutex_unlock(&__mdio_board_lock); 
     55        } 
     56 
     57        return 0; 
     58} 
  • new file drivers/net/phy/mdio-boardinfo.h

    - +  
     1/* 
     2 * mdio-boardinfo.h - boardinfo interface internal to the mdio_bus component 
     3 * 
     4 * This program is free software; you can redistribute  it and/or modify it 
     5 * under  the terms of  the GNU General  Public License as published by the 
     6 * Free Software Foundation;  either version 2 of the  License, or (at your 
     7 * option) any later version. 
     8 * 
     9 */ 
     10 
     11#include <linux/mutex.h> 
     12 
     13struct mdio_board_entry { 
     14        struct list_head        list; 
     15        struct mdio_board_info  board_info; 
     16}; 
     17 
     18/* __mdio_board_lock protects __mdio_board_list 
     19 * only mdio_bus components are allowed to use these symbols. 
     20 */ 
     21extern struct mutex __mdio_board_lock; 
     22extern struct list_head __mdio_board_list; 
  • drivers/net/Makefile

    a b obj-$(CONFIG_MII) += mii.o 
    1515obj-$(CONFIG_MDIO) += mdio.o 
    1616obj-$(CONFIG_NET) += Space.o loopback.o 
    1717obj-$(CONFIG_NETCONSOLE) += netconsole.o 
    18 obj-$(CONFIG_PHYLIB) += phy/ 
     18obj-y += phy/ 
    1919obj-$(CONFIG_RIONET) += rionet.o 
    2020obj-$(CONFIG_TUN) += tun.o 
    2121obj-$(CONFIG_VETH) += veth.o 
Note: See TracBrowser for help on using the repository browser.