cregit-Linux how code gets into the kernel

Release 4.11 arch/arm/common/scoop.c

Directory: arch/arm/common
/*
 * Support code for the SCOOP interface found on various Sharp PDAs
 *
 * Copyright (c) 2004 Richard Purdie
 *
 *      Based on code written by Sharp/Lineo for 2.4 kernels
 *
 * 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.
 *
 */

#include <linux/device.h>
#include <linux/gpio.h>
#include <linux/string.h>
#include <linux/slab.h>
#include <linux/platform_device.h>
#include <linux/export.h>
#include <linux/io.h>
#include <asm/hardware/scoop.h>

/* PCMCIA to Scoop linkage

   There is no easy way to link multiple scoop devices into one
   single entity for the pxa2xx_pcmcia device so this structure
   is used which is setup by the platform code.

   This file is never modular so this symbol is always
   accessile to the board support files.
*/

struct scoop_pcmcia_config *platform_scoop_config;

EXPORT_SYMBOL(platform_scoop_config);


struct  scoop_dev {
	
void __iomem *base;
	
struct gpio_chip gpio;
	
spinlock_t scoop_lock;
	
unsigned short suspend_clr;
	
unsigned short suspend_set;
	
u32 scoop_gpwr;
};


void reset_scoop(struct device *dev) { struct scoop_dev *sdev = dev_get_drvdata(dev); iowrite16(0x0100, sdev->base + SCOOP_MCR); /* 00 */ iowrite16(0x0000, sdev->base + SCOOP_CDR); /* 04 */ iowrite16(0x0000, sdev->base + SCOOP_CCR); /* 10 */ iowrite16(0x0000, sdev->base + SCOOP_IMR); /* 18 */ iowrite16(0x00FF, sdev->base + SCOOP_IRM); /* 14 */ iowrite16(0x0000, sdev->base + SCOOP_ISR); /* 1C */ iowrite16(0x0000, sdev->base + SCOOP_IRM); }

Contributors

PersonTokensPropCommitsCommitProp
Richard Purdie6966.99%250.00%
Dmitry Baryshkov2827.18%125.00%
H Hartley Sweeten65.83%125.00%
Total103100.00%4100.00%


static void __scoop_gpio_set(struct scoop_dev *sdev, unsigned offset, int value) { unsigned short gpwr; gpwr = ioread16(sdev->base + SCOOP_GPWR); if (value) gpwr |= 1 << (offset + 1); else gpwr &= ~(1 << (offset + 1)); iowrite16(gpwr, sdev->base + SCOOP_GPWR); }

Contributors

PersonTokensPropCommitsCommitProp
Dmitry Baryshkov71100.00%1100.00%
Total71100.00%1100.00%


static void scoop_gpio_set(struct gpio_chip *chip, unsigned offset, int value) { struct scoop_dev *sdev = gpiochip_get_data(chip); unsigned long flags; spin_lock_irqsave(&sdev->scoop_lock, flags); __scoop_gpio_set(sdev, offset, value); spin_unlock_irqrestore(&sdev->scoop_lock, flags); }

Contributors

PersonTokensPropCommitsCommitProp
Dmitry Baryshkov5998.33%150.00%
Linus Walleij11.67%150.00%
Total60100.00%2100.00%


static int scoop_gpio_get(struct gpio_chip *chip, unsigned offset) { struct scoop_dev *sdev = gpiochip_get_data(chip); /* XXX: I'm unsure, but it seems so */ return !!(ioread16(sdev->base + SCOOP_GPRR) & (1 << (offset + 1))); }

Contributors

PersonTokensPropCommitsCommitProp
Dmitry Baryshkov4387.76%125.00%
Linus Walleij510.20%250.00%
André Goddard Rosa12.04%125.00%
Total49100.00%4100.00%


