9
0
Fork 0

Merge branch 'for-next/driver'

This commit is contained in:
Sascha Hauer 2012-10-03 21:09:34 +02:00
commit d4541ee94f
63 changed files with 1938 additions and 377 deletions

View File

@ -32,17 +32,45 @@
#include <common.h>
#include <init.h>
#include <clock.h>
#include <errno.h>
#include <notifier.h>
#include <mach/imx-regs.h>
#include <mach/clock.h>
#include <io.h>
#define GPT(x) __REG(IMX_TIM1_BASE + (x))
#define timer_base IOMEM(IMX_TIM1_BASE)
/* Part 1: Registers */
# define GPT_TCTL 0x00
# define GPT_TPRER 0x04
/* Part 2: Bitfields */
#define TCTL_SWR (1 << 15) /* Software reset */
#define IMX1_TCTL_FRR (1 << 8) /* Freerun / restart */
#define IMX31_TCTL_FRR (1 << 9) /* Freerun / restart */
#define IMX1_TCTL_CLKSOURCE_IPG (1 << 1) /* Clock source bit position */
#define IMX31_TCTL_CLKSOURCE_IPG (1 << 6) /* Clock source bit position */
#define TCTL_TEN (1 << 0) /* Timer enable */
struct imx_gpt_regs {
unsigned int tcn;
uint32_t tctl_val;
};
static struct imx_gpt_regs regs_imx1 = {
.tcn = 0x10,
.tctl_val = IMX1_TCTL_FRR | IMX1_TCTL_CLKSOURCE_IPG | TCTL_TEN,
};
static struct imx_gpt_regs regs_imx31 = {
.tcn = 0x24,
.tctl_val = IMX31_TCTL_FRR | IMX31_TCTL_CLKSOURCE_IPG | TCTL_TEN,
};
static struct imx_gpt_regs *regs;
static void __iomem *timer_base;
static uint64_t imx_clocksource_read(void)
{
return readl(timer_base + GPT_TCN);
return readl(timer_base + regs->tcn);
}
static struct clocksource cs = {
@ -61,10 +89,20 @@ static struct notifier_block imx_clock_notifier = {
.notifier_call = imx_clocksource_clock_change,
};
static int clocksource_init (void)
static int imx_gpt_probe(struct device_d *dev)
{
int i;
uint32_t val;
int ret;
/* one timer is enough */
if (timer_base)
return -EBUSY;
ret = dev_get_drvdata(dev, (unsigned long *)&regs);
if (ret)
return ret;
timer_base = dev_request_mem_region(dev, 0);
/* setup GP Timer 1 */
writel(TCTL_SWR, timer_base + GPT_TCTL);
@ -85,9 +123,7 @@ static int clocksource_init (void)
writel(0, timer_base + GPT_TCTL); /* We have no udelay by now */
writel(0, timer_base + GPT_TPRER);
val = readl(timer_base + GPT_TCTL);
val |= TCTL_FRR | (1 << TCTL_CLKSOURCE) | TCTL_TEN; /* Freerun Mode, PERCLK1 input */
writel(val, timer_base + GPT_TCTL);
writel(regs->tctl_val, timer_base + GPT_TCTL);
cs.mult = clocksource_hz2mult(imx_get_gptclk(), cs.shift);
@ -98,7 +134,42 @@ static int clocksource_init (void)
return 0;
}
core_initcall(clocksource_init);
static __maybe_unused struct of_device_id imx_gpt_dt_ids[] = {
{
.compatible = "fsl,imx1-gpt",
.data = (unsigned long)&regs_imx1,
}, {
.compatible = "fsl,imx31-gpt",
.data = (unsigned long)&regs_imx31,
}, {
/* sentinel */
}
};
static struct platform_device_id imx_gpt_ids[] = {
{
.name = "imx1-gpt",
.driver_data = (unsigned long)&regs_imx1,
}, {
.name = "imx31-gpt",
.driver_data = (unsigned long)&regs_imx31,
}, {
/* sentinel */
},
};
static struct driver_d imx_gpt_driver = {
.name = "imx-gpt",
.probe = imx_gpt_probe,
.of_compatible = DRV_OF_COMPAT(imx_gpt_dt_ids),
.id_table = imx_gpt_ids,
};
static int imx_gpt_init(void)
{
return register_driver(&imx_gpt_driver);
}
coredevice_initcall(imx_gpt_init);
/*
* Watchdog Registers

View File

@ -30,28 +30,28 @@
#include <gpio.h>
#include <init.h>
#if defined CONFIG_ARCH_IMX1 || defined CONFIG_ARCH_IMX21 || defined CONFIG_ARCH_IMX27
#define GPIO_DR 0x1c
#define GPIO_GDIR 0x00
#define GPIO_PSR 0x24
#define GPIO_ICR1 0x28
#define GPIO_ICR2 0x2C
#define GPIO_IMR 0x30
#define GPIO_ISR 0x34
#else
#define GPIO_DR 0x00
#define GPIO_GDIR 0x04
#define GPIO_PSR 0x08
#define GPIO_ICR1 0x0C
#define GPIO_ICR2 0x10
#define GPIO_IMR 0x14
#define GPIO_ISR 0x18
#define GPIO_ISR 0x18
#endif
struct imx_gpio_chip {
void __iomem *base;
struct gpio_chip chip;
struct imx_gpio_regs *regs;
};
struct imx_gpio_regs {
unsigned int dr;
unsigned int gdir;
unsigned int psr;
};
static struct imx_gpio_regs regs_imx1 = {
.dr = 0x1c,
.gdir = 0x00,
.psr = 0x24,
};
static struct imx_gpio_regs regs_imx31 = {
.dr = 0x00,
.gdir = 0x04,
.psr = 0x08,
};
static void imx_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
@ -63,14 +63,14 @@ static void imx_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
if (!base)
return;
val = readl(base + GPIO_DR);
val = readl(base + imxgpio->regs->dr);
if (value)
val |= 1 << gpio;
else
val &= ~(1 << gpio);
writel(val, base + GPIO_DR);
writel(val, base + imxgpio->regs->dr);
}
static int imx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
@ -82,9 +82,9 @@ static int imx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
if (!base)
return -EINVAL;
val = readl(base + GPIO_GDIR);
val = readl(base + imxgpio->regs->gdir);
val &= ~(1 << gpio);
writel(val, base + GPIO_GDIR);
writel(val, base + imxgpio->regs->gdir);
return 0;
}
@ -98,9 +98,9 @@ static int imx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int
gpio_set_value(gpio + chip->base, value);
val = readl(base + GPIO_GDIR);
val = readl(base + imxgpio->regs->gdir);
val |= 1 << gpio;
writel(val, base + GPIO_GDIR);
writel(val, base + imxgpio->regs->gdir);
return 0;
}
@ -111,7 +111,7 @@ static int imx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
void __iomem *base = imxgpio->base;
u32 val;
val = readl(base + GPIO_PSR);
val = readl(base + imxgpio->regs->psr);
return val & (1 << gpio) ? 1 : 0;
}
@ -126,23 +126,80 @@ static struct gpio_ops imx_gpio_ops = {
static int imx_gpio_probe(struct device_d *dev)
{
struct imx_gpio_chip *imxgpio;
struct imx_gpio_regs *regs;
int ret;
ret = dev_get_drvdata(dev, (unsigned long *)&regs);
if (ret)
return ret;
imxgpio = xzalloc(sizeof(*imxgpio));
imxgpio->base = dev_request_mem_region(dev, 0);
imxgpio->chip.ops = &imx_gpio_ops;
imxgpio->chip.base = -1;
if (dev->id < 0) {
imxgpio->chip.base = of_alias_get_id(dev->device_node, "gpio");
if (imxgpio->chip.base < 0)
return imxgpio->chip.base;
} else {
imxgpio->chip.base = dev->id * 32;
}
imxgpio->chip.ngpio = 32;
imxgpio->chip.dev = dev;
imxgpio->regs = regs;
gpiochip_add(&imxgpio->chip);
dev_info(dev, "probed gpiochip%d with base %d\n", dev->id, imxgpio->chip.base);
dev_dbg(dev, "probed gpiochip%d with base %d\n", dev->id, imxgpio->chip.base);
return 0;
}
static __maybe_unused struct of_device_id imx_gpio_dt_ids[] = {
{
.compatible = "fsl,imx1-gpio",
.data = (unsigned long)&regs_imx1,
}, {
.compatible = "fsl,imx21-gpio",
.data = (unsigned long)&regs_imx1,
}, {
.compatible = "fsl,imx27-gpio",
.data = (unsigned long)&regs_imx1,
}, {
.compatible = "fsl,imx31-gpio",
.data = (unsigned long)&regs_imx31,
}, {
.compatible = "fsl,imx35-gpio",
.data = (unsigned long)&regs_imx31,
}, {
.compatible = "fsl,imx51-gpio",
.data = (unsigned long)&regs_imx31,
}, {
.compatible = "fsl,imx53-gpio",
.data = (unsigned long)&regs_imx31,
}, {
.compatible = "fsl,imx6q-gpio",
.data = (unsigned long)&regs_imx31,
}, {
/* sentinel */
}
};
static struct platform_device_id imx_gpio_ids[] = {
{
.name = "imx1-gpio",
.driver_data = (unsigned long)&regs_imx1,
}, {
.name = "imx31-gpio",
.driver_data = (unsigned long)&regs_imx31,
}, {
/* sentinel */
},
};
static struct driver_d imx_gpio_driver = {
.name = "imx-gpio",
.probe = imx_gpio_probe,
.of_compatible = DRV_OF_COMPAT(imx_gpio_dt_ids),
.id_table = imx_gpio_ids,
};
static int imx_gpio_add(void)

View File

