static int events_probe(struct platform_device *pdev)
{
    struct input_dev *input_dev;
    struct event_dev *edev = NULL;
    struct resource *res;
    unsigned keymapnamelen;
    int i;
    int count;
    int irq;
    void __iomem *addr;
    int ret;
    
    printk("*** events probe ***\n");

    input_dev = input_allocate_device();
    res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
    if(!input_dev || !res) goto fail;

    addr = ioremap(res->start, 4096);
    irq = platform_get_irq(pdev, 0);

    printk("events_probe() addr=0x%p irq=%d\n", addr, irq);

    if(!addr) goto fail;
    if(irq < 0) goto fail;

    __raw_writel(PAGE_NAME, addr + REG_SET_PAGE);
    keymapnamelen = __raw_readl(addr + REG_LEN);

    edev = kzalloc(sizeof(struct event_dev) + keymapnamelen + 1, GFP_KERNEL);
    if (!edev) goto fail;

    edev->input = input_dev;
    edev->addr = addr;
    edev->irq = irq;
    
    for (i = 0; i < keymapnamelen; i++) {
        edev->name[i] = __raw_readb(edev->addr + REG_DATA + i);
    }
    printk("events_probe() keymap=%s\n", edev->name);

    events_import_bits(edev, input_dev->evbit, EV_SYN, EV_MAX);
    events_import_bits(edev, input_dev->keybit, EV_KEY, KEY_MAX);
    events_import_bits(edev, input_dev->relbit, EV_REL, REL_MAX);
    events_import_bits(edev, input_dev->absbit, EV_ABS, ABS_MAX);
    events_import_bits(edev, input_dev->mscbit, EV_MSC, MSC_MAX);
    events_import_bits(edev, input_dev->ledbit, EV_LED, LED_MAX);
    events_import_bits(edev, input_dev->sndbit, EV_SND, SND_MAX);
    events_import_bits(edev, input_dev->ffbit, EV_FF, FF_MAX);
    events_import_bits(edev, input_dev->swbit, EV_SW, SW_MAX);

    __raw_writel(PAGE_ABSDATA, addr + REG_SET_PAGE);
    count = __raw_readl(addr + REG_LEN) / (4 * 4);
    if (count > ABS_MAX)
        count = ABS_MAX;
    for(i = 0; i < count; i++) {
        int val[4]; 
        int j;
        if (!test_bit(i, input_dev->absbit))
            continue;
        for(j = 0; j < ARRAY_SIZE(val); j++)
            val[j] = __raw_readl(edev->addr + REG_DATA + (i * ARRAY_SIZE(val) + j) * 4);
        input_set_abs_params(input_dev, i, val[0], val[1], val[2], val[3]);
    }
    
    platform_set_drvdata(pdev, edev);

    input_dev->name = edev->name;
    input_set_drvdata(input_dev, edev);
    
    ret = input_register_device(input_dev);
    if (ret)
        goto fail;

    if(request_irq(edev->irq, events_interrupt, 0,
                   "goldfish-events-keypad", edev) < 0) {
        input_unregister_device(input_dev);
        kfree(edev);
        return -EINVAL;
    }

    return 0;

fail:
    kfree(edev);
    input_free_device(input_dev);
    
    return -EINVAL;
}
Esempio n. 2
0
static int events_probe(struct platform_device *pdev)
{
	struct input_dev *input_dev;
	struct event_dev *edev;
	struct resource *res;
	unsigned keymapnamelen;
	void __iomem *addr;
	int irq;
	int i;
	int error;

	irq = platform_get_irq(pdev, 0);
	if (irq < 0)
		return -EINVAL;

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (!res)
		return -EINVAL;

	addr = devm_ioremap(&pdev->dev, res->start, 4096);
	if (!addr)
		return -ENOMEM;

	__raw_writel(PAGE_NAME, addr + REG_SET_PAGE);
	keymapnamelen = __raw_readl(addr + REG_LEN);

	edev = devm_kzalloc(&pdev->dev,
			    sizeof(struct event_dev) + keymapnamelen + 1,
			    GFP_KERNEL);
	if (!edev)
		return -ENOMEM;

	input_dev = devm_input_allocate_device(&pdev->dev);
	if (!input_dev)
		return -ENOMEM;

	edev->input = input_dev;
	edev->addr = addr;
	edev->irq = irq;

	for (i = 0; i < keymapnamelen; i++)
		edev->name[i] = __raw_readb(edev->addr + REG_DATA + i);

	pr_debug("events_probe() keymap=%s\n", edev->name);

	input_dev->name = edev->name;
	input_dev->id.bustype = BUS_HOST;

	events_import_bits(edev, input_dev->evbit, EV_SYN, EV_MAX);
	events_import_bits(edev, input_dev->keybit, EV_KEY, KEY_MAX);
	events_import_bits(edev, input_dev->relbit, EV_REL, REL_MAX);
	events_import_bits(edev, input_dev->absbit, EV_ABS, ABS_MAX);
	events_import_bits(edev, input_dev->mscbit, EV_MSC, MSC_MAX);
	events_import_bits(edev, input_dev->ledbit, EV_LED, LED_MAX);
	events_import_bits(edev, input_dev->sndbit, EV_SND, SND_MAX);
	events_import_bits(edev, input_dev->ffbit, EV_FF, FF_MAX);
	events_import_bits(edev, input_dev->swbit, EV_SW, SW_MAX);

	events_import_abs_params(edev);

	error = devm_request_irq(&pdev->dev, edev->irq, events_interrupt, 0,
				 "goldfish-events-keypad", edev);
	if (error)
		return error;

	error = input_register_device(input_dev);
	if (error)
		return error;

	return 0;
}