static int scoop_gpio_direction_input(struct gpio_chip *chip, unsigned offset) { struct scoop_dev *sdev = gpiochip_get_data(chip); unsigned long flags; unsigned short gpcr; spin_lock_irqsave(&sdev->scoop_lock, flags); gpcr = ioread16(sdev->base + SCOOP_GPCR); gpcr &= ~(1 << (offset + 1)); iowrite16(gpcr, sdev->base + SCOOP_GPCR); spin_unlock_irqrestore(&sdev->scoop_lock, flags); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Dmitry Baryshkov8998.89%150.00%
Linus Walleij11.11%150.00%
Total90100.00%2100.00%


static int scoop_gpio_direction_output(struct gpio_chip *chip, unsigned offset, int value) { struct scoop_dev *sdev = gpiochip_get_data(chip); unsigned long flags; unsigned short gpcr; spin_lock_irqsave(&sdev->scoop_lock, flags); __scoop_gpio_set(sdev, offset, value); gpcr = ioread16(sdev->base + SCOOP_GPCR); gpcr |= 1 << (offset + 1); iowrite16(gpcr, sdev->base + SCOOP_GPCR); spin_unlock_irqrestore(&sdev->scoop_lock, flags); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Dmitry Baryshkov9898.99%150.00%
Linus Walleij11.01%150.00%
Total99100.00%2100.00%


unsigned short read_scoop_reg(struct device *dev, unsigned short reg) { struct scoop_dev *sdev = dev_get_drvdata(dev); return ioread16(sdev->base + reg); }

Contributors

PersonTokensPropCommitsCommitProp
Richard Purdie3394.29%266.67%
Dmitry Baryshkov25.71%133.33%
Total35100.00%3100.00%


void write_scoop_reg(struct device *dev, unsigned short reg, unsigned short data) { struct scoop_dev *sdev = dev_get_drvdata(dev); iowrite16(data, sdev->base + reg); }

Contributors

PersonTokensPropCommitsCommitProp
Richard Purdie3589.74%266.67%
Dmitry Baryshkov410.26%133.33%
Total39100.00%3100.00%

EXPORT_SYMBOL(reset_scoop); EXPORT_SYMBOL(read_scoop_reg); EXPORT_SYMBOL(write_scoop_reg); #ifdef CONFIG_PM
static void check_scoop_reg(struct scoop_dev *sdev) { unsigned short mcr; mcr = ioread16(sdev->base + SCOOP_MCR); if ((mcr & 0x100) == 0) iowrite16(0x0101, sdev->base + SCOOP_MCR); }

Contributors

PersonTokensPropCommitsCommitProp
Richard Purdie4187.23%150.00%
Dmitry Baryshkov612.77%150.00%
Total47100.00%2100.00%


static int scoop_suspend(struct platform_device *dev, pm_message_t state) { struct scoop_dev *sdev = platform_get_drvdata(dev); check_scoop_reg(sdev); sdev->scoop_gpwr = ioread16(sdev->base + SCOOP_GPWR); iowrite16((sdev->scoop_gpwr & ~sdev->suspend_clr) | sdev->suspend_set, sdev->base + SCOOP_GPWR); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Richard Purdie5782.61%466.67%
Dmitry Baryshkov1014.49%116.67%
Russell King22.90%116.67%
Total69100.00%6100.00%


static int scoop_resume(struct platform_device *dev) { struct scoop_dev *sdev = platform_get_drvdata(dev); check_scoop_reg(sdev); iowrite16(sdev->scoop_gpwr, sdev->base + SCOOP_GPWR); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Richard Purdie3480.95%360.00%
Dmitry Baryshkov614.29%120.00%
Russell King24.76%120.00%
Total42100.00%5100.00%

#else #define scoop_suspend NULL #define scoop_resume NULL #endif
static int scoop_probe(struct platform_device *pdev) { struct scoop_dev *devptr; struct scoop_config *inf; struct resource *mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); int ret; if (!mem) return -EINVAL; devptr = kzalloc(sizeof(struct scoop_dev), GFP_KERNEL); if (!devptr) return -ENOMEM; spin_lock_init(&devptr->scoop_lock); inf = pdev->dev.platform_data; devptr->base = ioremap(mem->start, resource_size(mem)); if (!devptr->base) { ret = -ENOMEM; goto err_ioremap; } platform_set_drvdata(pdev, devptr); printk("Sharp Scoop Device found at 0x%08x -> 0x%8p\n",(unsigned int)mem->start, devptr->base); iowrite16(0x0140, devptr->base + SCOOP_MCR); reset_scoop(&pdev->dev); iowrite16(0x0000, devptr->base + SCOOP_CPR); iowrite16(inf->io_dir & 0xffff, devptr->base + SCOOP_GPCR); iowrite16(inf->io_out & 0xffff, devptr->base + SCOOP_GPWR); devptr->suspend_clr = inf->suspend_clr; devptr->suspend_set = inf->suspend_set; devptr->gpio.base = -1; if (inf->gpio_base != 0) { devptr->gpio.label = dev_name(&pdev->dev); devptr->gpio.base = inf->gpio_base; devptr->gpio.ngpio = 12; /* PA11 = 0, PA12 = 1, etc. up to PA22 = 11 */ devptr->gpio.set = scoop_gpio_set; devptr->gpio.get = scoop_gpio_get; devptr->gpio.direction_input = scoop_gpio_direction_input; devptr->gpio.direction_output = scoop_gpio_direction_output; ret = gpiochip_add_data(&devptr->gpio, devptr); if (ret) goto err_gpio; } return 0; err_gpio: platform_set_drvdata(pdev, NULL); err_ioremap: iounmap(devptr->base); kfree(devptr); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Richard Purdie17449.71%430.77%
Dmitry Baryshkov15544.29%323.08%
Russell King82.29%215.38%
Kay Sievers41.14%17.69%
Joe Perches30.86%17.69%
Pavel Machek30.86%17.69%
Linus Walleij30.86%17.69%
Total350100.00%13100.00%


static int scoop_remove(struct platform_device *pdev) { struct scoop_dev *sdev = platform_get_drvdata(pdev); if (!sdev) return -EINVAL; if (sdev->gpio.base != -1) gpiochip_remove(&sdev->gpio); platform_set_drvdata(pdev, NULL); iounmap(sdev->base); kfree(sdev); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Richard Purdie3447.89%133.33%
Dmitry Baryshkov3143.66%133.33%
Russell King68.45%133.33%
Total71100.00%3100.00%

static struct platform_driver scoop_driver = { .probe = scoop_probe, .remove = scoop_remove, .suspend = scoop_suspend, .resume = scoop_resume, .driver = { .name = "sharp-scoop", }, };
static int __init scoop_init(void) { return platform_driver_register(&scoop_driver); }

Contributors

PersonTokensPropCommitsCommitProp
Richard Purdie1487.50%133.33%
Russell King16.25%133.33%
Dmitry Baryshkov16.25%133.33%
Total16100.00%3100.00%

subsys_initcall(scoop_init);

Overall Contributors

PersonTokensPropCommitsCommitProp
Dmitry Baryshkov61047.77%313.04%
Richard Purdie59246.36%626.09%
Russell King352.74%313.04%
Linus Walleij110.86%28.70%
H Hartley Sweeten60.47%14.35%
Tim Schmielau60.47%28.70%
Kay Sievers40.31%14.35%
Joe Perches30.23%14.35%
Stefan Schmidt30.23%14.35%
Paul Gortmaker30.23%14.35%
Pavel Machek30.23%14.35%
André Goddard Rosa10.08%14.35%
Total1277100.00%23100.00%
Directory: arch/arm/common
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.