@ -20,10 +20,11 @@
static int imx1_init(void)
{
add_generic_device("imx-gpio", 0, NULL, 0x0021c000, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 1, NULL, 0x0021c100, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 2, NULL, 0x0021c200, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 3, NULL, 0x0021c300, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpt", 0, NULL, 0x00202000, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpio", 0, NULL, 0x0021c000, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpio", 1, NULL, 0x0021c100, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpio", 2, NULL, 0x0021c200, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpio", 3, NULL, 0x0021c300, 0x100, IORESOURCE_MEM, NULL);
return 0;
}

View File

@ -29,12 +29,13 @@ int imx_silicon_revision(void)
static int imx21_init(void)
{
add_generic_device("imx-gpio", 0, NULL, 0x10015000, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 1, NULL, 0x10015100, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 2, NULL, 0x10015200, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 3, NULL, 0x10015300, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 4, NULL, 0x10015400, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 5, NULL, 0x10015500, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpt", 0, NULL, 0x10003000, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpio", 0, NULL, 0x10015000, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpio", 1, NULL, 0x10015100, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpio", 2, NULL, 0x10015200, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpio", 3, NULL, 0x10015300, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpio", 4, NULL, 0x10015400, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpio", 5, NULL, 0x10015500, 0x100, IORESOURCE_MEM, NULL);
return 0;
}

View File

@ -48,10 +48,12 @@ static int imx25_init(void)
add_generic_device("imx_iim", 0, NULL, IMX_IIM_BASE, SZ_4K,
IORESOURCE_MEM, &imx25_iim_pdata);
add_generic_device("imx-gpio", 0, NULL, 0x53fcc000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 1, NULL, 0x53fd0000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 2, NULL, 0x53fa4000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 3, NULL, 0x53f9c000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpt", 0, NULL, 0x53f90000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 0, NULL, 0x53fcc000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 1, NULL, 0x53fd0000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 2, NULL, 0x53fa4000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 3, NULL, 0x53f9c000, 0x1000, IORESOURCE_MEM, NULL);
return 0;
}
coredevice_initcall(imx25_init);

View File

@ -73,12 +73,13 @@ static int imx27_init(void)
imx27_init_max();
add_generic_device("imx-gpio", 0, NULL, 0x10015000, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 1, NULL, 0x10015100, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 2, NULL, 0x10015200, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 3, NULL, 0x10015300, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 4, NULL, 0x10015400, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 5, NULL, 0x10015500, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpt", 0, NULL, 0x10003000, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpio", 0, NULL, 0x10015000, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpio", 1, NULL, 0x10015100, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpio", 2, NULL, 0x10015200, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpio", 3, NULL, 0x10015300, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpio", 4, NULL, 0x10015400, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpio", 5, NULL, 0x10015500, 0x100, IORESOURCE_MEM, NULL);
return 0;
}
coredevice_initcall(imx27_init);
console_initcall(imx27_init);

View File

@ -25,9 +25,10 @@ static int imx31_init(void)
add_generic_device("imx_iim", 0, NULL, IMX_IIM_BASE, SZ_4K,
IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 0, NULL, 0x53fcc000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 1, NULL, 0x53fd0000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 2, NULL, 0x53fa4000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpt", 0, NULL, 0x53f90000, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 0, NULL, 0x53fcc000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 1, NULL, 0x53fd0000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 2, NULL, 0x53fa4000, 0x1000, IORESOURCE_MEM, NULL);
return 0;
}

View File

@ -56,9 +56,10 @@ static int imx35_init(void)
add_generic_device("imx_iim", 0, NULL, IMX_IIM_BASE, SZ_4K,
IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 0, NULL, 0x53fcc000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 1, NULL, 0x53fd0000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 2, NULL, 0x53fa4000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpt", 0, NULL, 0x53f90000, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 0, NULL, 0x53fcc000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 1, NULL, 0x53fd0000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 2, NULL, 0x53fa4000, 0x1000, IORESOURCE_MEM, NULL);
return 0;
}

View File

@ -78,10 +78,11 @@ static int imx51_init(void)
add_generic_device("imx_iim", 0, NULL, MX51_IIM_BASE_ADDR, SZ_4K,
IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 0, NULL, 0x73f84000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 1, NULL, 0x73f88000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 2, NULL, 0x73f8c000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 3, NULL, 0x73f90000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpt", 0, NULL, 0x73fa0000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 0, NULL, 0x73f84000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 1, NULL, 0x73f88000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 2, NULL, 0x73f8c000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 3, NULL, 0x73f90000, 0x1000, IORESOURCE_MEM, NULL);
return 0;
}

View File

@ -74,13 +74,15 @@ static int imx53_init(void)
add_generic_device("imx_iim", 0, NULL, MX53_IIM_BASE_ADDR, SZ_4K,
IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 0, NULL, MX53_GPIO1_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 1, NULL, MX53_GPIO2_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 2, NULL, MX53_GPIO3_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 3, NULL, MX53_GPIO4_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 4, NULL, MX53_GPIO5_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 5, NULL, MX53_GPIO6_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 6, NULL, MX53_GPIO7_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpt", 0, NULL, 0X53fa0000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 0, NULL, MX53_GPIO1_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 1, NULL, MX53_GPIO2_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 2, NULL, MX53_GPIO3_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 3, NULL, MX53_GPIO4_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 4, NULL, MX53_GPIO5_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 5, NULL, MX53_GPIO6_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 6, NULL, MX53_GPIO7_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
return 0;
}
coredevice_initcall(imx53_init);

View File

@ -58,13 +58,14 @@ void imx6_init_lowlevel(void)
static int imx6_init(void)
{
add_generic_device("imx-gpio", 0, NULL, MX6_GPIO1_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 1, NULL, MX6_GPIO2_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 2, NULL, MX6_GPIO3_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 3, NULL, MX6_GPIO4_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 4, NULL, MX6_GPIO5_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 5, NULL, MX6_GPIO6_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
add_generic_device("imx-gpio", 6, NULL, MX6_GPIO7_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpt", 0, NULL, 0x02098000, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 0, NULL, MX6_GPIO1_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 1, NULL, MX6_GPIO2_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 2, NULL, MX6_GPIO3_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 3, NULL, MX6_GPIO4_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 4, NULL, MX6_GPIO5_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 5, NULL, MX6_GPIO6_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
add_generic_device("imx31-gpio", 6, NULL, MX6_GPIO7_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
return 0;
}

View File

@ -207,27 +207,4 @@
#define PD31_PF_TMR2OUT ( GPIO_PORTD | GPIO_PF | 31 )
#define PD31_BIN_SPI2_TXD ( GPIO_PORTD | GPIO_BIN | 31 )
/*
* Definitions for the clocksource driver
*/
/* Part 1: Registers */
# define GPT_TCTL 0x00
# define GPT_TPRER 0x04
# define GPT_TCMP 0x08
# define GPT_TCR 0x0c
# define GPT_TCN 0x10
# define GPT_TSTAT 0x14
/* Part 2: Bitfields */
#define TCTL_SWR (1<<15) /* Software reset */
#define TCTL_FRR (1<<8) /* Freerun / restart */
#define TCTL_CAP (3<<6) /* Capture Edge */
#define TCTL_OM (1<<5) /* output mode */
#define TCTL_IRQEN (1<<4) /* interrupt enable */
#define TCTL_CLKSOURCE (1) /* Clock source bit position */
#define TCTL_TEN (1) /* Timer enable */
#define TPRER_PRES (0xff) /* Prescale */
#define TSTAT_CAPT (1<<1) /* Capture event */
#define TSTAT_COMP (1) /* Compare event */
#endif /* _IMX1_REGS_H */

View File

@ -107,30 +107,6 @@
#define CCSR_32K_SR (1 << 15)
/*
* Definitions for the clocksource driver
*/
/* Part 1: Registers */
# define GPT_TCTL 0x00
# define GPT_TPRER 0x04
# define GPT_TCMP 0x08
# define GPT_TCR 0x0c
# define GPT_TCN 0x10
# define GPT_TSTAT 0x14
/* Part 2: Bitfields */
#define TCTL_SWR (1<<15) /* Software reset */
#define TCTL_CC (1<<10) /* counter clear */
#define TCTL_FRR (1<<8) /* Freerun / restart */
#define TCTL_CAP (3<<6) /* Capture Edge */
#define TCTL_CAPEN (1<<5) /* compare interrupt enable */
#define TCTL_COMPEN (1<<4) /* compare interrupt enable */
#define TCTL_CLKSOURCE (1) /* Clock source bit position */
#define TCTL_TEN (1) /* Timer enable */
#define TPRER_PRES (0xff) /* Prescale */
#define TSTAT_CAPT (1<<1) /* Capture event */
#define TSTAT_COMP (1) /* Compare event */
#define IMX_CS0_BASE 0xC8000000
#define IMX_CS1_BASE 0xCC000000
#define IMX_CS2_BASE 0xD0000000

View File

@ -107,33 +107,6 @@
#define CSCR_L(x) (WEIM_BASE + 4 + (x) * 0x10)
#define CSCR_A(x) (WEIM_BASE + 8 + (x) * 0x10)
/*
* Definitions for the clocksource driver
*
* These defines are using the i.MX1/27 notation
* to reuse the clocksource code for these CPUs
* on the i.MX35
*/
/* Part 1: Registers */
#define GPT_TCTL 0x00
#define GPT_TPRER 0x04
#define GPT_TCMP 0x10
#define GPT_TCR 0x1c
#define GPT_TCN 0x24
#define GPT_TSTAT 0x08
/* Part 2: Bitfields */
#define TCTL_SWR (1<<15) /* Software reset */
#define TCTL_FRR (1<<9) /* Freerun / restart */
#define TCTL_CAP (3<<6) /* Capture Edge */
#define TCTL_OM (1<<5) /* output mode */
#define TCTL_IRQEN (1<<4) /* interrupt enable */
#define TCTL_CLKSOURCE (6) /* Clock source bit position */
#define TCTL_TEN (1) /* Timer enable */
#define TPRER_PRES (0xff) /* Prescale */
#define TSTAT_CAPT (1<<1) /* Capture event */
#define TSTAT_COMP (1) /* Compare event */
/*
* Watchdog Registers
*/

View File

@ -221,29 +221,6 @@
#define ESDCFG_TWTR (1 << 20)
#define ESDCFG_TXP(x) (((x) & 0x3) << 21)
/*
* Definitions for the clocksource driver
*/
/* Part 1: Registers */
# define GPT_TCTL 0x00
# define GPT_TPRER 0x04
# define GPT_TCMP 0x08
# define GPT_TCR 0x0c
# define GPT_TCN 0x10
# define GPT_TSTAT 0x14
/* Part 2: Bitfields */
#define TCTL_SWR (1<<15) /* Software reset */
#define TCTL_FRR (1<<8) /* Freerun / restart */
#define TCTL_CAP (3<<6) /* Capture Edge */
#define TCTL_OM (1<<5) /* output mode */
#define TCTL_IRQEN (1<<4) /* interrupt enable */
#define TCTL_CLKSOURCE (1) /* Clock source bit position */
#define TCTL_TEN (1) /* Timer enable */
#define TPRER_PRES (0xff) /* Prescale */
#define TSTAT_CAPT (1<<1) /* Capture event */
#define TSTAT_COMP (1) /* Compare event */
#define IMX_CS0_BASE 0xC0000000
#define IMX_CS1_BASE 0xC8000000
#define IMX_CS2_BASE 0xD0000000

View File

@ -57,33 +57,6 @@
#define IMX_CS5_BASE 0xB6000000
#define IMX_CS5_RANGE (32 * 1024 * 1024)
/*
* Definitions for the clocksource driver
*
* These defines are using the i.MX1/27 notation
* to reuse the clocksource code for these CPUs
* on the i.MX31
*/
/* Part 1: Registers */
#define GPT_TCTL 0x00
#define GPT_TPRER 0x04
#define GPT_TCMP 0x10
#define GPT_TCR 0x1c
#define GPT_TCN 0x24
#define GPT_TSTAT 0x08
/* Part 2: Bitfields */
#define TCTL_SWR (1<<15) /* Software reset */
#define TCTL_FRR (1<<9) /* Freerun / restart */
#define TCTL_CAP (3<<6) /* Capture Edge */
#define TCTL_OM (1<<5) /* output mode */
#define TCTL_IRQEN (1<<4) /* interrupt enable */
#define TCTL_CLKSOURCE (6) /* Clock source bit position */
#define TCTL_TEN (1) /* Timer enable */
#define TPRER_PRES (0xff) /* Prescale */
#define TSTAT_CAPT (1<<1) /* Capture event */
#define TSTAT_COMP (1) /* Compare event */
#if 0
#define IMX_IO_BASE 0x00200000

View File

@ -116,32 +116,4 @@
#define CSCR_L(x) (WEIM_BASE + 4 + (x) * 0x10)
#define CSCR_A(x) (WEIM_BASE + 8 + (x) * 0x10)
/*
* Definitions for the clocksource driver
*
* These defines are using the i.MX1/27 notation
* to reuse the clocksource code for these CPUs
* on the i.MX35
*/
/* Part 1: Registers */
#define GPT_TCTL 0x00
#define GPT_TPRER 0x04
#define GPT_TCMP 0x10
#define GPT_TCR 0x1c
#define GPT_TCN 0x24
#define GPT_TSTAT 0x08
/* Part 2: Bitfields */
#define TCTL_SWR (1<<15) /* Software reset */
#define TCTL_FRR (1<<9) /* Freerun / restart */
#define TCTL_CAP (3<<6) /* Capture Edge */
#define TCTL_OM (1<<5) /* output mode */
#define TCTL_IRQEN (1<<4) /* interrupt enable */
#define TCTL_CLKSOURCE (6) /* Clock source bit position */
#define TCTL_TEN (1) /* Timer enable */
#define TPRER_PRES (0xff) /* Prescale */
#define TSTAT_CAPT (1<<1) /* Capture event */
#define TSTAT_COMP (1) /* Compare event */
#endif /* __ASM_ARCH_MX35_REGS_H */

View File

@ -5,13 +5,6 @@
#define IMX_WDT_BASE 0x73f98000
#define IMX_IOMUXC_BASE 0x73fa8000
#define GPT_TCTL 0x00
#define GPT_TPRER 0x04
#define GPT_TCMP 0x10
#define GPT_TCR 0x1c
#define GPT_TCN 0x24
#define GPT_TSTAT 0x08
/* WEIM registers */
#define WEIM_CSxGCR1(n) (((n) * 0x18) + 0x00)
#define WEIM_CSxGCR2(n) (((n) * 0x18) + 0x04)
@ -22,18 +15,6 @@
#define WEIM_WIAR 0x94
#define WEIM_EAR 0x98
/* Part 2: Bitfields */
#define TCTL_SWR (1<<15) /* Software reset */
#define TCTL_FRR (1<<9) /* Freerun / restart */
#define TCTL_CAP (3<<6) /* Capture Edge */
#define TCTL_OM (1<<5) /* output mode */
#define TCTL_IRQEN (1<<4) /* interrupt enable */
#define TCTL_CLKSOURCE (6) /* Clock source bit position */
#define TCTL_TEN (1) /* Timer enable */
#define TPRER_PRES (0xff) /* Prescale */
#define TSTAT_CAPT (1<<1) /* Capture event */
#define TSTAT_COMP (1) /* Compare event */
#define MX51_IROM_BASE_ADDR 0x0
/*

View File

@ -5,25 +5,6 @@
#define IMX_WDT_BASE 0X53F98000
#define IMX_IOMUXC_BASE 0X53FA8000
#define GPT_TCTL 0x00
#define GPT_TPRER 0x04
#define GPT_TCMP 0x10
#define GPT_TCR 0x1c
#define GPT_TCN 0x24
#define GPT_TSTAT 0x08
/* Part 2: Bitfields */
#define TCTL_SWR (1<<15) /* Software reset */
#define TCTL_FRR (1<<9) /* Freerun / restart */
#define TCTL_CAP (3<<6) /* Capture Edge */
#define TCTL_OM (1<<5) /* output mode */
#define TCTL_IRQEN (1<<4) /* interrupt enable */
#define TCTL_CLKSOURCE (6) /* Clock source bit position */
#define TCTL_TEN (1) /* Timer enable */
#define TPRER_PRES (0xff) /* Prescale */
#define TSTAT_CAPT (1<<1) /* Capture event */
#define TSTAT_COMP (1) /* Compare event */
#define MX53_IROM_BASE_ADDR 0x0
/*

View File

@ -5,25 +5,6 @@
#define IMX_WDT_BASE 0x020bc000
#define IMX_IOMUXC_BASE 0x020e0000
#define GPT_TCTL 0x00
#define GPT_TPRER 0x04
#define GPT_TCMP 0x10
#define GPT_TCR 0x1c
#define GPT_TCN 0x24
#define GPT_TSTAT 0x08
/* Part 2: Bitfields */
#define TCTL_SWR (1<<15) /* Software reset */
#define TCTL_FRR (1<<9) /* Freerun / restart */
#define TCTL_CAP (3<<6) /* Capture Edge */
#define TCTL_OM (1<<5) /* output mode */
#define TCTL_IRQEN (1<<4) /* interrupt enable */
#define TCTL_CLKSOURCE (6) /* Clock source bit position */
#define TCTL_TEN (1) /* Timer enable */
#define TPRER_PRES (0xff) /* Prescale */
#define TSTAT_CAPT (1<<1) /* Capture event */
#define TSTAT_COMP (1) /* Compare event */
#define MX6_AIPS1_ARB_BASE_ADDR 0x02000000
#define MX6_AIPS2_ARB_BASE_ADDR 0x02100000

View File

@ -468,7 +468,17 @@ config CMD_OFTREE
tristate
select OFTREE
prompt "oftree"
select FDT
help
The oftree command has support for dumping devicetrees and, if
enabled, to probe devices from the devicetree
config CMD_OFTREE_PROBE
bool
depends on CMD_OFTREE
select OFDEVICE
prompt "oftree probe support"
help
This enables the -p option to probe devices from the devicetree
endmenu

View File

@ -48,7 +48,8 @@ static int do_oftree(int argc, char *argv[])
char *file = NULL;
const char *node = "/";
int dump = 0;
int parse = 0;
int probe = 0;
int ret;
while ((opt = getopt(argc, argv, "dpfn:")) > 0) {
switch (opt) {
@ -56,7 +57,12 @@ static int do_oftree(int argc, char *argv[])
dump = 1;
break;
case 'p':
parse = 1;
if (IS_ENABLED(CONFIG_CMD_OFTREE_PROBE)) {
probe = 1;
} else {
printf("oftree device probe support disabled\n");
return COMMAND_ERROR_USAGE;
}
break;
case 'f':
free(barebox_fdt);
@ -71,7 +77,7 @@ static int do_oftree(int argc, char *argv[])
if (optind < argc)
file = argv[optind];
if (!dump && !parse)
if (!dump && !probe)
return COMMAND_ERROR_USAGE;
if (dump) {
@ -95,7 +101,7 @@ static int do_oftree(int argc, char *argv[])
return 0;
}
if (parse) {
if (probe) {
if (!file)
return COMMAND_ERROR_USAGE;
@ -105,17 +111,13 @@ static int do_oftree(int argc, char *argv[])
return 1;
}
fdt = xrealloc(fdt, size + 0x8000);
fdt_open_into(fdt, fdt, size + 0x8000);
if (!fdt) {
printf("unable to read %s\n", file);
ret = of_parse_dtb(fdt);
if (ret) {
printf("parse oftree: %s\n", strerror(-ret));
return 1;
}
if (barebox_fdt)
free(barebox_fdt);
barebox_fdt = fdt;
of_probe();
}
return 0;
@ -123,7 +125,7 @@ static int do_oftree(int argc, char *argv[])
BAREBOX_CMD_HELP_START(oftree)
BAREBOX_CMD_HELP_USAGE("oftree [OPTIONS]\n")
BAREBOX_CMD_HELP_OPT ("-p <FILE>", "parse and store oftree from <file>\n")
BAREBOX_CMD_HELP_OPT ("-p <FILE>", "probe devices in oftree from <file>\n")
BAREBOX_CMD_HELP_OPT ("-d [FILE]", "dump oftree from [FILE] or the parsed tree if no file is given\n")
BAREBOX_CMD_HELP_OPT ("-f", "free stored oftree\n")
BAREBOX_CMD_HELP_END

View File

@ -57,7 +57,7 @@ static int is_printable_string(const void *data, int len)
* a string, concatenated strings, a byte, word, double word, or (if all
* else fails) it is printed as a stream of bytes.
*/
static void print_data(const void *data, int len)
void of_print_property(const void *data, int len)
{
int j;
@ -169,7 +169,7 @@ int fdt_print(struct fdt_header *working_fdt, const char *pathp)
printf_indent(level, "%s;\n", pathp);
} else {
printf_indent(level, "%s = ", pathp);
print_data(nodep, len);
of_print_property(nodep, len);
printf(";\n");
}
break;

View File

@ -20,5 +20,6 @@ source "drivers/watchdog/Kconfig"
source "drivers/pwm/Kconfig"
source "drivers/dma/Kconfig"
source "drivers/gpio/Kconfig"
source "drivers/of/Kconfig"
endmenu

View File

@ -19,3 +19,4 @@ obj-y += misc/
obj-y += dma/
obj-y += watchdog/
obj-y += gpio/
obj-$(CONFIG_OFDEVICE) += of/

View File

@ -1,3 +1,4 @@
obj-y += bus.o
obj-y += driver.o
obj-y += platform.o
obj-y += resource.o

37
drivers/base/bus.c Normal file
View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
*
* Under GPLv2
*/
#include <common.h>
#include <driver.h>
#include <errno.h>
LIST_HEAD(bus_list);
EXPORT_SYMBOL(bus_list);
struct bus_type *get_bus_by_name(const char *name)
{
struct bus_type *bus;
for_each_bus(bus) {
if(!strcmp(bus->name, name))
return bus;
}
return NULL;
}
int bus_register(struct bus_type *bus)
{
if (get_bus_by_name(bus->name))
return -EEXIST;
INIT_LIST_HEAD(&bus->device_list);
INIT_LIST_HEAD(&bus->driver_list);
list_add_tail(&bus->list, &bus_list);
return 0;
}

View File

@ -85,8 +85,6 @@ static int match(struct driver_d *drv, struct device_d *dev)
dev->driver = drv;
if (dev->bus != drv->bus)
goto err_out;
if (dev->bus->match(dev, drv))
goto err_out;
if (dev->bus->probe(dev))
@ -116,18 +114,29 @@ int register_device(struct device_d *new_device)
debug ("register_device: %s\n", dev_name(new_device));
if (!new_device->bus) {
// dev_err(new_device, "no bus type associated. Needs fixup\n");
if (!new_device->bus)
new_device->bus = &platform_bus;
if (new_device->bus == &platform_bus && new_device->resource) {
struct device_d *dev;
bus_for_each_device(new_device->bus, dev) {
if (!dev->resource)
continue;
if (dev->resource->start == new_device->resource->start) {
return -EBUSY;
}
}
}
list_add_tail(&new_device->list, &device_list);
list_add_tail(&new_device->bus_list, &new_device->bus->device_list);
INIT_LIST_HEAD(&new_device->children);
INIT_LIST_HEAD(&new_device->cdevs);
INIT_LIST_HEAD(&new_device->parameters);
INIT_LIST_HEAD(&new_device->active);
for_each_driver(drv) {
bus_for_each_driver(new_device->bus, drv) {
if (!match(drv, new_device))
break;
}
@ -159,6 +168,7 @@ int unregister_device(struct device_d *old_dev)
}
list_del(&old_dev->list);
list_del(&old_dev->bus_list);
list_del(&old_dev->active);
/* remove device from parents child list */
@ -212,13 +222,14 @@ int register_driver(struct driver_d *drv)
}
list_add_tail(&drv->list, &driver_list);
list_add_tail(&drv->bus_list, &drv->bus->driver_list);
if (!drv->info)
drv->info = noinfo;
if (!drv->shortinfo)
drv->shortinfo = noshortinfo;
for_each_device(dev)
bus_for_each_device(drv->bus, dev)
match(drv, dev);
return 0;
@ -313,6 +324,25 @@ const char *dev_id(const struct device_d *dev)
return buf;
}
int dev_printf(const struct device_d *dev, const char *format, ...)
{
va_list args;
int ret = 0;
if (dev->driver && dev->driver->name)
ret += printf("%s ", dev->driver->name);
ret += printf("%s: ", dev_name(dev));
va_start(args, format);
ret += vprintf(format, args);
va_end(args);
return ret;
}
void devices_shutdown(void)
{
struct device_d *dev;
@ -357,6 +387,21 @@ static int do_devinfo_subtree(struct device_d *dev, int depth)
return 0;
}
int dev_get_drvdata(struct device_d *dev, unsigned long *data)
{
if (dev->of_id_entry) {
*data = dev->of_id_entry->data;
return 0;
}
if (dev->id_entry) {
*data = dev->id_entry->driver_data;
return 0;
}
return -ENODEV;
}
static int do_devinfo(int argc, char *argv[])
{
struct device_d *dev;
@ -406,6 +451,12 @@ static int do_devinfo(int argc, char *argv[])
list_for_each_entry(param, &dev->parameters, list)
printf("%16s = %s\n", param->name, dev_get_param(dev, param->name));
#ifdef CONFIG_OFDEVICE
if (dev->device_node) {
printf("\ndevice node: %s\n", dev->device_node->full_name);
of_print_nodes(dev->device_node, 0);
}
#endif
}
return 0;

View File

@ -21,10 +21,31 @@
*/
#include <common.h>
#include <driver.h>
#include <errno.h>
#include <init.h>
static int platform_match(struct device_d *dev, struct driver_d *drv)
{
return strcmp(dev->name, drv->name) ? -1 : 0;
if (IS_ENABLED(CONFIG_OFDEVICE) && dev->device_node &&
drv->of_compatible)
return of_match(dev, drv);
if (!strcmp(dev->name, drv->name))
return 0;
if (drv->id_table) {
struct platform_device_id *id = drv->id_table;
while (id->name) {
if (!strcmp(id->name, dev->name)) {
dev->id_entry = id;
return 0;
}
id++;
}
}
return -1;
}
static int platform_probe(struct device_d *dev)
@ -44,15 +65,8 @@ struct bus_type platform_bus = {
.remove = platform_remove,
};
#if 0
LIST_HEAD(bus_list);
EXPORT_SYMBOL(bus_list);
int bus_register(struct bus_type *bus)
static int plarform_init(void)
{
list_add_tail(&bus->list, &bus_list);
return 0;
return bus_register(&platform_bus);
}
#endif
pure_initcall(plarform_init);

View File

@ -312,7 +312,7 @@ static struct driver_d at25_driver = {
static int at25_init(void)
{
register_driver(&at25_driver);
spi_register_driver(&at25_driver);
return 0;
}

View File

@ -145,7 +145,7 @@ static int stmpe_gpio_probe(struct device_d *dev)
return ret;
}
dev_info(dev, "probed stmpe gpiochip%d with base %d\n", dev->id, stmpegpio->chip.base);
dev_dbg(dev, "probed stmpe gpiochip%d with base %d\n", dev->id, stmpegpio->chip.base);
return 0;
}

View File

@ -21,6 +21,7 @@
#include <errno.h>
#include <malloc.h>
#include <xfuncs.h>
#include <init.h>
#include <i2c/i2c.h>
@ -251,6 +252,7 @@ struct i2c_client *i2c_new_device(struct i2c_adapter *adapter,
strcpy(client->dev.name, chip->type);
client->dev.type_data = client;
client->dev.platform_data = chip->platform_data;
client->dev.bus = &i2c_bus;
client->adapter = adapter;
client->addr = chip->addr;
@ -372,3 +374,31 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
return 0;
}
EXPORT_SYMBOL(i2c_add_numbered_adapter);
static int i2c_match(struct device_d *dev, struct driver_d *drv)
{
return strcmp(dev->name, drv->name) ? -1 : 0;
}
static int i2c_probe(struct device_d *dev)
{
return dev->driver->probe(dev);
}
static void i2c_remove(struct device_d *dev)
{
dev->driver->remove(dev);
}
struct bus_type i2c_bus = {
.name = "i2c",
.match = i2c_match,
.probe = i2c_probe,
.remove = i2c_remove,
};
static int i2c_bus_init(void)
{
return bus_register(&i2c_bus);
}
pure_initcall(i2c_bus_init);

View File

@ -567,16 +567,28 @@ static int fsl_esdhc_probe(struct device_d *dev)
return 0;
}
static __maybe_unused struct of_device_id fsl_esdhc_compatible[] = {
{
.compatible = "fsl,imx51-esdhc",
}, {
.compatible = "fsl,imx53-esdhc",
}, {
.compatible = "fsl,imx6q-usdhc",
}, {
/* sentinel */
}
};
static struct driver_d fsl_esdhc_driver = {
.name = "imx-esdhc",
.probe = fsl_esdhc_probe,
.name = "imx-esdhc",
.probe = fsl_esdhc_probe,
.of_compatible = DRV_OF_COMPAT(fsl_esdhc_compatible),
};
static int fsl_esdhc_init_driver(void)
{
register_driver(&fsl_esdhc_driver);
return 0;
register_driver(&fsl_esdhc_driver);
return 0;
}
device_initcall(fsl_esdhc_init_driver);

View File

@ -423,7 +423,7 @@ static struct driver_d spi_mci_driver = {
static int spi_mci_init_driver(void)
{
register_driver(&spi_mci_driver);
spi_register_driver(&spi_mci_driver);
return 0;
}

View File

@ -103,7 +103,7 @@ static struct driver_d lp_driver = {
static int lp_init(void)
{
register_driver(&lp_driver);
i2c_register_driver(&lp_driver);
return 0;
}

View File

@ -336,31 +336,51 @@ static int mc_probe(struct device_d *dev, enum mc13xxx_mode mode)
return 0;
}
static __maybe_unused struct of_device_id mc13892_dt_ids[] = {
{
.compatible = "fsl,mc13892",
}, {
.compatible = "fsl,mc13783",
}, {
/* sentinel */
}
};
#ifdef CONFIG_I2C
static int mc_i2c_probe(struct device_d *dev)
{
return mc_probe(dev, MC13XXX_MODE_I2C);
}
static struct driver_d mc_i2c_driver = {
.name = "mc13xxx-i2c",
.probe = mc_i2c_probe,
.of_compatible = DRV_OF_COMPAT(mc13892_dt_ids),
};
static int mc_i2c_init(void)
{
return i2c_register_driver(&mc_i2c_driver);
}
device_initcall(mc_i2c_init);
#endif
#ifdef CONFIG_SPI
static int mc_spi_probe(struct device_d *dev)
{
return mc_probe(dev, MC13XXX_MODE_SPI);
}
static struct driver_d mc_i2c_driver = {
.name = "mc13xxx-i2c",
.probe = mc_i2c_probe,
};
static struct driver_d mc_spi_driver = {
.name = "mc13xxx-spi",
.probe = mc_spi_probe,
.of_compatible = DRV_OF_COMPAT(mc13892_dt_ids),
};
static int mc_init(void)
static int mc_spi_init(void)
{
register_driver(&mc_i2c_driver);
register_driver(&mc_spi_driver);
return 0;
return spi_register_driver(&mc_spi_driver);
}
device_initcall(mc_init);
device_initcall(mc_spi_init);
#endif

View File

@ -134,7 +134,7 @@ static struct driver_d mc34704_driver = {
static int mc34704_init(void)
{
register_driver(&mc34704_driver);
return 0;
i2c_register_driver(&mc34704_driver);
return 0;
}
device_initcall(mc34704_init);

View File

@ -266,31 +266,40 @@ static int mc_probe(struct device_d *dev, enum mc34708_mode mode)
return 0;
}
#ifdef CONFIG_I2C
static int mc_i2c_probe(struct device_d *dev)
{
return mc_probe(dev, MC34708_MODE_I2C);
}
static int mc_spi_probe(struct device_d *dev)
{
return mc_probe(dev, MC34708_MODE_SPI);
}
static struct driver_d mc_i2c_driver = {
.name = "mc34708-i2c",
.probe = mc_i2c_probe,
};
static int mc_i2c_init(void)
{
return i2c_register_driver(&mc_i2c_driver);
}
device_initcall(mc_i2c_init);
#endif
#ifdef CONFIG_SPI
static int mc_spi_probe(struct device_d *dev)
{
return mc_probe(dev, MC34708_MODE_SPI);
}
static struct driver_d mc_spi_driver = {
.name = "mc34708-spi",
.probe = mc_spi_probe,
};
static int mc_init(void)
static int mc_spi_init(void)
{
register_driver(&mc_i2c_driver);
register_driver(&mc_spi_driver);
return 0;
return spi_register_driver(&mc_spi_driver);
}
device_initcall(mc_init);
device_initcall(mc_spi_init);
#endif

View File

@ -146,7 +146,7 @@ static struct driver_d mc_driver = {
static int mc_init(void)
{
register_driver(&mc_driver);
i2c_register_driver(&mc_driver);
return 0;
}

View File

@ -146,7 +146,7 @@ static struct driver_d stmpe_driver = {
static int stmpe_init(void)
{
register_driver(&stmpe_driver);
i2c_register_driver(&stmpe_driver);
return 0;
}

View File

@ -53,7 +53,7 @@ static struct driver_d twl_driver = {
static int twl_init(void)
{
register_driver(&twl_driver);
i2c_register_driver(&twl_driver);
return 0;
}

View File

@ -49,7 +49,7 @@ static struct driver_d twl_driver = {
static int twl_init(void)
{
register_driver(&twl_driver);
i2c_register_driver(&twl_driver);
return 0;
}

View File

@ -125,5 +125,12 @@ config DRIVER_NET_GIANFAR
source "drivers/net/usb/Kconfig"
config DRIVER_NET_MICREL
depends on SPI
bool "Micrel KSZ8864RMN Ethernet Switch driver"
help
This option enables support for enabling the Micrel
KSZ8864RMN Ethernet Switch over SPI.
endmenu

View File

@ -15,3 +15,4 @@ obj-$(CONFIG_DRIVER_NET_TSE) += altera_tse.o
obj-$(CONFIG_DRIVER_NET_KS8851_MLL) += ks8851_mll.o
obj-$(CONFIG_DRIVER_NET_DESIGNWARE) += designware.o
obj-$(CONFIG_DRIVER_NET_GIANFAR) += gianfar.o
obj-$(CONFIG_DRIVER_NET_MICREL) += ksz8864rmn.o

191
drivers/net/ksz8864rmn.c Normal file
View File

@ -0,0 +1,191 @@
/*
* Copyright (C) 2012 Jan Luebbe, Pengutronix
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* 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 <common.h>
#include <init.h>
#include <driver.h>
#include <spi/spi.h>
#include <errno.h>
#define REG_ID0 0x00
#define REG_ID1 0x01
#define REG_GC00 0x02
#define REG_GC01 0x03
#define REG_GC02 0x04
#define REG_GC03 0x05
#define REG_GC04 0x06
#define REG_GC05 0x07
#define REG_GC06 0x08
#define REG_GC07 0x09
#define REG_GC08 0x0a
#define REG_GC09 0x0b
#define REG_GC10 0x0c
#define REG_GC11 0x0d
#define REG_PSTAT1(p) (0x10 * p + 0xe)
#define REG_PSTAT2(p) (0x10 * p + 0xf)
#define CMD_WRITE 0x02
#define CMD_READ 0x03
struct micrel_switch_priv {
struct cdev cdev;
struct spi_device *spi;
};
static int micrel_switch_read_reg(struct spi_device *spi, uint8_t reg)
{
uint8_t tx[2];
uint8_t rx[1];
int ret;
tx[0] = CMD_READ;
tx[1] = reg;
ret = spi_write_then_read(spi, tx, 2, rx, 1);
if (ret < 0)
return ret;
return rx[0];
}
static void micrel_switch_write_reg(struct spi_device *spi, uint8_t reg, uint8_t val)
{
uint8_t tx[3];
tx[0] = CMD_WRITE;
tx[1] = reg;
tx[2] = val;
spi_write_then_read(spi, tx, 3, NULL, 0);
}
static int micrel_switch_enable_set(struct device_d *dev, struct param_d *param,
const char *val)
{
struct spi_device *spi = (struct spi_device *)dev->type_data;
int enable;
char *new;
if (!val)
return dev_param_set_generic(dev, param, NULL);
enable = simple_strtoul(val, NULL, 0);
if (enable) {
micrel_switch_write_reg(spi, REG_ID1, 1);
new = "1";
} else {
micrel_switch_write_reg(spi, REG_ID1, 0);
new = "0";
}
dev_param_set_generic(dev, param, new);
return 0;
}
static ssize_t micel_switch_read(struct cdev *cdev, void *_buf, size_t count, loff_t offset, ulong flags)
{
int i, ret;
uint8_t *buf = _buf;
struct micrel_switch_priv *priv = cdev->priv;
for (i = 0; i < count; i++) {
ret = micrel_switch_read_reg(priv->spi, offset);
if (ret < 0)
return ret;
*buf = ret;
buf++;
offset++;
}
return count;
}
static ssize_t micel_switch_write(struct cdev *cdev, const void *_buf, size_t count, loff_t offset, ulong flags)
{
int i;
const uint8_t *buf = _buf;
struct micrel_switch_priv *priv = cdev->priv;
for (i = 0; i < count; i++) {
micrel_switch_write_reg(priv->spi, offset, *buf);
buf++;
offset++;
}
return count;
}
static struct file_operations micrel_switch_ops = {
.read = micel_switch_read,
.write = micel_switch_write,
.lseek = dev_lseek_default,
};
static int micrel_switch_probe(struct device_d *dev)
{
struct micrel_switch_priv *priv;
int ret = 0;
priv = xzalloc(sizeof(*priv));
dev->priv = priv;
priv->spi = (struct spi_device *)dev->type_data;
priv->spi->mode = SPI_MODE_0;
priv->spi->bits_per_word = 8;
ret = micrel_switch_read_reg(priv->spi, REG_ID0);
if (ret < 0) {
dev_err(&priv->spi->dev, "failed to read device id\n");
return ret;
}
if (ret != 0x95) {
dev_err(&priv->spi->dev, "unknown device id: %02x\n", ret);
return -ENODEV;
}
priv->cdev.name = asprintf("switch%d", dev->id);
priv->cdev.size = 256;
priv->cdev.ops = &micrel_switch_ops;
priv->cdev.priv = priv;
priv->cdev.dev = dev;
devfs_create(&priv->cdev);
dev_add_param(dev, "enable", micrel_switch_enable_set, NULL, 0);
dev_set_param(dev, "enable", "1");
return 0;
}
static struct driver_d micrel_switch_driver = {
.name = "ksz8864rmn",
.probe = micrel_switch_probe,
};
static int micrel_switch_init(void)
{
spi_register_driver(&micrel_switch_driver);
return 0;
}
device_initcall(micrel_switch_init);

View File

@ -982,6 +982,7 @@ static void cfi_init_mtd(struct flash_info *info)
static int cfi_probe (struct device_d *dev)
{
struct flash_info *info = xzalloc(sizeof(*info));
int cfinum;
dev->priv = (void *)info;
@ -1000,7 +1001,12 @@ static int cfi_probe (struct device_d *dev)
dev_info(dev, "found cfi flash at %p, size %ld\n",
info->base, info->size);
info->cdev.name = asprintf("nor%d", dev->id);
if (dev->id < 0)
cfinum = cdev_find_free_index("nor");
else
cfinum = dev->id;
info->cdev.name = asprintf("nor%d", cfinum);
info->cdev.size = info->size;
info->cdev.dev = dev;
info->cdev.ops = &cfi_ops;
@ -1011,19 +1017,30 @@ static int cfi_probe (struct device_d *dev)
#endif
devfs_create(&info->cdev);
if (dev->device_node)
of_parse_partitions(info->cdev.name, dev->device_node);
return 0;
}
static __maybe_unused struct of_device_id cfi_dt_ids[] = {
{
.compatible = "cfi-flash",
}, {
/* sentinel */
}
};
static struct driver_d cfi_driver = {
.name = "cfi_flash",
.probe = cfi_probe,
.info = cfi_info,
.name = "cfi_flash",
.probe = cfi_probe,
.info = cfi_info,
.of_compatible = DRV_OF_COMPAT(cfi_dt_ids),
};
static int cfi_init(void)
{
return register_driver(&cfi_driver);
return register_driver(&cfi_driver);
}
device_initcall(cfi_init);

View File

@ -838,7 +838,7 @@ static struct driver_d epcs_flash_driver = {
static int epcs_init(void)
{
register_driver(&epcs_flash_driver);
spi_register_driver(&epcs_flash_driver);
return 0;
}

2
drivers/of/Kconfig Normal file
View File

@ -0,0 +1,2 @@
config OFDEVICE
bool

3
drivers/of/Makefile Normal file
View File

@ -0,0 +1,3 @@
obj-y += base.o
obj-y += gpio.o
obj-y += partition.o

802
drivers/of/base.c Normal file
View File

@ -0,0 +1,802 @@
/*
* base.c - basic devicetree functions
*
* Copyright (c) 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
*
* based on Linux devicetree support
*
* See file CREDITS for list of people who contributed to this
* project.
*
* 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.
*/
#include <common.h>
#include <of.h>
#include <errno.h>
#include <libfdt.h>
#include <malloc.h>
#include <init.h>
#include <linux/ctype.h>
/**
* struct alias_prop - Alias property in 'aliases' node
* @link: List node to link the structure in aliases_lookup list
* @alias: Alias property name
* @np: Pointer to device_node that the alias stands for
* @id: Index value from end of alias name
* @stem: Alias string without the index
*
* The structure represents one alias property of 'aliases' node as
* an entry in aliases_lookup list.
*/
struct alias_prop {
struct list_head link;
const char *alias;
struct device_node *np;
int id;
char stem[0];
};
static LIST_HEAD(aliases_lookup);
static LIST_HEAD(phandle_list);
static LIST_HEAD(allnodes);
struct device_node *root_node;
struct device_node *of_aliases;
int of_n_addr_cells(struct device_node *np)
{
const __be32 *ip;
do {
if (np->parent)
np = np->parent;
ip = of_get_property(np, "#address-cells", NULL);
if (ip)
return be32_to_cpup(ip);
} while (np->parent);
/* No #address-cells property for the root node */
return OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
}
EXPORT_SYMBOL(of_n_addr_cells);
int of_n_size_cells(struct device_node *np)
{
const __be32 *ip;
do {
if (np->parent)
np = np->parent;
ip = of_get_property(np, "#size-cells", NULL);
if (ip)
return be32_to_cpup(ip);
} while (np->parent);
/* No #size-cells property for the root node */
return OF_ROOT_NODE_SIZE_CELLS_DEFAULT;
}
EXPORT_SYMBOL(of_n_size_cells);
static void of_bus_default_count_cells(struct device_node *dev,
int *addrc, int *sizec)
{
if (addrc)
*addrc = of_n_addr_cells(dev);
if (sizec)
*sizec = of_n_size_cells(dev);
}
void of_bus_count_cells(struct device_node *dev,
int *addrc, int *sizec)
{
of_bus_default_count_cells(dev, addrc, sizec);
}
struct property *of_find_property(const struct device_node *node, const char *name)
{
struct property *p;
list_for_each_entry(p, &node->properties, list)
if (!strcmp(p->name, name))
return p;
return NULL;
}
EXPORT_SYMBOL(of_find_property);
static void of_alias_add(struct alias_prop *ap, struct device_node *np,
int id, const char *stem, int stem_len)
{
ap->np = np;
ap->id = id;
strncpy(ap->stem, stem, stem_len);
ap->stem[stem_len] = 0;
list_add_tail(&ap->link, &aliases_lookup);
pr_debug("adding DT alias:%s: stem=%s id=%i node=%s\n",
ap->alias, ap->stem, ap->id, np->full_name);
}
/**
* of_alias_scan - Scan all properties of 'aliases' node
*
* The function scans all the properties of 'aliases' node and populates
* the global lookup table with the properties. It returns the
* number of alias_prop found, or error code in error case.
*/
void of_alias_scan(void)
{
struct property *pp;
of_aliases = of_find_node_by_path("/aliases");
if (!of_aliases)
return;
list_for_each_entry(pp, &of_aliases->properties, list) {
const char *start = pp->name;
const char *end = start + strlen(start);
struct device_node *np;
struct alias_prop *ap;
int id, len;
/* Skip those we do not want to proceed */
if (!strcmp(pp->name, "name") ||
!strcmp(pp->name, "phandle") ||
!strcmp(pp->name, "linux,phandle"))
continue;
np = of_find_node_by_path(pp->value);
if (!np)
continue;
/* walk the alias backwards to extract the id and work out
* the 'stem' string */
while (isdigit(*(end-1)) && end > start)
end--;
len = end - start;
id = simple_strtol(end, 0, 10);
if (id < 0)
continue;
/* Allocate an alias_prop with enough space for the stem */
ap = xzalloc(sizeof(*ap) + len + 1);
if (!ap)
continue;
ap->alias = start;
of_alias_add(ap, np, id, start, len);
}
}
/**
* of_alias_get_id - Get alias id for the given device_node
* @np: Pointer to the given device_node
* @stem: Alias stem of the given device_node
*
* The function travels the lookup table to get alias id for the given
* device_node and alias stem. It returns the alias id if find it.
*/
int of_alias_get_id(struct device_node *np, const char *stem)
{
struct alias_prop *app;
int id = -ENODEV;
list_for_each_entry(app, &aliases_lookup, link) {
if (strcmp(app->stem, stem) != 0)
continue;
if (np == app->np) {
id = app->id;
break;
}
}
return id;
}
EXPORT_SYMBOL_GPL(of_alias_get_id);
u64 of_translate_address(struct device_node *node, const __be32 *in_addr)
{
struct property *p;
u64 addr = be32_to_cpu(*in_addr);
while (1) {
int na, nc;
if (!node->parent)
return addr;
node = node->parent;
p = of_find_property(node, "ranges");
if (!p && node->parent)
return OF_BAD_ADDR;
of_bus_count_cells(node, &na, &nc);
if (na != 1 || nc != 1) {
printk("%s: #size-cells != 1 or #address-cells != 1 "
"currently not supported\n", node->name);
return OF_BAD_ADDR;
}
}
}
EXPORT_SYMBOL(of_translate_address);
/*
* of_find_node_by_phandle - Find a node given a phandle
* @handle: phandle of the node to find
*/
struct device_node *of_find_node_by_phandle(phandle phandle)
{
struct device_node *node;
list_for_each_entry(node, &phandle_list, phandles)
if (node->phandle == phandle)
return node;
return NULL;
}
EXPORT_SYMBOL(of_find_node_by_phandle);
/*
* Find a property with a given name for a given node
* and return the value.
*/
const void *of_get_property(const struct device_node *np, const char *name,
int *lenp)
{
struct property *pp = of_find_property(np, name);
if (!pp)
return NULL;
if (lenp)
*lenp = pp->length;
return pp ? pp->value : NULL;
}
EXPORT_SYMBOL(of_get_property);
/** Checks if the given "compat" string matches one of the strings in
* the device's "compatible" property
*/
int of_device_is_compatible(const struct device_node *device,
const char *compat)
{
const char *cp;
int cplen, l;
cp = of_get_property(device, "compatible", &cplen);
if (cp == NULL)
return 0;
while (cplen > 0) {
if (strcmp(cp, compat) == 0)
return 1;
l = strlen(cp) + 1;
cp += l;
cplen -= l;
}
return 0;
}
EXPORT_SYMBOL(of_device_is_compatible);
int of_match(struct device_d *dev, struct driver_d *drv)
{
struct of_device_id *id;
id = drv->of_compatible;
while (id->compatible) {
if (of_device_is_compatible(dev->device_node, id->compatible) == 1) {
dev->of_id_entry = id;
return 0;
}
id++;
}
return 1;
}
EXPORT_SYMBOL(of_match);
/**
* of_property_read_u32_array - Find and read an array of 32 bit integers
* from a property.
*
* @np: device node from which the property value is to be read.
* @propname: name of the property to be searched.
* @out_value: pointer to return value, modified only if return value is 0.
*
* Search for a property in a device node and read 32-bit value(s) from
* it. Returns 0 on success, -EINVAL if the property does not exist,
* -ENODATA if property does not have a value, and -EOVERFLOW if the
* property data isn't large enough.
*
* The out_value is modified only if a valid u32 value can be decoded.
*/
int of_property_read_u32_array(const struct device_node *np,
const char *propname, u32 *out_values,
size_t sz)
{
struct property *prop = of_find_property(np, propname);
const __be32 *val;
if (!prop)
return -EINVAL;
if (!prop->value)
return -ENODATA;
if ((sz * sizeof(*out_values)) > prop->length)
return -EOVERFLOW;
val = prop->value;
while (sz--)
*out_values++ = be32_to_cpup(val++);
return 0;
}
EXPORT_SYMBOL_GPL(of_property_read_u32_array);
/**
* of_parse_phandles_with_args - Find a node pointed by phandle in a list
* @np: pointer to a device tree node containing a list
* @list_name: property name that contains a list
* @cells_name: property name that specifies phandles' arguments count
* @index: index of a phandle to parse out
* @out_node: optional pointer to device_node struct pointer (will be filled)
* @out_args: optional pointer to arguments pointer (will be filled)
*
* This function is useful to parse lists of phandles and their arguments.
* Returns 0 on success and fills out_node and out_args, on error returns
* appropriate errno value.
*
* Example:
*
* phandle1: node1 {
* #list-cells = <2>;
* }
*
* phandle2: node2 {
* #list-cells = <1>;
* }
*
* node3 {
* list = <&phandle1 1 2 &phandle2 3>;
* }
*
* To get a device_node of the `node2' node you may call this:
* of_parse_phandles_with_args(node3, "list", "#list-cells", 2, &node2, &args);
*/
int of_parse_phandles_with_args(struct device_node *np, const char *list_name,
const char *cells_name, int index,
struct device_node **out_node,
const void **out_args)
{
int ret = -EINVAL;
const __be32 *list;
const __be32 *list_end;
int size;
int cur_index = 0;
struct device_node *node = NULL;
const void *args = NULL;
list = of_get_property(np, list_name, &size);
if (!list) {
ret = -ENOENT;
goto err0;
}
list_end = list + size / sizeof(*list);
while (list < list_end) {
const __be32 *cells;
phandle phandle;
phandle = be32_to_cpup(list++);
args = list;
/* one cell hole in the list = <>; */
if (!phandle)
goto next;
node = of_find_node_by_phandle(phandle);
if (!node) {
pr_debug("%s: could not find phandle %d\n",
np->full_name, phandle);
goto err0;
}
cells = of_get_property(node, cells_name, &size);
if (!cells || size != sizeof(*cells)) {
pr_debug("%s: could not get %s for %s\n",
np->full_name, cells_name, node->full_name);
goto err1;
}
list += be32_to_cpup(cells);
if (list > list_end) {
pr_debug("%s: insufficient arguments length\n",
np->full_name);
goto err1;
}
next:
if (cur_index == index)
break;
node = NULL;
args = NULL;
cur_index++;
}
if (!node) {
/*
* args w/o node indicates that the loop above has stopped at
* the 'hole' cell. Report this differently.
*/
if (args)
ret = -EEXIST;
else
ret = -ENOENT;
goto err0;
}
if (out_node)
*out_node = node;
if (out_args)
*out_args = args;
return 0;
err1:
err0:
pr_debug("%s failed with status %d\n", __func__, ret);
return ret;
}
EXPORT_SYMBOL(of_parse_phandles_with_args);
/**
* of_machine_is_compatible - Test root of device tree for a given compatible value
* @compat: compatible string to look for in root node's compatible property.
*
* Returns true if the root node has the given value in its
* compatible property.
*/
int of_machine_is_compatible(const char *compat)
{
if (!root_node)
return 0;
return of_device_is_compatible(root_node, compat);
}
EXPORT_SYMBOL(of_machine_is_compatible);
/**
* of_find_node_by_path - Find a node matching a full OF path
* @path: The full path to match
*
* Returns a node pointer with refcount incremented, use
* of_node_put() on it when done.
*/
struct device_node *of_find_node_by_path(const char *path)
{
struct device_node *np;
list_for_each_entry(np, &allnodes, list) {
if (np->full_name && (strcmp(np->full_name, path) == 0))
break;
}
return np;
}
EXPORT_SYMBOL(of_find_node_by_path);
struct device_node *of_get_root_node(void)
{
return root_node;
}
static int of_node_disabled(struct device_node *node)
{
struct property *p;
p = of_find_property(node, "status");
if (p) {
if (!strcmp("disabled", p->value))
return 1;
}
return 0;
}
void of_print_nodes(struct device_node *node, int indent)
{
struct device_node *n;
struct property *p;
int i;
if (!node)
return;
if (of_node_disabled(node))
return;
for (i = 0; i < indent; i++)
printf("\t");
printf("%s%s\n", node->name, node->name ? " {" : "{");
list_for_each_entry(p, &node->properties, list) {
for (i = 0; i < indent + 1; i++)
printf("\t");
printf("%s: ", p->name);
of_print_property(p->value, p->length);
printf("\n");
}
list_for_each_entry(n, &node->children, parent_list) {
of_print_nodes(n, indent + 1);
}
for (i = 0; i < indent; i++)
printf("\t");
printf("};\n");
}
static struct device_node *new_device_node(struct device_node *parent)
{
struct device_node *node;
node = xzalloc(sizeof(*node));
node->parent = parent;
if (parent)
list_add_tail(&node->parent_list, &parent->children);
INIT_LIST_HEAD(&node->children);
INIT_LIST_HEAD(&node->properties);
return node;
}
static struct property *new_property(struct device_node *node, const char *name,
const void *data, int len)
{
struct property *prop;
prop = xzalloc(sizeof(*prop));
prop->name = strdup(name);
prop->length = len;
prop->value = xzalloc(len);
memcpy(prop->value, data, len);
list_add_tail(&prop->list, &node->properties);
return prop;
}
static struct device_d *add_of_device(struct device_node *node)
{
struct device_d *dev;
char *name, *at;
const struct property *cp;
if (of_node_disabled(node))
return NULL;
cp = of_get_property(node, "compatible", NULL);
if (!cp)
return NULL;
dev = xzalloc(sizeof(*dev));
name = xstrdup(node->name);
at = strchr(name, '@');
if (at) {
*at = 0;
snprintf(dev->name, MAX_DRIVER_NAME, "%s.%s", at + 1, name);
} else {
strncpy(dev->name, node->name, MAX_DRIVER_NAME);
}
dev->id = DEVICE_ID_SINGLE;
dev->resource = node->resource;
dev->num_resources = 1;
dev->device_node = node;
node->device = dev;
debug("register device 0x%08x\n", node->resource[0].start);
register_device(dev);
free(name);
return dev;
}
EXPORT_SYMBOL(add_of_device);
static int add_of_device_resource(struct device_node *node)
{
struct property *reg;
u64 address, size;
struct resource *res;
struct device_d *dev;
phandle phandle;
int ret;
ret = of_property_read_u32(node, "phandle", &phandle);
if (!ret) {
node->phandle = phandle;
list_add_tail(&node->phandles, &phandle_list);
}
reg = of_find_property(node, "reg");
if (!reg)
return -ENODEV;
address = of_translate_address(node, reg->value);
if (address == OF_BAD_ADDR)
return -EINVAL;
size = be32_to_cpu(((u32 *)reg->value)[1]);
/*
* A device may already be registered as platform_device.
* Instead of registering the same device again, just
* add this node to the existing device.
*/
for_each_device(dev) {
if (!dev->resource)
continue;
if (dev->resource->start == address) {
debug("connecting %s to %s\n", node->name, dev_name(dev));
node->device = dev;
dev->device_node = node;
node->resource = dev->resource;
return 0;
}
}
res = xzalloc(sizeof(*res));
res->start = address;
res->end = address + size - 1;
res->flags = IORESOURCE_MEM;
node->resource = res;
add_of_device(node);
return 0;
}
void of_free(struct device_node *node)
{
struct device_node *n, *nt;
struct property *p, *pt;
if (!node)
return;
list_for_each_entry_safe(p, pt, &node->properties, list) {
list_del(&p->list);
free(p->name);
free(p->value);
free(p);
}
list_for_each_entry_safe(n, nt, &node->children, parent_list) {
of_free(n);
}
if (node->parent)
list_del(&node->parent_list);
if (node->device)
node->device->device_node = NULL;
else
free(node->resource);
free(node->name);
free(node->full_name);
free(node);
}
static void __of_probe(struct device_node *node)
{
struct device_node *n;
if (node->device)
return;
add_of_device_resource(node);
list_for_each_entry(n, &node->children, parent_list)
__of_probe(n);
}
int of_probe(void)
{
if(!root_node)
return -ENODEV;
__of_probe(root_node);
return 0;
}
/*
* Parse a flat device tree binary blob and store it in the barebox
* internal tree format,
*/
int of_parse_dtb(struct fdt_header *fdt)
{
const void *nodep; /* property node pointer */
int nodeoffset; /* node offset from libfdt */
int nextoffset; /* next node offset from libfdt */
uint32_t tag; /* tag */
int len; /* length of the property */
int level = 0; /* keep track of nesting level */
const struct fdt_property *fdt_prop;
const char *pathp;
int depth = 10000;
struct device_node *node = NULL;
char buf[1024];
int ret;
if (root_node)
return -EBUSY;
nodeoffset = fdt_path_offset(fdt, "/");
if (nodeoffset < 0) {
/*
* Not found or something else bad happened.
*/
printf ("libfdt fdt_path_offset() returned %s\n",
fdt_strerror(nodeoffset));
return -EINVAL;
}
while (1) {
tag = fdt_next_tag(fdt, nodeoffset, &nextoffset);
switch (tag) {
case FDT_BEGIN_NODE:
pathp = fdt_get_name(fdt, nodeoffset, NULL);
if (pathp == NULL)
pathp = "/* NULL pointer error */";
ret = fdt_get_path(fdt, nodeoffset, buf, 1024);
if (ret)
return -EINVAL;
node = new_device_node(node);
if (!node->parent)
root_node = node;
node->full_name = xstrdup(buf);
node->name = xstrdup(pathp);
list_add_tail(&node->list, &allnodes);
break;
case FDT_END_NODE:
node = node->parent;
break;
case FDT_PROP:
fdt_prop = fdt_offset_ptr(fdt, nodeoffset,
sizeof(*fdt_prop));
pathp = fdt_string(fdt,
fdt32_to_cpu(fdt_prop->nameoff));
len = fdt32_to_cpu(fdt_prop->len);
nodep = fdt_prop->data;
new_property(node, pathp, nodep, len);
break;
case FDT_NOP:
break;
case FDT_END:
of_alias_scan();
return 0;
default:
if (level <= depth)
printf("Unknown tag 0x%08X\n", tag);
return -EINVAL;
}
nodeoffset = nextoffset;
}
return 0;
}

28
drivers/of/gpio.c Normal file
View File

@ -0,0 +1,28 @@
#define DEBUG
#include <common.h>
#include <errno.h>
#include <of.h>
#include <gpio.h>
int of_get_named_gpio(struct device_node *np,
const char *propname, int index)
{
int ret;
struct device_node *gpio_np;
const void *gpio_spec;
ret = of_parse_phandles_with_args(np, propname, "#gpio-cells", index,
&gpio_np, &gpio_spec);
if (ret) {
pr_debug("%s: can't parse gpios property: %d\n", __func__, ret);
return -EINVAL;
}
ret = gpio_get_num(gpio_np->device, be32_to_cpup(gpio_spec));
if (ret < 0)
return ret;
return ret;
}

64
drivers/of/partition.c Normal file
View File

@ -0,0 +1,64 @@
/*
* partition.c - devicetree partition parsing
*
* Copyright (c) 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
*
* based on Linux devicetree support
*
* See file CREDITS for list of people who contributed to this
* project.
*
* 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.
*/
#include <common.h>
#include <of.h>
#include <malloc.h>
#include <linux/mtd/mtd.h>
int of_parse_partitions(const char *cdevname,
struct device_node *node)
{
struct device_node *n;
const char *partname;
char *filename;
device_node_for_nach_child(node, n) {
const __be32 *reg;
unsigned long offset, size;
const char *name;
int len;
unsigned long flags = 0;
reg = of_get_property(n, "reg", &len);
if (!reg)
continue;
offset = be32_to_cpu(reg[0]);
size = be32_to_cpu(reg[1]);
partname = of_get_property(n, "label", &len);
if (!partname)
partname = of_get_property(n, "name", &len);
name = (char *)partname;
debug("add partition: %s.%s 0x%08lx 0x%08lx\n", cdevname, partname, offset, size);
if (of_get_property(n, "read-only", &len))
flags = DEVFS_PARTITION_READONLY;
filename = asprintf("%s.%s", cdevname, partname);
devfs_add_partition(cdevname, offset, size, flags, filename);
free(filename);
}
return 0;
}

View File

@ -357,10 +357,23 @@ static void imx_serial_remove(struct device_d *dev)
free(priv);
}
static __maybe_unused struct of_device_id imx_serial_dt_ids[] = {
{
.compatible = "fsl,imx1-uart",
.data = 0,
}, {
.compatible = "fsl,imx21-uart",
.data = 1,
}, {
/* sentinel */
}
};
static struct driver_d imx_serial_driver = {
.name = "imx_serial",
.probe = imx_serial_probe,
.name = "imx_serial",
.probe = imx_serial_probe,
.remove = imx_serial_remove,
.of_compatible = DRV_OF_COMPAT(imx_serial_dt_ids),
};
static int imx_serial_init(void)

View File

@ -24,6 +24,7 @@
#include <spi/spi.h>
#include <xfuncs.h>
#include <io.h>
#include <errno.h>
#include <gpio.h>
#include <mach/spi.h>
#include <mach/generic.h>
@ -495,6 +496,32 @@ static struct spi_imx_devtype_data spi_imx_devtype_data[] = {
#endif
};
static int imx_spi_dt_probe(struct imx_spi *imx)
{
struct device_node *node = imx->master.dev->device_node;
int ret, i;
u32 num_cs;
if (!node)
return -ENODEV;
ret = of_property_read_u32(node, "fsl,spi-num-chipselects", &num_cs);
if (ret)
return ret;
imx->master.num_chipselect = num_cs;
imx->cs_array = xzalloc(sizeof(u32) * num_cs);
for (i = 0; i < num_cs; i++) {
int cs_gpio = of_get_named_gpio(node, "cs-gpios", i);
imx->cs_array[i] = cs_gpio;
}
spi_of_register_slaves(&imx->master, node);
return 0;
}
static int imx_spi_probe(struct device_d *dev)
{
struct spi_master *master;
@ -509,8 +536,13 @@ static int imx_spi_probe(struct device_d *dev)
master->setup = imx_spi_setup;
master->transfer = imx_spi_transfer;
master->num_chipselect = pdata->num_chipselect;
imx->cs_array = pdata->chipselect;
if (pdata) {
master->num_chipselect = pdata->num_chipselect;
imx->cs_array = pdata->chipselect;
} else {
if (IS_ENABLED(CONFIG_OFDEVICE))
imx_spi_dt_probe(imx);
}
#ifdef CONFIG_DRIVER_SPI_IMX_0_0
if (cpu_is_mx27())
@ -536,9 +568,22 @@ static int imx_spi_probe(struct device_d *dev)
return 0;
}
static __maybe_unused struct of_device_id imx_spi_dt_ids[] = {
{
.compatible = "fsl,imx27-cspi",
}, {
.compatible = "fsl,imx35-cspi",
}, {
.compatible = "fsl,imx51-ecspi",
}, {
/* sentinel */
}
};
static struct driver_d imx_spi_driver = {
.name = "imx_spi",
.probe = imx_spi_probe,
.of_compatible = DRV_OF_COMPAT(imx_spi_dt_ids),
};
static int imx_spi_init(void)

View File

@ -27,6 +27,8 @@
#include <xfuncs.h>
#include <malloc.h>
#include <errno.h>
#include <init.h>
#include <of.h>
/* SPI devices should normally not be created by SPI device drivers; that
* would make them board-specific. Similarly with SPI master drivers.
@ -77,10 +79,12 @@ struct spi_device *spi_new_device(struct spi_master *master,
proxy->mode = chip->mode;
proxy->bits_per_word = chip->bits_per_word ? chip->bits_per_word : 8;
proxy->dev.platform_data = chip->platform_data;
proxy->dev.bus = &spi_bus;
strcpy(proxy->dev.name, chip->name);
/* allocate a free id for this chip */
proxy->dev.id = DEVICE_ID_DYNAMIC;
proxy->dev.type_data = proxy;
proxy->dev.device_node = chip->device_node;
dev_add_child(master->dev, &proxy->dev);
/* drivers may modify this initial i/o setup */
@ -100,6 +104,27 @@ fail:
}
EXPORT_SYMBOL(spi_new_device);
#ifdef CONFIG_OFDEVICE
void spi_of_register_slaves(struct spi_master *master, struct device_node *node)
{
struct device_node *n;
struct spi_board_info chip;
struct property *reg;
device_node_for_nach_child(node, n) {
chip.name = n->name;
chip.bus_num = master->bus_num;
chip.max_speed_hz = 300000; /* FIXME */
reg = of_find_property(n, "reg");
if (!reg)
continue;
chip.chip_select = of_read_number(reg->value, 1);
chip.device_node = n;
spi_register_board_info(&chip, 1);
}
}
#endif
/**
* spi_register_board_info - register SPI devices for a given board
* @info: array of chip descriptors
@ -154,6 +179,8 @@ static void scan_boardinfo(struct spi_master *master)
}
}
static LIST_HEAD(spi_master_list);
/**
* spi_register_master - register SPI master controller
* @master: initialized master, originally from spi_alloc_master()
@ -186,6 +213,8 @@ int spi_register_master(struct spi_master *master)
if (master->num_chipselect == 0)
return -EINVAL;
list_add_tail(&master->list, &spi_master_list);
/* populate children from any spi device tables */
scan_boardinfo(master);
status = 0;
@ -240,3 +269,35 @@ int spi_write_then_read(struct spi_device *spi,
return status;
}
EXPORT_SYMBOL(spi_write_then_read);
static int spi_match(struct device_d *dev, struct driver_d *drv)
{
if (IS_ENABLED(CONFIG_OFDEVICE) && dev->device_node &&
drv->of_compatible)
return of_match(dev, drv);
return strcmp(dev->name, drv->name) ? -1 : 0;
}
static int spi_probe(struct device_d *dev)
{
return dev->driver->probe(dev);
}
static void spi_remove(struct device_d *dev)
{
dev->driver->remove(dev);
}
struct bus_type spi_bus = {
.name = "spi",
.match = spi_match,
.probe = spi_probe,
.remove = spi_remove,
};
static int spi_bus_init(void)
{
return bus_register(&spi_bus);
}
pure_initcall(spi_bus_init);

View File

@ -1422,3 +1422,8 @@ struct bus_type usb_bus_type = {
.remove = usb_remove,
};
static int usb_bus_init(void)
{
return bus_register(&usb_bus_type);
}
pure_initcall(usb_bus_init);

View File

@ -125,6 +125,7 @@ int register_framebuffer(struct fb_info *info)
sprintf(dev->name, "fb");
info->dev.bus = &fb_bus;
register_device(&info->dev);
dev_add_param(dev, "enable", fb_enable_set, NULL, 0);
dev_set_param(dev, "enable", "0");
@ -160,19 +161,41 @@ static void fb_info(struct device_d *dev)
printf("\n");
}
static int fb_probe(struct device_d *hw_dev)
static struct driver_d fb_driver = {
.name = "fb",
.info = fb_info,
};
static int fb_match(struct device_d *dev, struct driver_d *drv)
{
return 0;
}
static struct driver_d fb_driver = {
.name = "fb",
static int fb_probe(struct device_d *dev)
{
return 0;
}
static void fb_remove(struct device_d *dev)
{
}
struct bus_type fb_bus = {
.name = "fb",
.match = fb_match,
.probe = fb_probe,
.info = fb_info,
.remove = fb_remove,
};
static int fb_bus_init(void)
{
return bus_register(&fb_bus);
}
pure_initcall(fb_bus_init);
static int fb_init_driver(void)
{
fb_driver.bus = &fb_bus;
register_driver(&fb_driver);
return 0;
}

View File

@ -1141,6 +1141,12 @@ struct bus_type fs_bus = {
.remove = fs_remove,
};
static int fs_bus_init(void)
{
return bus_register(&fs_bus);
}
pure_initcall(fs_bus_init);
int register_fs_driver(struct fs_driver_d *fsdrv)
{
fsdrv->drv.bus = &fs_bus;

View File

@ -25,6 +25,7 @@
#include <linux/list.h>
#include <linux/ioport.h>
#include <of.h>
#define MAX_DRIVER_NAME 32
#define FORMAT_DRIVER_NAME_ID "%s%d"
@ -60,6 +61,11 @@
struct filep;
struct bus_type;
struct platform_device_id {
const char *name;
unsigned long driver_data;
};
/** @brief Describes a particular device present in the system */
struct device_d {
/*! This member (and 'type' described below) is used to match with a
@ -86,6 +92,7 @@ struct device_d {
struct driver_d *driver; /*! The driver for this device */
struct list_head list; /* The list of all devices */
struct list_head bus_list; /* our bus */
struct list_head children; /* our children */
struct list_head sibling;
struct list_head active; /* The list of all devices which have a driver */
@ -99,6 +106,11 @@ struct device_d {
struct list_head parameters;
struct list_head cdevs;
struct platform_device_id *id_entry;
struct device_node *device_node;
struct of_device_id *of_id_entry;
};
/** @brief Describes a driver present in the system */
@ -108,6 +120,7 @@ struct driver_d {
const char *name;
struct list_head list;
struct list_head bus_list; /* our bus */
/*! Called if an instance of a device is found */
int (*probe) (struct device_d *);
@ -119,6 +132,9 @@ struct driver_d {
void (*shortinfo) (struct device_d *);
struct bus_type *bus;
struct platform_device_id *id_table;
struct of_device_id *of_compatible;
};
/*@}*/ /* do not delete, doxygen relevant */
@ -333,9 +349,9 @@ static inline int dev_close_default(struct device_d *dev, struct filep *f)
/* debugging and troubleshooting/diagnostic helpers. */
#define dev_printf(dev, format, arg...) \
printf("%s@%s: " format , (dev)->name , \
dev_name(dev) , ## arg)
int dev_printf(const struct device_d *dev, const char *format, ...)
__attribute__ ((format(__printf__, 2, 3)));
#define dev_emerg(dev, format, arg...) \
dev_printf((dev) , format , ## arg)
@ -367,8 +383,26 @@ struct bus_type {
void (*remove)(struct device_d *dev);
struct list_head list;
struct list_head device_list;
struct list_head driver_list;
};
int bus_register(struct bus_type *bus);
extern struct list_head bus_list;
/* Iterate over all buses
*/
#define for_each_bus(bus) list_for_each_entry(bus, &bus_list, list)
/* Iterate over all devices of a bus
*/
#define bus_for_each_device(bus, dev) list_for_each_entry(dev, &bus->device_list, bus_list)
/* Iterate over all drivers of a bus
*/
#define bus_for_each_driver(bus, drv) list_for_each_entry(drv, &bus->driver_list, bus_list)
extern struct bus_type platform_bus;
struct file_operations {
@ -423,5 +457,10 @@ int devfs_add_partition(const char *devname, loff_t offset, loff_t size,
int flags, const char *name);
int devfs_del_partition(const char *name);
#define DRV_OF_COMPAT(compat) \
IS_ENABLED(CONFIG_OFDEVICE) ? (compat) : NULL
int dev_get_drvdata(struct device_d *dev, unsigned long *data);
#endif /* DRIVER_H */

View File

@ -110,5 +110,7 @@ int register_framebuffer(struct fb_info *info);
#define FBIO_ENABLE _IO('F', 2)
#define FBIO_DISABLE _IO('F', 3)
extern struct bus_type fb_bus;
#endif /* __FB_H */

View File

@ -139,4 +139,12 @@ extern int i2c_write_reg(struct i2c_client *client, u32 addr, const u8 *buf, u16
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
extern struct bus_type i2c_bus;
static inline int i2c_register_driver(struct driver_d *drv)
{
drv->bus = &i2c_bus;
return register_driver(drv);
}
#endif /* I2C_I2C_H */

View File

@ -2,6 +2,8 @@
#define __OF_H
#include <fdt.h>
#include <errno.h>
#include <asm/byteorder.h>
extern struct fdt_header *barebox_fdt;
@ -19,4 +21,115 @@ void do_fixup_by_path_u32(struct fdt_header *fdt, const char *path, const char *
u32 val, int create);
int fdt_get_path_or_create(struct fdt_header *fdt, const char *path);
#define OF_BAD_ADDR ((u64)-1)
typedef u32 phandle;
struct property {
char *name;
int length;
void *value;
struct list_head list;
};
struct device_node {
char *name;
char *full_name;
struct list_head properties;
struct device_node *parent;
struct list_head children;
struct list_head parent_list;
struct list_head list;
struct resource *resource;
struct device_d *device;
struct list_head phandles;
phandle phandle;
};
struct of_device_id {
char *compatible;
unsigned long data;
};
struct driver_d;
int of_match(struct device_d *dev, struct driver_d *drv);
struct property *of_find_property(const struct device_node *node, const char *name);
struct device_node *of_find_node_by_path(const char *path);
struct fdt_header *fdt_get_tree(void);
#define device_node_for_nach_child(node, child) \
list_for_each_entry(child, &node->children, parent_list)
/* Helper to read a big number; size is in cells (not bytes) */
static inline u64 of_read_number(const __be32 *cell, int size)
{
u64 r = 0;
while (size--)
r = (r << 32) | be32_to_cpu(*(cell++));
return r;
}
int of_property_read_u32_array(const struct device_node *np,
const char *propname, u32 *out_values,
size_t sz);
static inline int of_property_read_u32(const struct device_node *np,
const char *propname,
u32 *out_value)
{
return of_property_read_u32_array(np, propname, out_value, 1);
}
const void *of_get_property(const struct device_node *np, const char *name,
int *lenp);
int of_parse_phandles_with_args(struct device_node *np, const char *list_name,
const char *cells_name, int index,
struct device_node **out_node,
const void **out_args);
int of_get_named_gpio(struct device_node *np,
const char *propname, int index);
struct device_node *of_find_node_by_phandle(phandle phandle);
void of_print_property(const void *data, int len);
int of_machine_is_compatible(const char *compat);
#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
void of_print_nodes(struct device_node *node, int indent);
int of_probe(void);
int of_parse_dtb(struct fdt_header *fdt);
#ifdef CONFIG_OFDEVICE
int of_parse_partitions(const char *cdevname,
struct device_node *node);
struct device_node *of_get_root_node(void);
int of_alias_get_id(struct device_node *np, const char *stem);
#else
static inline int of_parse_partitions(const char *cdevname,
struct device_node *node)
{
return -EINVAL;
}
static inline struct device_node *of_get_root_node(void)
{
return NULL;
}
static inline int of_alias_get_id(struct device_node *np, const char *stem)
{
return -ENOENT;
}
#endif
#endif /* __OF_H */

View File

@ -17,6 +17,7 @@ struct spi_board_info {
u8 mode;
u8 bits_per_word;
void *platform_data;
struct device_node *device_node;
};
/**
@ -163,6 +164,8 @@ struct spi_master {
/* called on release() to free memory provided by spi_master */
void (*cleanup)(struct spi_device *spi);
struct list_head list;
};
/*---------------------------------------------------------------------------*/
@ -427,4 +430,14 @@ static inline ssize_t spi_w8r8(struct spi_device *spi, u8 cmd)
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
extern struct bus_type spi_bus;
static inline int spi_register_driver(struct driver_d *drv)
{
drv->bus = &spi_bus;
return register_driver(drv);
}
void spi_of_register_slaves(struct spi_master *master, struct device_node *node);
#endif /* __INCLUDE_SPI_H */