pasemi: allow 8KB config space for I/O bridge
PATCH 1/5 pasemi: allow 8KB config space for I/O bridge
Device 0 function 0 on the root bus is really a two-function bus agent, but only the first function is visible. Because of this, we need to allow config accesses into the second range. Modify the check for valid offsets accordingly.
arch/powerpc/platforms/pasemi/pci.c +13 -3
@@ -33,7 +33,17 @@#define PA_PXP_CFA (bus, devfn, off) (((bus) << 20) | ((devfn) << 12) | (off)) -#define CONFIG_OFFSET_VALID (off) ((off) < 4096) +static inline int pa_pxp_offset_valid (u8 bus,u8 devfn,int offset) +{ +/* Device 0 Function 0 is special: It's config space spans function 1 as +* well, so allow larger offset. It's really a two-function device but the +* second function does not probe. +*/ +if (bus ==0 && devfn ==0 ) +return offset <8192 ; +else +return offset <4096 ; +}static void volatile __iomem *pa_pxp_cfg_addr (struct pci_controller *hose,u8 bus,u8 devfn,int offset)
@@ -51,7 +61,7 @@ static int pa_pxp_read_config(struct pciif (!hose)return PCIBIOS_DEVICE_NOT_FOUND ; -if (!CONFIG_OFFSET_VALID (offset)) +if (!pa_pxp_offset_valid (bus->number, devfn, offset))return PCIBIOS_BAD_REGISTER_NUMBER ; addr =pa_pxp_cfg_addr (hose, bus->number, devfn, offset);
@@ -85,7 +95,7 @@ static int pa_pxp_write_config(struct pcif (!hose)return PCIBIOS_DEVICE_NOT_FOUND ; -if (!CONFIG_OFFSET_VALID (offset)) +if (!pa_pxp_offset_valid (bus->number, devfn, offset))return PCIBIOS_BAD_REGISTER_NUMBER ; addr =pa_pxp_cfg_addr (hose, bus->number, devfn, offset);
PATCH 2/5 pasemi: enable one more hid bit
Minor HID change. Firmware can't know that we want this set so we have to set it in the kernel.
arch/powerpc/kernel/cpu_setup_pa6t.S +1 -1
@@ -34,7 +34,7 @@ _GLOBAL(__setup_cpu_pa6t) beqlr mfspr r0,SPRN_HID5 - ori r0,r0,0x30 + ori r0,r0,0x38 mtspr SPRN_HID5,r0 mfspr r0,SPRN_LPCR
Re: [PATCH] [2/5] pasemi: enable one more hid bit
Quoted 2 lines · Olof Johansson
Minor HID change. Firmware can't know that we want this set so we have to set it in the kernel.
Care to document/name these bits ?
Quoted 20 lines
Signed-off-by Olof Johansson <[email protected]>Index:
linux-2.6/arch/powerpc/kernel/cpu_setup_pa6t.S
===================================================================arch/powerpc/kernel/cpu_setup_pa6t.S +1
-1@@ -34,7 +34,7 @@ _GLOBAL(__setup_cpu_pa6t) beqlr mfspr r0,SPRN_HID5 - ori r0,r0,0x30 + ori r0,r0,0x38 mtspr SPRN_HID5,r0 mfspr r0,SPRN_LPCR_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev
Re: [PATCH] [2/5] pasemi: enable one more hid bit
Quoted 5 lines · Benjamin Herrenschmidt
Quoted 2 lines · Olof Johansson
Minor HID change. Firmware can't know that we want this set so we have to set it in the kernel.
Care to document/name these bits ?
Not at this time, sorry.
-Olof
PATCH 3/5 pasemi: reset mpic on boot
In reply to Olof JohanssonReset MPIC on boot to clear some timer state that firmware might leave configured.
arch/powerpc/platforms/pasemi/setup.c +1 -1
@@ -147,7 +147,7 @@ static __init void pas_init_IRQ(void)printk (KERN_DEBUG "OpenPIC addr: %lx\n" , openpic_addr); mpic =mpic_alloc (mpic_node, openpic_addr, -MPIC_PRIMARY |MPIC_LARGE_VECTORS , +MPIC_PRIMARY |MPIC_LARGE_VECTORS |MPIC_WANTS_RESET ,0 ,0 ," PAS-OPIC " );BUG_ON (!mpic);
PATCH 4/5 pasemi: PA6T oprofile support
In reply to Olof JohanssonOprofile support for PA6T, kernel side.
Also rename the PA6T_SPRN.* defines to SPRN_PA6T.*.
arch/powerpc/kernel/cputable.c +2 -0
@@ -373,6 +373,8 @@ static struct cpu_spec cpu_specs[] = { .pmc_type = PPC_PMC_PA6T, .cpu_setup = __setup_cpu_pa6t, .cpu_restore = __restore_cpu_pa6t, + .oprofile_cpu_type = "ppc64/pa6t", + .oprofile_type = PPC_OPROFILE_PA6T, .platform = "pa6t", }, {/* default match */
arch/powerpc/kernel/sysfs.c +6 -6
@@ -189,12 +189,12 @@ SYSFS_PMCSETUP(purr, SPRN_PURR);SYSFS_PMCSETUP (spurr,SPRN_SPURR );SYSFS_PMCSETUP (dscr,SPRN_DSCR ); -SYSFS_PMCSETUP (pa6t_pmc0,PA6T_SPRN_PMC0 ); -SYSFS_PMCSETUP (pa6t_pmc1,PA6T_SPRN_PMC1 ); -SYSFS_PMCSETUP (pa6t_pmc2,PA6T_SPRN_PMC2 ); -SYSFS_PMCSETUP (pa6t_pmc3,PA6T_SPRN_PMC3 ); -SYSFS_PMCSETUP (pa6t_pmc4,PA6T_SPRN_PMC4 ); -SYSFS_PMCSETUP (pa6t_pmc5,PA6T_SPRN_PMC5 ); +SYSFS_PMCSETUP (pa6t_pmc0,SPRN_PA6T_PMC0 ); +SYSFS_PMCSETUP (pa6t_pmc1,SPRN_PA6T_PMC1 ); +SYSFS_PMCSETUP (pa6t_pmc2,SPRN_PA6T_PMC2 ); +SYSFS_PMCSETUP (pa6t_pmc3,SPRN_PA6T_PMC3 ); +SYSFS_PMCSETUP (pa6t_pmc4,SPRN_PA6T_PMC4 ); +SYSFS_PMCSETUP (pa6t_pmc5,SPRN_PA6T_PMC5 ); static SYSDEV_ATTR(mmcra, 0600, show_mmcra, store_mmcra);
arch/powerpc/oprofile/op_model_pa6t.c new file +234 -0
234 lines not on this page · raw message
arch/powerpc/platforms/pasemi/setup.c +1 -0
@@ -28,6 +28,7 @@#include <linux/console.h> #include <linux/pci.h> +#include <asm/pmc.h> #include <asm/prom.h> #include <asm/system.h> #include <asm/iommu.h>
include/asm-powerpc/cputable.h +1 -0
@@ -48,6 +48,7 @@ enum powerpc_oprofile_type {PPC_OPROFILE_G4 =3 ,PPC_OPROFILE_BOOKE =4 ,PPC_OPROFILE_CELL =5 , + PPC_OPROFILE_PA6T = 6, }; enum powerpc_pmc_type {
include/asm-powerpc/reg.h +71 -6
83 lines not on this page · raw message
include/asm-powerpc/pmc.h +1 -0
@@ -30,6 +30,7 @@ void release_pmc_hardware(void);#ifdef CONFIG_PPC64 void power4_enable_pmcs (void ); +void pasemi_enable_pmcs (void );#endif #endif /* __KERNEL__ */
arch/powerpc/oprofile/common.c +3 -0
@@ -160,6 +160,9 @@ int __init oprofile_arch_init(struct oprcase PPC_OPROFILE_POWER4 : model = &op_model_power4;break ; +case PPC_OPROFILE_PA6T : + model = &op_model_pa6t; +break ;#endif #ifdef CONFIG_6xxcase PPC_OPROFILE_G4 :
arch/powerpc/oprofile/Makefile +1 -1
@@ -12,6 +12,6 @@ DRIVER_OBJS := $(addprefix ../../../driv oprofile-y := $(DRIVER_OBJS) common.o backtrace.o oprofile-$(CONFIG_PPC_CELL_NATIVE) += op_model_cell.o -oprofile-$(CONFIG_PPC64) += op_model_rs64.o op_model_power4.o +oprofile-$(CONFIG_PPC64) += op_model_rs64.o op_model_power4.o op_model_pa6t.o oprofile-$(CONFIG_FSL_BOOKE) += op_model_fsl_booke.o oprofile-$(CONFIG_6xx) += op_model_7450.o
include/asm-powerpc/oprofile_impl.h +2 -0
@@ -57,6 +57,8 @@ extern struct op_powerpc_model op_model_extern struct op_powerpc_model op_model_power4;extern struct op_powerpc_model op_model_7450;extern struct op_powerpc_model op_model_cell; +extern struct op_powerpc_model op_model_pa6t; +/* All the classic PPC parts use these */ static inline unsigned int classic_ctr_read (unsigned int i)
PATCH v2 4/5 pasemi: PA6T oprofile support
Oprofile support for PA6T, kernel side.
Also rename the PA6T_SPRN.* defines to SPRN_PA6T.*.
--
Changed: Fixed some redundant defines and unneeded include file.
arch/powerpc/kernel/cputable.c +2 -0
@@ -389,6 +389,8 @@ static struct cpu_spec cpu_specs[] = { .pmc_type = PPC_PMC_PA6T, .cpu_setup = __setup_cpu_pa6t, .cpu_restore = __restore_cpu_pa6t, + .oprofile_cpu_type = "ppc64/pa6t", + .oprofile_type = PPC_OPROFILE_PA6T, .platform = "pa6t", }, {/* default match */
arch/powerpc/kernel/sysfs.c +6 -6
@@ -189,12 +189,12 @@ SYSFS_PMCSETUP(purr, SPRN_PURR);SYSFS_PMCSETUP (spurr,SPRN_SPURR );SYSFS_PMCSETUP (dscr,SPRN_DSCR ); -SYSFS_PMCSETUP (pa6t_pmc0,PA6T_SPRN_PMC0 ); -SYSFS_PMCSETUP (pa6t_pmc1,PA6T_SPRN_PMC1 ); -SYSFS_PMCSETUP (pa6t_pmc2,PA6T_SPRN_PMC2 ); -SYSFS_PMCSETUP (pa6t_pmc3,PA6T_SPRN_PMC3 ); -SYSFS_PMCSETUP (pa6t_pmc4,PA6T_SPRN_PMC4 ); -SYSFS_PMCSETUP (pa6t_pmc5,PA6T_SPRN_PMC5 ); +SYSFS_PMCSETUP (pa6t_pmc0,SPRN_PA6T_PMC0 ); +SYSFS_PMCSETUP (pa6t_pmc1,SPRN_PA6T_PMC1 ); +SYSFS_PMCSETUP (pa6t_pmc2,SPRN_PA6T_PMC2 ); +SYSFS_PMCSETUP (pa6t_pmc3,SPRN_PA6T_PMC3 ); +SYSFS_PMCSETUP (pa6t_pmc4,SPRN_PA6T_PMC4 ); +SYSFS_PMCSETUP (pa6t_pmc5,SPRN_PA6T_PMC5 ); static SYSDEV_ATTR(mmcra, 0600, show_mmcra, store_mmcra);
arch/powerpc/oprofile/op_model_pa6t.c new file +234 -0
234 lines not on this page · raw message
include/asm-powerpc/cputable.h +1 -0
@@ -48,6 +48,7 @@ enum powerpc_oprofile_type {PPC_OPROFILE_G4 =3 ,PPC_OPROFILE_BOOKE =4 ,PPC_OPROFILE_CELL =5 , + PPC_OPROFILE_PA6T = 6, }; enum powerpc_pmc_type {
include/asm-powerpc/reg.h +62 -6
74 lines not on this page · raw message
include/asm-powerpc/pmc.h +1 -0
@@ -30,6 +30,7 @@ void release_pmc_hardware(void);#ifdef CONFIG_PPC64 void power4_enable_pmcs (void ); +void pasemi_enable_pmcs (void );#endif #endif /* __KERNEL__ */
arch/powerpc/oprofile/common.c +3 -0
@@ -160,6 +160,9 @@ int __init oprofile_arch_init(struct oprcase PPC_OPROFILE_POWER4 : model = &op_model_power4;break ; +case PPC_OPROFILE_PA6T : + model = &op_model_pa6t; +break ;#endif #ifdef CONFIG_6xxcase PPC_OPROFILE_G4 :
arch/powerpc/oprofile/Makefile +1 -1
@@ -12,6 +12,6 @@ DRIVER_OBJS := $(addprefix ../../../driv oprofile-y := $(DRIVER_OBJS) common.o backtrace.o oprofile-$(CONFIG_PPC_CELL_NATIVE) += op_model_cell.o -oprofile-$(CONFIG_PPC64) += op_model_rs64.o op_model_power4.o +oprofile-$(CONFIG_PPC64) += op_model_rs64.o op_model_power4.o op_model_pa6t.o oprofile-$(CONFIG_FSL_BOOKE) += op_model_fsl_booke.o oprofile-$(CONFIG_6xx) += op_model_7450.o
include/asm-powerpc/oprofile_impl.h +2 -0
@@ -57,6 +57,8 @@ extern struct op_powerpc_model op_model_extern struct op_powerpc_model op_model_power4;extern struct op_powerpc_model op_model_7450;extern struct op_powerpc_model op_model_cell; +extern struct op_powerpc_model op_model_pa6t; +/* All the classic PPC parts use these */ static inline unsigned int classic_ctr_read (unsigned int i)
PATCH 5/5 pasemi: GPIO MDIO of_platform driver
In reply to Olof JohanssonMDIO driver for PHY's connected via GPIO as on the PA Semi Electra eval board.
arch/powerpc/platforms/pasemi/gpio_mdio.c new file +349 -0
@@ -0,0 +1,349 @@ +/* +* Copyright (C) 2006-2007 PA Semi, Inc +* +* Author: Olof Johansson, PA Semi +* +* Maintained by: Olof Johansson <[email protected]> +* +* Based on drivers/net/fs_enet/mii-bitbang.c. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <linux/io.h> +#include <linux/module.h> +#include <linux/types.h> +#include <linux/sched.h> +#include <linux/errno.h> +#include <linux/ioport.h> +#include <linux/interrupt.h> +#include <linux/phy.h> +#include <linux/platform_device.h> +#include <asm/of_platform.h> + +#define DELAY 1 + +static void __iomem *gpio_regs; + +struct gpio_priv { +int mdc_pin; +int mdio_pin; +}; + +#define MDC_PIN (bus) (((struct gpio_priv *)bus->priv)->mdc_pin) +#define MDIO_PIN (bus) (((struct gpio_priv *)bus->priv)->mdio_pin) + +static inline void mdio_lo (struct mii_bus *bus) +{ +out_le32 (gpio_regs+0x10 ,1 <<MDIO_PIN (bus)); +} + +static inline void mdio_hi (struct mii_bus *bus) +{ +out_le32 (gpio_regs,1 <<MDIO_PIN (bus)); +} + +static inline void mdc_lo (struct mii_bus *bus) +{ +out_le32 (gpio_regs+0x10 ,1 <<MDC_PIN (bus)); +} + +static inline void mdc_hi (struct mii_bus *bus) +{ +out_le32 (gpio_regs,1 <<MDC_PIN (bus)); +} + +static inline void mdio_active (struct mii_bus *bus) +{ +out_le32 (gpio_regs+0x20 , (1 <<MDC_PIN (bus)) | (1 <<MDIO_PIN (bus))); +} + +static inline void mdio_tristate (struct mii_bus *bus) +{ +out_le32 (gpio_regs+0x30 , (1 <<MDIO_PIN (bus))); +} + +static inline int mdio_read (struct mii_bus *bus) +{ +return !!(in_le32 (gpio_regs+0x40 ) & (1 <<MDIO_PIN (bus))); +} + +static void clock_out (struct mii_bus *bus,int bit) +{ +if (bit) +mdio_hi (bus); +else +mdio_lo (bus); +udelay (DELAY ); +mdc_hi (bus); +udelay (DELAY ); +mdc_lo (bus); +} + +/* Utility to send the preamble, address, and register (common to read and write). */ +static void bitbang_pre (struct mii_bus *bus,int read,u8 addr,u8 reg) +{ +int i; + +/* CFE uses a really long preamble (40 bits). We'll do the same. */ +mdio_active (bus); +for (i =0 ; i <40 ; i++) { +clock_out (bus,1 ); + } + +/* send the start bit (01) and the read opcode (10) or write (10) */ +clock_out (bus,0 ); +clock_out (bus,1 ); + +clock_out (bus, read); +clock_out (bus, !read); + +/* send the PHY address */ +for (i =0 ; i <5 ; i++) { +clock_out (bus, (addr &0x10 ) !=0 ); + addr <<=1 ; + } + +/* send the register address */ +for (i =0 ; i <5 ; i++) { +clock_out (bus, (reg &0x10 ) !=0 ); + reg <<=1 ; + } +} + +static int gpio_mdio_read (struct mii_bus *bus,int phy_id,int location) +{ +u16 rdreg; +int ret, i; +u8 addr = phy_id &0xff ; +u8 reg = location &0xff ; + +bitbang_pre (bus,1 , addr, reg); + +/* tri-state our MDIO I/O pin so we can read */ +mdio_tristate (bus); +udelay (DELAY ); +mdc_hi (bus); +udelay (DELAY ); +mdc_lo (bus); + +/* read 16 bits of register data, MSB first */ + rdreg =0 ; +for (i =0 ; i <16 ; i++) { +mdc_lo (bus); +udelay (DELAY ); +mdc_hi (bus); +udelay (DELAY ); +mdc_lo (bus); +udelay (DELAY ); + rdreg <<=1 ; + rdreg |=mdio_read (bus); + } + +mdc_hi (bus); +udelay (DELAY ); +mdc_lo (bus); +udelay (DELAY ); + + ret = rdreg; + +return ret; +} + +static int gpio_mdio_write (struct mii_bus *bus,int phy_id,int location,u16 val) +{ +int i; + +u8 addr = phy_id &0xff ; +u8 reg = location &0xff ; +u16 value = val &0xffff ; + +bitbang_pre (bus,0 , addr, reg); + +/* send the turnaround (10) */ +mdc_lo (bus); +mdio_hi (bus); +udelay (DELAY ); +mdc_hi (bus); +udelay (DELAY ); +mdc_lo (bus); +mdio_lo (bus); +udelay (DELAY ); +mdc_hi (bus); +udelay (DELAY ); + +/* write 16 bits of register data, MSB first */ +for (i =0 ; i <16 ; i++) { +mdc_lo (bus); +if (value &0x8000 ) +mdio_hi (bus); +else +mdio_lo (bus); +udelay (DELAY ); +mdc_hi (bus); +udelay (DELAY ); + value <<=1 ; + } + +/* +* Tri-state the MDIO line. +*/ +mdio_tristate (bus); +mdc_lo (bus); +udelay (DELAY ); +mdc_hi (bus); +udelay (DELAY ); +return 0 ; +} + +static int gpio_mdio_reset (struct mii_bus *bus) +{ +/*nothing here - dunno how to reset it*/ +return 0 ; +} + + +static int __devinit gpio_mdio_probe (struct of_device *ofdev, +const struct of_device_id *match) +{ +struct device *dev = &ofdev->dev; +struct device_node *np = ofdev->node; +struct device_node *gpio_np; +struct mii_bus *new_bus; +struct resource res; +struct gpio_priv *priv; +const unsigned int *prop; +int err =0 ; +int i; + + gpio_np =of_find_compatible_node (NULL ,"gpio" ,"1682m-gpio" ); + +if (!gpio_np) +return -ENODEV ; + + err =of_address_to_resource (gpio_np,0 , &res); +of_node_put (gpio_np); + +if (err) +return -EINVAL ; + +if (!gpio_regs) + gpio_regs =ioremap (res.start,0x100 ); + +if (!gpio_regs) +return -EPERM ; + + priv =kzalloc (sizeof (struct gpio_priv ),GFP_KERNEL ); +if (priv ==NULL ) +return -ENOMEM ; + + new_bus =kzalloc (sizeof (struct mii_bus ),GFP_KERNEL ); + +if (new_bus ==NULL ) +return -ENOMEM ; + + new_bus->name ="pasemi gpio mdio bus" , + new_bus->read = &gpio_mdio_read, + new_bus->write = &gpio_mdio_write, + new_bus->reset = &gpio_mdio_reset, + + prop =get_property (np,"reg" ,NULL ); + new_bus->id = *prop; + new_bus->priv = priv; + + new_bus->phy_mask =0 ; + + new_bus->irq =kmalloc (sizeof (int )*PHY_MAX_ADDR ,GFP_KERNEL ); +for (i =0 ; i <PHY_MAX_ADDR ; ++i) + new_bus->irq[i] =irq_create_mapping (NULL ,10 ); + + + prop =get_property (np,"mdc-pin" ,NULL ); + priv->mdc_pin = *prop; + + prop =get_property (np,"mdio-pin" ,NULL ); + priv->mdio_pin = *prop; + + new_bus->dev = dev; +dev_set_drvdata (dev, new_bus); + + err =mdiobus_register (new_bus); + +if (0 != err) { +printk (KERN_ERR "%s: Cannot register as MDIO bus, err %d\n" , + new_bus->name, err); + goto bus_register_fail; + } + +return 0 ; + +bus_register_fail: +kfree (new_bus); + +return err; +} + + +static int gpio_mdio_remove (struct of_device *dev) +{ +struct mii_bus *bus =dev_get_drvdata (&dev->dev); + +mdiobus_unregister (bus); + +dev_set_drvdata (&dev->dev,NULL ); + +kfree (bus->priv); + bus->priv =NULL ; +kfree (bus); + +return 0 ; +} + +static struct of_device_id gpio_mdio_match[] = +{ + { + .compatible ="gpio-mdio" , + }, + {}, +}; + +static struct of_platform_driver gpio_mdio_driver = +{ + .name ="gpio-mdio-bitbang" , + .match_table = gpio_mdio_match, + .probe = gpio_mdio_probe, + .remove = gpio_mdio_remove, +}; + +int gpio_mdio_init (void ) +{ +return of_register_platform_driver (&gpio_mdio_driver); +} + +void gpio_mdio_exit (void ) +{ +of_unregister_platform_driver (&gpio_mdio_driver); +} + +device_initcall (gpio_mdio_init); + +static int __devinit hack_init (void ) +{ +struct platform_device *pdev; + + pdev =platform_device_register_simple ("gpio-mdio-bitbang" ,0 ,NULL ,0 ); + +return 0 ; +} +late_initcall (hack_init);
arch/powerpc/platforms/pasemi/Makefile +1 -1
@@ -1,3 +1,3 @@ -obj-y += setup.o pci.o time.o idle.o powersave.o iommu.o +obj-y += setup.o pci.o time.o idle.o powersave.o iommu.o gpio_mdio.o obj-$(CONFIG_PPC_PASEMI_CPUFREQ) += cpufreq.o
Re: [PATCH] [5/5] pasemi: GPIO MDIO of_platform driver
arch/powerpc/platforms/pasemi/gpio_mdio.c
Quoted 5 lines · Olof Johansson
arch/powerpc/platforms/pasemi/gpio_mdio.c new file +5
-0+static int __devinit hack_init(void) +{ +=A0=A0=A0=A0=A0=A0=A0struct platform_device *pdev; + +=A0=A0=A0=A0=A0=A0=A0pdev =3D platform_device_register_simple("gpio-mdio=
=2Dbitbang", 0, NULL, 0);
arch/powerpc/platforms/pasemi/gpio_mdio.c line 349
Quoted 4 lines
arch/powerpc/platforms/pasemi/gpio_mdio.c new file +4
-0+ +=A0=A0=A0=A0=A0=A0=A0return 0; +} +late_initcall (hack_init);
Why do you need this? The name already suggests that you are aware that this should be autoprobed, but it would be good to have a comment explaining why you did it this way.
Arnd <><
Re: [PATCH] [5/5] pasemi: GPIO MDIO of_platform driver
Quoted 14 lines · Arnd Bergmann
arch/powerpc/platforms/pasemi/gpio_mdio.c line 349
Quoted 9 lines · Olof Johansson
arch/powerpc/platforms/pasemi/gpio_mdio.c new file +9
-0+static int __devinit hack_init (void ) +{ +???????struct platform_device *pdev; + +???????pdev = platform_device_register_simple("gpio-mdio-bitbang", 0, NULL, 0); + +???????return 0; +} +late_initcall (hack_init);Why do you need this? The name already suggests that you are aware that this should be autoprobed, but it would be good to have a comment explaining why you did it this way.
Because I'm an idiot and forgot to take it away before posting. :-) Thanks, will clean it up.
-Olof
PATCH v2 5/5 pasemi: GPIO MDIO of_platform driver
In reply to Olof JohanssonMDIO driver for PHY's connected via GPIO as on the PA Semi Electra eval board.
--
Changed: Removed hack to probe the device, and added the compatible = "sdc" of platform probe.
arch/powerpc/platforms/pasemi/gpio_mdio.c new file +339 -0
@@ -0,0 +1,339 @@ +/* +* Copyright (C) 2006-2007 PA Semi, Inc +* +* Author: Olof Johansson, PA Semi +* +* Maintained by: Olof Johansson <[email protected]> +* +* Based on drivers/net/fs_enet/mii-bitbang.c. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include <linux/io.h> +#include <linux/module.h> +#include <linux/types.h> +#include <linux/sched.h> +#include <linux/errno.h> +#include <linux/ioport.h> +#include <linux/interrupt.h> +#include <linux/phy.h> +#include <linux/platform_device.h> +#include <asm/of_platform.h> + +#define DELAY 1 + +static void __iomem *gpio_regs; + +struct gpio_priv { +int mdc_pin; +int mdio_pin; +}; + +#define MDC_PIN (bus) (((struct gpio_priv *)bus->priv)->mdc_pin) +#define MDIO_PIN (bus) (((struct gpio_priv *)bus->priv)->mdio_pin) + +static inline void mdio_lo (struct mii_bus *bus) +{ +out_le32 (gpio_regs+0x10 ,1 <<MDIO_PIN (bus)); +} + +static inline void mdio_hi (struct mii_bus *bus) +{ +out_le32 (gpio_regs,1 <<MDIO_PIN (bus)); +} + +static inline void mdc_lo (struct mii_bus *bus) +{ +out_le32 (gpio_regs+0x10 ,1 <<MDC_PIN (bus)); +} + +static inline void mdc_hi (struct mii_bus *bus) +{ +out_le32 (gpio_regs,1 <<MDC_PIN (bus)); +} + +static inline void mdio_active (struct mii_bus *bus) +{ +out_le32 (gpio_regs+0x20 , (1 <<MDC_PIN (bus)) | (1 <<MDIO_PIN (bus))); +} + +static inline void mdio_tristate (struct mii_bus *bus) +{ +out_le32 (gpio_regs+0x30 , (1 <<MDIO_PIN (bus))); +} + +static inline int mdio_read (struct mii_bus *bus) +{ +return !!(in_le32 (gpio_regs+0x40 ) & (1 <<MDIO_PIN (bus))); +} + +static void clock_out (struct mii_bus *bus,int bit) +{ +if (bit) +mdio_hi (bus); +else +mdio_lo (bus); +udelay (DELAY ); +mdc_hi (bus); +udelay (DELAY ); +mdc_lo (bus); +} + +/* Utility to send the preamble, address, and register (common to read and write). */ +static void bitbang_pre (struct mii_bus *bus,int read,u8 addr,u8 reg) +{ +int i; + +/* CFE uses a really long preamble (40 bits). We'll do the same. */ +mdio_active (bus); +for (i =0 ; i <40 ; i++) { +clock_out (bus,1 ); + } + +/* send the start bit (01) and the read opcode (10) or write (10) */ +clock_out (bus,0 ); +clock_out (bus,1 ); + +clock_out (bus, read); +clock_out (bus, !read); + +/* send the PHY address */ +for (i =0 ; i <5 ; i++) { +clock_out (bus, (addr &0x10 ) !=0 ); + addr <<=1 ; + } + +/* send the register address */ +for (i =0 ; i <5 ; i++) { +clock_out (bus, (reg &0x10 ) !=0 ); + reg <<=1 ; + } +} + +static int gpio_mdio_read (struct mii_bus *bus,int phy_id,int location) +{ +u16 rdreg; +int ret, i; +u8 addr = phy_id &0xff ; +u8 reg = location &0xff ; + +bitbang_pre (bus,1 , addr, reg); + +/* tri-state our MDIO I/O pin so we can read */ +mdio_tristate (bus); +udelay (DELAY ); +mdc_hi (bus); +udelay (DELAY ); +mdc_lo (bus); + +/* read 16 bits of register data, MSB first */ + rdreg =0 ; +for (i =0 ; i <16 ; i++) { +mdc_lo (bus); +udelay (DELAY ); +mdc_hi (bus); +udelay (DELAY ); +mdc_lo (bus); +udelay (DELAY ); + rdreg <<=1 ; + rdreg |=mdio_read (bus); + } + +mdc_hi (bus); +udelay (DELAY ); +mdc_lo (bus); +udelay (DELAY ); + + ret = rdreg; + +return ret; +} + +static int gpio_mdio_write (struct mii_bus *bus,int phy_id,int location,u16 val) +{ +int i; + +u8 addr = phy_id &0xff ; +u8 reg = location &0xff ; +u16 value = val &0xffff ; + +bitbang_pre (bus,0 , addr, reg); + +/* send the turnaround (10) */ +mdc_lo (bus); +mdio_hi (bus); +udelay (DELAY ); +mdc_hi (bus); +udelay (DELAY ); +mdc_lo (bus); +mdio_lo (bus); +udelay (DELAY ); +mdc_hi (bus); +udelay (DELAY ); + +/* write 16 bits of register data, MSB first */ +for (i =0 ; i <16 ; i++) { +mdc_lo (bus); +if (value &0x8000 ) +mdio_hi (bus); +else +mdio_lo (bus); +udelay (DELAY ); +mdc_hi (bus); +udelay (DELAY ); + value <<=1 ; + } + +/* +* Tri-state the MDIO line. +*/ +mdio_tristate (bus); +mdc_lo (bus); +udelay (DELAY ); +mdc_hi (bus); +udelay (DELAY ); +return 0 ; +} + +static int gpio_mdio_reset (struct mii_bus *bus) +{ +/*nothing here - dunno how to reset it*/ +return 0 ; +} + + +static int __devinit gpio_mdio_probe (struct of_device *ofdev, +const struct of_device_id *match) +{ +struct device *dev = &ofdev->dev; +struct device_node *np = ofdev->node; +struct device_node *gpio_np; +struct mii_bus *new_bus; +struct resource res; +struct gpio_priv *priv; +const unsigned int *prop; +int err =0 ; +int i; + + gpio_np =of_find_compatible_node (NULL ,"gpio" ,"1682m-gpio" ); + +if (!gpio_np) +return -ENODEV ; + + err =of_address_to_resource (gpio_np,0 , &res); +of_node_put (gpio_np); + +if (err) +return -EINVAL ; + +if (!gpio_regs) + gpio_regs =ioremap (res.start,0x100 ); + +if (!gpio_regs) +return -EPERM ; + + priv =kzalloc (sizeof (struct gpio_priv ),GFP_KERNEL ); +if (priv ==NULL ) +return -ENOMEM ; + + new_bus =kzalloc (sizeof (struct mii_bus ),GFP_KERNEL ); + +if (new_bus ==NULL ) +return -ENOMEM ; + + new_bus->name ="pasemi gpio mdio bus" , + new_bus->read = &gpio_mdio_read, + new_bus->write = &gpio_mdio_write, + new_bus->reset = &gpio_mdio_reset, + + prop =get_property (np,"reg" ,NULL ); + new_bus->id = *prop; + new_bus->priv = priv; + + new_bus->phy_mask =0 ; + + new_bus->irq =kmalloc (sizeof (int )*PHY_MAX_ADDR ,GFP_KERNEL ); +for (i =0 ; i <PHY_MAX_ADDR ; ++i) + new_bus->irq[i] =irq_create_mapping (NULL ,10 ); + + + prop =get_property (np,"mdc-pin" ,NULL ); + priv->mdc_pin = *prop; + + prop =get_property (np,"mdio-pin" ,NULL ); + priv->mdio_pin = *prop; + + new_bus->dev = dev; +dev_set_drvdata (dev, new_bus); + + err =mdiobus_register (new_bus); + +if (0 != err) { +printk (KERN_ERR "%s: Cannot register as MDIO bus, err %d\n" , + new_bus->name, err); + goto bus_register_fail; + } + +return 0 ; + +bus_register_fail: +kfree (new_bus); + +return err; +} + + +static int gpio_mdio_remove (struct of_device *dev) +{ +struct mii_bus *bus =dev_get_drvdata (&dev->dev); + +mdiobus_unregister (bus); + +dev_set_drvdata (&dev->dev,NULL ); + +kfree (bus->priv); + bus->priv =NULL ; +kfree (bus); + +return 0 ; +} + +static struct of_device_id gpio_mdio_match[] = +{ + { + .compatible ="gpio-mdio" , + }, + {}, +}; + +static struct of_platform_driver gpio_mdio_driver = +{ + .name ="gpio-mdio-bitbang" , + .match_table = gpio_mdio_match, + .probe = gpio_mdio_probe, + .remove = gpio_mdio_remove, +}; + +int gpio_mdio_init (void ) +{ +return of_register_platform_driver (&gpio_mdio_driver); +} + +void gpio_mdio_exit (void ) +{ +of_unregister_platform_driver (&gpio_mdio_driver); +} +device_initcall (gpio_mdio_init); +
arch/powerpc/platforms/pasemi/Makefile +1 -1
@@ -1,3 +1,3 @@ -obj-y += setup.o pci.o time.o idle.o powersave.o iommu.o +obj-y += setup.o pci.o time.o idle.o powersave.o iommu.o gpio_mdio.o obj-$(CONFIG_PPC_PASEMI_CPUFREQ) += cpufreq.o
arch/powerpc/platforms/pasemi/setup.c +14 -0
@@ -209,6 +209,20 @@ static void __init pas_init_early(void)iommu_init_early_pasemi (); } +static struct of_device_id pasemi_bus_ids[] = { + { .type ="sdc" , }, + {}, +}; + +static int __init pasemi_publish_devices (void ) +{ +/* Publish OF platform devices for southbridge IOs */ +of_platform_bus_probe (NULL , pasemi_bus_ids,NULL ); + +return 0 ; +} +device_initcall (pasemi_publish_devices); +/* * Called very early, MMU is off, device-tree isn't unflattened
Re: [PATCH] [5/5] [v2] pasemi: GPIO MDIO of_platform driver
I just noticed this in arch/powerpc/platforms/pasemi/setup.c:
Quoted 9 lines
arch/powerpc/platforms/pasemi/setup.c +3
-0@@ -209,6 +209,20 @@ static void __init pas_init_early(void)iommu_init_early_pasemi (); } +static struct of_device_id pasemi_bus_ids[] = { + { .type ="sdc" , }, + {},
arch/powerpc/platforms/pasemi/setup.c static void __init pas_init_early(void) · line 224
Quoted 10 lines
arch/powerpc/platforms/pasemi/setup.c +10
-0+}; + +static int __init pasemi_publish_devices (void ) +{ +/* Publish OF platform devices for southbridge IOs */ +of_platform_bus_probe (NULL , pasemi_bus_ids,NULL ); + +return 0 ; +} +device_initcall (pasemi_publish_devices);
Oof. Please make sure you only call of_platform_bus_probe if you are actually on a pasemi platform... :)
Paul.
Re: [PATCH] [5/5] [v2] pasemi: GPIO MDIO of_platform driver
Quoted 4 lines · Paul Mackerras
I just noticed this in
arch/powerpc/platforms/pasemi/setup.c:Oof. Please make sure you only call
of_platform_bus_probeif you are actually on a pasemi platform... :)
Check your inbox. :-) Benh just pinged me about it on IRC as well.
-Olof