Message ID | 1432554113-26280-1-git-send-email-dbaryshkov@gmail.com |
---|---|
State | New |
Headers | show |
On Mon, May 25, 2015 at 02:41:38PM +0300, Dmitry Eremin-Solenikov wrote: > As LoCoMo is switching to new device model, adapt keyboard driver to > support new locomo core driver. > > Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> > --- > drivers/input/keyboard/Kconfig | 2 +- > drivers/input/keyboard/locomokbd.c | 252 ++++++++++++++++++------------------- > 2 files changed, 121 insertions(+), 133 deletions(-) > > diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig > index 106fbac..9a20487 100644 > --- a/drivers/input/keyboard/Kconfig > +++ b/drivers/input/keyboard/Kconfig > @@ -337,7 +337,7 @@ config KEYBOARD_LM8333 > > config KEYBOARD_LOCOMO > tristate "LoCoMo Keyboard Support" > - depends on SHARP_LOCOMO > + depends on MFD_LOCOMO > help > Say Y here if you are running Linux on a Sharp Zaurus Collie or Poodle based PDA > > diff --git a/drivers/input/keyboard/locomokbd.c b/drivers/input/keyboard/locomokbd.c > index c94d610..9742c79 100644 > --- a/drivers/input/keyboard/locomokbd.c > +++ b/drivers/input/keyboard/locomokbd.c > @@ -23,28 +23,25 @@ > * > */ > > -#include <linux/slab.h> > -#include <linux/module.h> > +#include <linux/delay.h> > #include <linux/init.h> > #include <linux/input.h> > -#include <linux/delay.h> > -#include <linux/device.h> > #include <linux/interrupt.h> > -#include <linux/ioport.h> > - > -#include <asm/hardware/locomo.h> > -#include <asm/irq.h> > - > -MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>"); > -MODULE_DESCRIPTION("LoCoMo keyboard driver"); > -MODULE_LICENSE("GPL"); > - > -#define LOCOMOKBD_NUMKEYS 128 > +#include <linux/module.h> > +#include <linux/platform_device.h> > +#include <linux/regmap.h> > +#include <linux/slab.h> > +#include <linux/mfd/locomo.h> > > #define KEY_ACTIVITY KEY_F16 > #define KEY_CONTACT KEY_F18 > #define KEY_CENTER KEY_F15 > > +#define KB_ROWS 16 > +#define KB_COLS 8 > +#define LOCOMOKBD_NUMKEYS (KB_ROWS * KB_COLS) > +#define SCANCODE(c, r) (((c)<<4) + (r) + 1) > + > static const unsigned char > locomokbd_keycode[LOCOMOKBD_NUMKEYS] = { > 0, KEY_ESC, KEY_ACTIVITY, 0, 0, 0, 0, 0, 0, 0, /* 0 - 9 */ > @@ -62,20 +59,14 @@ locomokbd_keycode[LOCOMOKBD_NUMKEYS] = { > KEY_M, KEY_SPACE, KEY_V, KEY_APOSTROPHE, KEY_SLASH, 0, 0, 0 /* 120 - 128 */ > }; > > -#define KB_ROWS 16 > -#define KB_COLS 8 > -#define KB_ROWMASK(r) (1 << (r)) > -#define SCANCODE(c,r) ( ((c)<<4) + (r) + 1 ) > - > #define KB_DELAY 8 > -#define SCAN_INTERVAL (HZ/10) > > struct locomokbd { > unsigned char keycode[LOCOMOKBD_NUMKEYS]; > struct input_dev *input; > - char phys[32]; > > - unsigned long base; > + struct regmap *regmap; > + int irq; > spinlock_t lock; > > struct timer_list timer; > @@ -84,37 +75,33 @@ struct locomokbd { > }; > > /* helper functions for reading the keyboard matrix */ > -static inline void locomokbd_charge_all(unsigned long membase) > +static void locomokbd_charge_all(struct locomokbd *locomokbd) > { > - locomo_writel(0x00FF, membase + LOCOMO_KSC); > + regmap_write(locomokbd->regmap, LOCOMO_KSC, 0x00ff); > } > > -static inline void locomokbd_activate_all(unsigned long membase) > +static void locomokbd_activate_all(struct locomokbd *locomokbd) > { > - unsigned long r; > - > - locomo_writel(0, membase + LOCOMO_KSC); > - r = locomo_readl(membase + LOCOMO_KIC); > - r &= 0xFEFF; > - locomo_writel(r, membase + LOCOMO_KIC); > + regmap_write(locomokbd->regmap, LOCOMO_KSC, 0); > + regmap_update_bits(locomokbd->regmap, LOCOMO_KIC, 0x100, 0); > } > > -static inline void locomokbd_activate_col(unsigned long membase, int col) > +static void locomokbd_activate_col(struct locomokbd *locomokbd, int col) > { > unsigned short nset; > unsigned short nbset; > > - nset = 0xFF & ~(1 << col); > + nset = 0xFF & ~BIT(col); > nbset = (nset << 8) + nset; > - locomo_writel(nbset, membase + LOCOMO_KSC); > + regmap_write(locomokbd->regmap, LOCOMO_KSC, nbset); > } > > -static inline void locomokbd_reset_col(unsigned long membase, int col) > +static void locomokbd_reset_col(struct locomokbd *locomokbd, int col) > { > unsigned short nbset; > > - nbset = ((0xFF & ~(1 << col)) << 8) + 0xFF; > - locomo_writel(nbset, membase + LOCOMO_KSC); > + nbset = ((0xFF & ~BIT(col)) << 8) + 0xFF; > + regmap_write(locomokbd->regmap, LOCOMO_KSC, nbset); > } > > /* > @@ -129,24 +116,25 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd) > unsigned int row, col, rowd; > unsigned long flags; > unsigned int num_pressed; > - unsigned long membase = locomokbd->base; > + bool esc_pressed = false; > > spin_lock_irqsave(&locomokbd->lock, flags); > > - locomokbd_charge_all(membase); > + locomokbd_charge_all(locomokbd); > > num_pressed = 0; > for (col = 0; col < KB_COLS; col++) { > - > - locomokbd_activate_col(membase, col); > + udelay(KB_DELAY); > + locomokbd_activate_col(locomokbd, col); > udelay(KB_DELAY); > > - rowd = ~locomo_readl(membase + LOCOMO_KIB); > + regmap_read(locomokbd->regmap, LOCOMO_KIB, &rowd); > + rowd = ~rowd; > for (row = 0; row < KB_ROWS; row++) { > unsigned int scancode, pressed, key; > > scancode = SCANCODE(col, row); > - pressed = rowd & KB_ROWMASK(row); > + pressed = rowd & BIT(row); > key = locomokbd->keycode[scancode]; > > input_report_key(locomokbd->input, key, pressed); > @@ -158,30 +146,32 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd) > /* The "Cancel/ESC" key is labeled "On/Off" on > * Collie and Poodle and should suspend the device > * if it was pressed for more than a second. */ > - if (unlikely(key == KEY_ESC)) { > - if (!time_after(jiffies, > - locomokbd->suspend_jiffies + HZ)) > - continue; > - if (locomokbd->count_cancel++ > - != (HZ/SCAN_INTERVAL + 1)) > - continue; > - input_event(locomokbd->input, EV_PWR, > - KEY_SUSPEND, 1); > - locomokbd->suspend_jiffies = jiffies; > - } else > - locomokbd->count_cancel = 0; > + if (unlikely(key == KEY_ESC)) > + esc_pressed = true; > } > - locomokbd_reset_col(membase, col); > + locomokbd_reset_col(locomokbd, col); > } > - locomokbd_activate_all(membase); > + locomokbd_activate_all(locomokbd); > > input_sync(locomokbd->input); > > /* if any keys are pressed, enable the timer */ > if (num_pressed) > - mod_timer(&locomokbd->timer, jiffies + SCAN_INTERVAL); > + mod_timer(&locomokbd->timer, jiffies + msecs_to_jiffies(100)); > else > + regmap_update_bits(locomokbd->regmap, LOCOMO_KIC, 0x10, 0x10); > + > + > + if (esc_pressed && time_after(jiffies, > + locomokbd->suspend_jiffies + msecs_to_jiffies(1000))) { > + if (locomokbd->count_cancel++ > 20) { > + input_event(locomokbd->input, EV_PWR, > + KEY_SUSPEND, 1); > + locomokbd->suspend_jiffies = jiffies; > + } > + } else { > locomokbd->count_cancel = 0; > + } > > spin_unlock_irqrestore(&locomokbd->lock, flags); > } > @@ -192,18 +182,17 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd) > static irqreturn_t locomokbd_interrupt(int irq, void *dev_id) > { > struct locomokbd *locomokbd = dev_id; > - u16 r; > + unsigned int r; > > - r = locomo_readl(locomokbd->base + LOCOMO_KIC); > + regmap_read(locomokbd->regmap, LOCOMO_KIC, &r); > if ((r & 0x0001) == 0) > return IRQ_HANDLED; > > - locomo_writel(r & ~0x0100, locomokbd->base + LOCOMO_KIC); /* Ack */ > + /* Mask and Ack */ > + regmap_write(locomokbd->regmap, LOCOMO_KIC, r & ~0x110); > > - /** wait chattering delay **/ > - udelay(100); > + mod_timer(&locomokbd->timer, jiffies + msecs_to_jiffies(1)); > > - locomokbd_scankeyboard(locomokbd); > return IRQ_HANDLED; > } > > @@ -220,47 +209,39 @@ static void locomokbd_timer_callback(unsigned long data) > static int locomokbd_open(struct input_dev *dev) > { > struct locomokbd *locomokbd = input_get_drvdata(dev); > - u16 r; > - > - r = locomo_readl(locomokbd->base + LOCOMO_KIC) | 0x0010; > - locomo_writel(r, locomokbd->base + LOCOMO_KIC); > - return 0; > + > + return regmap_update_bits(locomokbd->regmap, LOCOMO_KIC, 0x10, 0x10); > } > > static void locomokbd_close(struct input_dev *dev) > { > struct locomokbd *locomokbd = input_get_drvdata(dev); > - u16 r; > - > - r = locomo_readl(locomokbd->base + LOCOMO_KIC) & ~0x0010; > - locomo_writel(r, locomokbd->base + LOCOMO_KIC); > + > + regmap_update_bits(locomokbd->regmap, LOCOMO_KIC, 0x10, 0x0); > + > + del_timer_sync(&locomokbd->timer); > } > > -static int locomokbd_probe(struct locomo_dev *dev) > +static int locomokbd_probe(struct platform_device *dev) > { > struct locomokbd *locomokbd; > struct input_dev *input_dev; > int i, err; > > - locomokbd = kzalloc(sizeof(struct locomokbd), GFP_KERNEL); > - input_dev = input_allocate_device(); > - if (!locomokbd || !input_dev) { > - err = -ENOMEM; > - goto err_free_mem; > - } > + locomokbd = devm_kzalloc(&dev->dev, sizeof(struct locomokbd), > + GFP_KERNEL); > + if (!locomokbd) > + return -ENOMEM; > > - /* try and claim memory region */ > - if (!request_mem_region((unsigned long) dev->mapbase, > - dev->length, > - LOCOMO_DRIVER_NAME(dev))) { > - err = -EBUSY; > - printk(KERN_ERR "locomokbd: Can't acquire access to io memory for keyboard\n"); > - goto err_free_mem; > - } > + locomokbd->regmap = dev_get_regmap(dev->dev.parent, NULL); > + if (!locomokbd->regmap) > + return -EINVAL; > > - locomo_set_drvdata(dev, locomokbd); > + locomokbd->irq = platform_get_irq(dev, 0); > + if (locomokbd->irq < 0) > + return -ENXIO; > > - locomokbd->base = (unsigned long) dev->mapbase; > + platform_set_drvdata(dev, locomokbd); > > spin_lock_init(&locomokbd->lock); > > @@ -270,11 +251,13 @@ static int locomokbd_probe(struct locomo_dev *dev) > > locomokbd->suspend_jiffies = jiffies; > > - locomokbd->input = input_dev; > - strcpy(locomokbd->phys, "locomokbd/input0"); > + input_dev = devm_input_allocate_device(&dev->dev); > + if (!input_dev) > + return -ENOMEM; > > + locomokbd->input = input_dev; > input_dev->name = "LoCoMo keyboard"; > - input_dev->phys = locomokbd->phys; > + input_dev->phys = "locomokbd/input0"; > input_dev->id.bustype = BUS_HOST; > input_dev->id.vendor = 0x0001; > input_dev->id.product = 0x0001; > @@ -291,72 +274,77 @@ static int locomokbd_probe(struct locomo_dev *dev) > > input_set_drvdata(input_dev, locomokbd); > > - memcpy(locomokbd->keycode, locomokbd_keycode, sizeof(locomokbd->keycode)); > + memcpy(locomokbd->keycode, > + locomokbd_keycode, > + sizeof(locomokbd->keycode)); > + > for (i = 0; i < LOCOMOKBD_NUMKEYS; i++) > - set_bit(locomokbd->keycode[i], input_dev->keybit); > - clear_bit(0, input_dev->keybit); > + input_set_capability(input_dev, EV_KEY, locomokbd->keycode[i]); > + input_set_capability(input_dev, EV_PWR, KEY_SUSPEND); > + __set_bit(EV_REP, input_dev->evbit); > + > + regmap_write(locomokbd->regmap, LOCOMO_KCMD, 1); > + regmap_write(locomokbd->regmap, LOCOMO_KSC, 0x0); > + regmap_write(locomokbd->regmap, LOCOMO_KIC, 0x0); > > /* attempt to get the interrupt */ > - err = request_irq(dev->irq[0], locomokbd_interrupt, 0, "locomokbd", locomokbd); > + err = devm_request_irq(&dev->dev, locomokbd->irq, locomokbd_interrupt, > + 0, "locomokbd", locomokbd); > if (err) { > - printk(KERN_ERR "locomokbd: Can't get irq for keyboard\n"); > - goto err_release_region; > + dev_err(&dev->dev, "Could not get keyboard IRQ\n"); > + return err; > } > > err = input_register_device(locomokbd->input); > if (err) > - goto err_free_irq; > + return err; > > return 0; > > - err_free_irq: > - free_irq(dev->irq[0], locomokbd); > - err_release_region: > - release_mem_region((unsigned long) dev->mapbase, dev->length); > - locomo_set_drvdata(dev, NULL); > - err_free_mem: > - input_free_device(input_dev); > - kfree(locomokbd); > - > return err; > } > > -static int locomokbd_remove(struct locomo_dev *dev) > +static int __maybe_unused locomokbd_suspend(struct device *dev) > { > - struct locomokbd *locomokbd = locomo_get_drvdata(dev); > + struct locomokbd *locomokbd = dev_get_drvdata(dev); > > - free_irq(dev->irq[0], locomokbd); > + regmap_update_bits(locomokbd->regmap, LOCOMO_KIC, 0x10, 0x0); > > del_timer_sync(&locomokbd->timer); > > - input_unregister_device(locomokbd->input); > - locomo_set_drvdata(dev, NULL); > + return 0; > +} > + > +static int __maybe_unused locomokbd_resume(struct device *dev) > +{ > + struct locomokbd *locomokbd = dev_get_drvdata(dev); > > - release_mem_region((unsigned long) dev->mapbase, dev->length); > + regmap_write(locomokbd->regmap, LOCOMO_KCMD, 1); > + regmap_write(locomokbd->regmap, LOCOMO_KSC, 0); > + regmap_write(locomokbd->regmap, LOCOMO_KIC, 0x0); > > - kfree(locomokbd); > + /* Rescan keyboard only if we are open by somebody */ > + mutex_lock(&locomokbd->input->mutex); > + if (locomokbd->input->users) > + locomokbd_scankeyboard(locomokbd); > + mutex_unlock(&locomokbd->input->mutex); > > return 0; > } > > -static struct locomo_driver keyboard_driver = { > - .drv = { > - .name = "locomokbd" > +static SIMPLE_DEV_PM_OPS(locomo_kbd_pm, locomokbd_suspend, locomokbd_resume); > + > +static struct platform_driver locomokbd_driver = { > + .driver = { > + .name = "locomo-kbd", > + .pm = &locomo_kbd_pm, > }, > - .devid = LOCOMO_DEVID_KEYBOARD, > .probe = locomokbd_probe, > - .remove = locomokbd_remove, > }; > > -static int __init locomokbd_init(void) > -{ > - return locomo_driver_register(&keyboard_driver); > -} > +module_platform_driver(locomokbd_driver); > > -static void __exit locomokbd_exit(void) > -{ > - locomo_driver_unregister(&keyboard_driver); > -} > - > -module_init(locomokbd_init); > -module_exit(locomokbd_exit); > +MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>"); > +MODULE_DESCRIPTION("LoCoMo keyboard driver"); > +MODULE_LICENSE("GPL"); > +MODULE_ALIAS("platform:locomo-kbd"); > -- > 2.1.4 >
On Mon, May 25, 2015 at 02:41:39PM +0300, Dmitry Eremin-Solenikov wrote: > There are two Enter keys on collie/poodle keyboards. Make one of them to > generate KEY_KPENTER rather than just KEY_ENTER. > > Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> > --- > drivers/input/keyboard/locomokbd.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/input/keyboard/locomokbd.c b/drivers/input/keyboard/locomokbd.c > index 9742c79..7645053 100644 > --- a/drivers/input/keyboard/locomokbd.c > +++ b/drivers/input/keyboard/locomokbd.c > @@ -50,7 +50,7 @@ locomokbd_keycode[LOCOMOKBD_NUMKEYS] = { > 0, 0, 0, KEY_CENTER, 0, KEY_MAIL, 0, 0, 0, 0, /* 30 - 39 */ > 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_RIGHT, /* 40 - 49 */ > KEY_UP, KEY_LEFT, 0, 0, KEY_P, 0, KEY_O, KEY_I, KEY_Y, KEY_T, /* 50 - 59 */ > - KEY_E, KEY_W, 0, 0, 0, 0, KEY_DOWN, KEY_ENTER, 0, 0, /* 60 - 69 */ > + KEY_E, KEY_W, 0, 0, 0, 0, KEY_DOWN, KEY_KPENTER, 0, 0, /* 60 - 69 */ > KEY_BACKSPACE, 0, KEY_L, KEY_U, KEY_H, KEY_R, KEY_D, KEY_Q, 0, 0, /* 70 - 79 */ > 0, 0, 0, 0, 0, 0, KEY_ENTER, KEY_RIGHTSHIFT, KEY_K, KEY_J, /* 80 - 89 */ > KEY_G, KEY_F, KEY_X, KEY_S, 0, 0, 0, 0, 0, 0, /* 90 - 99 */ > -- > 2.1.4 >
Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> writes: > Convert poodle to use new mfd-based LoCoMo driver. > > Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> > Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Robert Jarzmik <robert.jarzmik@free.fr> Cheers. -- Robert
On Mon, 25 May 2015, Dmitry Eremin-Solenikov wrote: > LoCoMo is a GA used on Sharp Zaurus SL-5x00. Current driver does has > several design issues (special bus instead of platform bus, doesn't use > mfd-core, etc). > > Implement 'core' parts of locomo support as an mfd driver. > > Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> > --- These things are much easier to re-review if you keep a change-log here. > drivers/mfd/Kconfig | 10 ++ > drivers/mfd/Makefile | 1 + > drivers/mfd/locomo.c | 336 +++++++++++++++++++++++++++++++++++++++++++++ > include/linux/mfd/locomo.h | 169 +++++++++++++++++++++++ > 4 files changed, 516 insertions(+) > create mode 100644 drivers/mfd/locomo.c > create mode 100644 include/linux/mfd/locomo.h Looks good now though: Acked-by: Lee Jones <lee.jones@linaro.org> How do you plan for this to be merged? > diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig > index d5ad04d..8c33940 100644 > --- a/drivers/mfd/Kconfig > +++ b/drivers/mfd/Kconfig > @@ -1430,6 +1430,16 @@ config MFD_STW481X > in various ST Microelectronics and ST-Ericsson embedded > Nomadik series. > > +config MFD_LOCOMO > + bool "Sharp LoCoMo support" > + depends on ARM > + select MFD_CORE > + select IRQ_DOMAIN > + select REGMAP_MMIO > + help > + Support for Sharp LoCoMo Grid Array found in Sharp SL-5x00 > + PDA family. > + > menu "Multimedia Capabilities Port drivers" > depends on ARCH_SA1100 > > diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile > index 0e5cfeb..6c23b73 100644 > --- a/drivers/mfd/Makefile > +++ b/drivers/mfd/Makefile > @@ -181,6 +181,7 @@ obj-$(CONFIG_MFD_HI6421_PMIC) += hi6421-pmic-core.o > obj-$(CONFIG_MFD_DLN2) += dln2.o > obj-$(CONFIG_MFD_RT5033) += rt5033.o > obj-$(CONFIG_MFD_SKY81452) += sky81452.o > +obj-$(CONFIG_MFD_LOCOMO) += locomo.o > > intel-soc-pmic-objs := intel_soc_pmic_core.o intel_soc_pmic_crc.o > obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.o > diff --git a/drivers/mfd/locomo.c b/drivers/mfd/locomo.c > new file mode 100644 > index 0000000..4682893 > --- /dev/null > +++ b/drivers/mfd/locomo.c > @@ -0,0 +1,336 @@ > +/* > + * Sharp LoCoMo support > + * > + * (C) Copyright 2015 Dmitry Eremin-Solenikov > + * > + * Based on old driver at arch/arm/common/locomo.c > + * > + * (C) Copyright 2004 John Lenz > + * > + * 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 file contains all generic LoCoMo support. > + * > + * All initialization functions provided here are intended to be called > + * from machine specific code with proper arguments when required. > + */ > + > +#include <linux/delay.h> > +#include <linux/gpio.h> > +#include <linux/io.h> > +#include <linux/irq.h> > +#include <linux/irqdomain.h> > +#include <linux/kernel.h> > +#include <linux/mfd/core.h> > +#include <linux/mfd/locomo.h> > +#include <linux/module.h> > +#include <linux/platform_device.h> > +#include <linux/regmap.h> > +#include <linux/slab.h> > + > +/* LoCoMo Interrupts */ > +#define IRQ_LOCOMO_KEY 0 > +#define IRQ_LOCOMO_GPIO 1 > +#define IRQ_LOCOMO_LT 2 > +#define IRQ_LOCOMO_SPI 3 > + > +#define LOCOMO_NR_IRQS 4 > + > +/* The following is the overall data for the locomo chip */ > +struct locomo { > + struct device *dev; > + unsigned int irq; > + spinlock_t lock; > + struct irq_domain *domain; > + struct regmap *regmap; > +}; > + > +static struct resource locomo_kbd_resources[] = { > + DEFINE_RES_IRQ(IRQ_LOCOMO_KEY), > +}; > + > +static struct resource locomo_gpio_resources[] = { > + DEFINE_RES_IRQ(IRQ_LOCOMO_GPIO), > +}; > + > +/* Filled in locomo_probe() function, will be kmemduped by platform core */ > +static struct locomo_gpio_platform_data locomo_gpio_pdata; > + > +static struct resource locomo_lt_resources[] = { > + DEFINE_RES_IRQ(IRQ_LOCOMO_LT), > +}; > + > +static struct resource locomo_spi_resources[] = { > + DEFINE_RES_IRQ(IRQ_LOCOMO_SPI), > +}; > + > +/* Filled in locomo_probe() function, will be kmemduped by platform core */ > +static struct locomo_lcd_platform_data locomo_lcd_pdata; > + > +static struct mfd_cell locomo_cells[] = { > + { > + .name = "locomo-kbd", > + .resources = locomo_kbd_resources, > + .num_resources = ARRAY_SIZE(locomo_kbd_resources), > + }, > + { > + .name = "locomo-gpio", > + .resources = locomo_gpio_resources, > + .num_resources = ARRAY_SIZE(locomo_gpio_resources), > + .platform_data = &locomo_gpio_pdata, > + .pdata_size = sizeof(locomo_gpio_pdata), > + }, > + { > + .name = "locomo-lt", /* Long time timer */ > + .resources = locomo_lt_resources, > + .num_resources = ARRAY_SIZE(locomo_lt_resources), > + }, > + { > + .name = "locomo-spi", > + .resources = locomo_spi_resources, > + .num_resources = ARRAY_SIZE(locomo_spi_resources), > + }, > + { > + .name = "locomo-lcd", > + .platform_data = &locomo_lcd_pdata, > + .pdata_size = sizeof(locomo_lcd_pdata), > + }, > + { .name = "locomo-led", }, > + { .name = "locomo-backlight", }, > + { .name = "locomo-i2c", }, > +}; > + > +/* > + * IRQ support > + */ > +static void locomo_handler(unsigned int irq, struct irq_desc *desc) > +{ > + struct locomo *ldev = irq_get_handler_data(irq); > + struct irq_chip *irqchip = irq_desc_get_chip(desc); > + unsigned int req; > + > + chained_irq_enter(irqchip, desc); > + > + /* Check why this interrupt was generated */ > + while (1) { > + regmap_read(ldev->regmap, LOCOMO_ICR, &req); > + req >>= LOCOMO_ICR_STATUS_SHIFT; > + > + if (!req) > + break; > + > + irq = ffs(req) - 1; > + generic_handle_irq(irq_find_mapping(ldev->domain, irq)); > + } > + > + chained_irq_exit(irqchip, desc); > +} > + > +static void locomo_mask_irq(struct irq_data *d) > +{ > + struct locomo *ldev = irq_data_get_irq_chip_data(d); > + unsigned int mask = BIT(d->hwirq + LOCOMO_ICR_MASK_SHIFT); > + > + regmap_update_bits(ldev->regmap, LOCOMO_ICR, mask, 0); > +} > + > +static void locomo_unmask_irq(struct irq_data *d) > +{ > + struct locomo *ldev = irq_data_get_irq_chip_data(d); > + unsigned int mask = BIT(d->hwirq + LOCOMO_ICR_MASK_SHIFT); > + > + regmap_update_bits(ldev->regmap, LOCOMO_ICR, mask, mask); > +} > + > +static struct irq_chip locomo_chip = { > + .name = "locomo", > + .irq_mask = locomo_mask_irq, > + .irq_unmask = locomo_unmask_irq, > +}; > + > +static int locomo_irq_map(struct irq_domain *d, unsigned int virq, > + irq_hw_number_t hwirq) > +{ > + struct locomo *locomo = d->host_data; > + > + irq_set_chip_data(virq, locomo); > + irq_set_chip_and_handler(virq, &locomo_chip, handle_level_irq); > + set_irq_flags(virq, IRQF_VALID); > + > + return 0; > +} > + > +static void locomo_irq_unmap(struct irq_domain *d, unsigned int virq) > +{ > + set_irq_flags(virq, 0); > + irq_set_chip_and_handler(virq, NULL, NULL); > + irq_set_chip_data(virq, NULL); > +} > + > +static struct irq_domain_ops locomo_irq_ops = { > + .map = locomo_irq_map, > + .unmap = locomo_irq_unmap, > + .xlate = irq_domain_xlate_onecell, > +}; > + > +static int locomo_setup_irq(struct locomo *ldev) > +{ > + ldev->domain = irq_domain_add_simple(NULL, LOCOMO_NR_IRQS, 0, > + &locomo_irq_ops, ldev); > + if (!ldev->domain) > + return -ENOMEM; > + > + /* > + * Install handler for IRQ_LOCOMO_HW. > + */ > + irq_set_irq_type(ldev->irq, IRQ_TYPE_EDGE_FALLING); > + irq_set_handler_data(ldev->irq, ldev); > + irq_set_chained_handler(ldev->irq, locomo_handler); > + > + return 0; > +} > + > +#ifdef CONFIG_PM_SLEEP > +static int locomo_suspend(struct device *dev) > +{ > + struct locomo *ldev = dev_get_drvdata(dev); > + > + /* Audio */ > + regmap_write(ldev->regmap, LOCOMO_PAIF, 0x00); > + > + /* > + * Original code disabled the clock depending on leds settings > + * However we disable leds before suspend, thus it's safe > + * to just assume this setting. > + */ > + /* CLK32 off */ > + regmap_write(ldev->regmap, LOCOMO_C32K, 0x00); > + > + /* 22MHz/24MHz clock off */ > + regmap_write(ldev->regmap, LOCOMO_ACC, 0x00); > + > + return 0; > +} > + > +static int locomo_resume(struct device *dev) > +{ > + struct locomo *ldev = dev_get_drvdata(dev); > + > + regmap_write(ldev->regmap, LOCOMO_C32K, 0x00); > + > + return 0; > +} > +#endif > + > +static SIMPLE_DEV_PM_OPS(locomo_pm, locomo_suspend, locomo_resume); > + > +static const struct regmap_config locomo_regmap_config = { > + .name = "LoCoMo", > + .reg_bits = 8, > + .reg_stride = 4, > + .val_bits = 16, > + .cache_type = REGCACHE_NONE, > + .max_register = 0xec, > +}; > + > +static int locomo_probe(struct platform_device *pdev) > +{ > + struct locomo_platform_data *pdata = dev_get_platdata(&pdev->dev); > + struct resource *res; > + void __iomem *base; > + struct locomo *ldev; > + unsigned int rev; > + int ret; > + > + ldev = devm_kzalloc(&pdev->dev, sizeof(*ldev), GFP_KERNEL); > + if (!ldev) > + return -ENOMEM; > + > + spin_lock_init(&ldev->lock); > + ldev->dev = &pdev->dev; > + > + ldev->irq = platform_get_irq(pdev, 0); > + if (ldev->irq < 0) > + return ldev->irq; > + > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > + base = devm_ioremap_resource(&pdev->dev, res); > + if (IS_ERR(base)) > + return PTR_ERR(base); > + > + ldev->regmap = devm_regmap_init_mmio(&pdev->dev, base, > + &locomo_regmap_config); > + if (IS_ERR(ldev->regmap)) > + return PTR_ERR(ldev->regmap); > + > + if (pdata) { > + locomo_gpio_pdata.gpio_base = pdata->gpio_base; > + locomo_lcd_pdata.comadj = pdata->comadj; > + } else { > + locomo_gpio_pdata.gpio_base = -1; > + locomo_lcd_pdata.comadj = 128; > + } > + > + platform_set_drvdata(pdev, ldev); > + > + regmap_read(ldev->regmap, LOCOMO_VER, &rev); > + dev_info(&pdev->dev, "LoCoMo Chip: %04x\n", rev); > + > + /* Clear IRQ status and mask */ > + regmap_write(ldev->regmap, LOCOMO_ICR, 0); > + > + /* Longtime timer */ > + regmap_write(ldev->regmap, LOCOMO_LTINT, 0); > + > + ret = locomo_setup_irq(ldev); > + if (ret) > + return ret; > + > + ret = mfd_add_devices(&pdev->dev, pdev->id, > + locomo_cells, ARRAY_SIZE(locomo_cells), > + res, -1, ldev->domain); > + if (ret) > + goto err; > + > + return 0; > + > +err: > + irq_set_chained_handler(ldev->irq, NULL); > + irq_set_handler_data(ldev->irq, NULL); > + > + irq_domain_remove(ldev->domain); > + > + return ret; > +} > + > +static int locomo_remove(struct platform_device *dev) > +{ > + struct locomo *ldev = platform_get_drvdata(dev); > + > + mfd_remove_devices(&dev->dev); > + > + irq_set_chained_handler(ldev->irq, NULL); > + irq_set_handler_data(ldev->irq, NULL); > + > + irq_domain_remove(ldev->domain); > + > + return 0; > +} > + > +static struct platform_driver locomo_device_driver = { > + .probe = locomo_probe, > + .remove = locomo_remove, > + .driver = { > + .name = "locomo", > + .pm = &locomo_pm, > + }, > +}; > + > +module_platform_driver(locomo_device_driver); > + > +MODULE_DESCRIPTION("Sharp LoCoMo core driver"); > +MODULE_LICENSE("GPL v2"); > +MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>"); > +MODULE_ALIAS("platform:locomo"); > diff --git a/include/linux/mfd/locomo.h b/include/linux/mfd/locomo.h > new file mode 100644 > index 0000000..999e3de > --- /dev/null > +++ b/include/linux/mfd/locomo.h > @@ -0,0 +1,169 @@ > +/* > + * This file contains the definitions for the LoCoMo G/A Chip > + * > + * (C) Copyright 2015 Dmitry Eremin-Solenikov > + * (C) Copyright 2004 John Lenz > + * > + * May be copied or modified under the terms of the GNU General Public > + * License. See linux/COPYING for more information. > + * > + * Based on sa1111.h > + */ > + > +#ifndef _ASM_ARCH_LOCOMO > +#define _ASM_ARCH_LOCOMO > + > +/* LOCOMO chip version */ > +#define LOCOMO_VER 0x00 > + > +/* Pin status */ > +#define LOCOMO_ST 0x04 > + > +/* Pin status */ > +#define LOCOMO_C32K 0x08 > + > +/* Interrupt controller */ > +#define LOCOMO_ICR 0x0c > +#define LOCOMO_ICR_MASK_SHIFT 4 > +#define LOCOMO_ICR_STATUS_SHIFT 8 > + > +/* Touch panel controller */ > +#define LOCOMO_ASD 0x20 /* AD start delay */ > +#define LOCOMO_HSD 0x28 /* HSYS delay */ > +#define LOCOMO_HSC 0x2c /* HSYS period */ > +#define LOCOMO_TADC 0x30 /* tablet ADC clock */ > + > +/* Backlight controller: TFT signal */ > +#define LOCOMO_TC 0x38 /* TFT control signal */ > +#define LOCOMO_CPSD 0x3c /* CPS delay */ > + > +/* Keyboard controller */ > +#define LOCOMO_KIB 0x40 /* KIB level */ > +#define LOCOMO_KSC 0x44 /* KSTRB control */ > +#define LOCOMO_KCMD 0x48 /* KSTRB command */ > +#define LOCOMO_KIC 0x4c /* Key interrupt */ > + > +/* Audio clock */ > +#define LOCOMO_ACC 0x54 /* Audio clock */ > +#define LOCOMO_ACC_XON 0x80 > +#define LOCOMO_ACC_XEN 0x40 > +#define LOCOMO_ACC_XSEL0 0x00 > +#define LOCOMO_ACC_XSEL1 0x20 > +#define LOCOMO_ACC_MCLKEN 0x10 > +#define LOCOMO_ACC_64FSEN 0x08 > +#define LOCOMO_ACC_CLKSEL000 0x00 /* mclk 2 */ > +#define LOCOMO_ACC_CLKSEL001 0x01 /* mclk 3 */ > +#define LOCOMO_ACC_CLKSEL010 0x02 /* mclk 4 */ > +#define LOCOMO_ACC_CLKSEL011 0x03 /* mclk 6 */ > +#define LOCOMO_ACC_CLKSEL100 0x04 /* mclk 8 */ > +#define LOCOMO_ACC_CLKSEL101 0x05 /* mclk 12 */ > + > +/* SPI interface */ > +#define LOCOMO_SPIMD 0x60 /* SPI mode setting */ > +#define LOCOMO_SPIMD_LOOPBACK BIT(15) /* loopback tx to rx */ > +#define LOCOMO_SPIMD_MSB1ST BIT(14) /* send MSB first */ > +#define LOCOMO_SPIMD_DOSTAT BIT(13) /* transmit line is idle high */ > +#define LOCOMO_SPIMD_TCPOL BIT(11) /* transmit CPOL (maybe affects CPHA) */ > +#define LOCOMO_SPIMD_RCPOL BIT(10) /* receive CPOL (maybe affects CPHA) */ > +#define LOCOMO_SPIMD_TDINV BIT(9) /* invert transmit line */ > +#define LOCOMO_SPIMD_RDINV BIT(8) /* invert receive line */ > +#define LOCOMO_SPIMD_XON BIT(7) /* enable spi controller clock */ > +#define LOCOMO_SPIMD_XEN BIT(6) /* clock bit write enable */ > +#define LOCOMO_SPIMD_XSEL 0x0018 /* clock select */ > +/* xon must be off when enabling xen, wait 300 us before xon -> 1 */ > +#define CLOCK_18MHZ 0 /* 18,432 MHz clock */ > +#define CLOCK_22MHZ 1 /* 22,5792 MHz clock */ > +#define CLOCK_25MHZ 2 /* 24,576 MHz clock */ > +#define LOCOMO_SPIMD_CLKSEL 0x7 > +#define DIV_1 0 /* don't divide clock */ > +#define DIV_2 1 /* divide clock by two */ > +#define DIV_4 2 /* divide clock by four */ > +#define DIV_8 3 /* divide clock by eight */ > +#define DIV_64 4 /* divide clock by 64 */ > + > +#define LOCOMO_SPICT 0x64 /* SPI mode control */ > +#define LOCOMO_SPICT_CRC16_7_B BIT(15) /* 0: crc16 1: crc7 */ > +#define LOCOMO_SPICT_CRCRX_TX_B BIT(14) > +#define LOCOMO_SPICT_CRCRESET_B BIT(13) > +#define LOCOMO_SPICT_CEN BIT(7) /* ?? enable */ > +#define LOCOMO_SPICT_CS BIT(6) /* chip select */ > +#define LOCOMO_SPICT_UNIT16 BIT(5) /* 0: 8 bit, 1: 16 bit*/ > +#define LOCOMO_SPICT_ALIGNEN BIT(2) /* align transfer enable */ > +#define LOCOMO_SPICT_RXWEN BIT(1) /* continuous receive */ > +#define LOCOMO_SPICT_RXUEN BIT(0) /* aligned receive */ > + > +#define LOCOMO_SPIST 0x68 /* SPI status */ > +#define LOCOMO_SPI_TEND BIT(3) /* Transfer end bit */ > +#define LOCOMO_SPI_REND BIT(2) /* Receive end bit */ > +#define LOCOMO_SPI_RFW BIT(1) /* write buffer bit */ > +#define LOCOMO_SPI_RFR BIT(0) /* read buffer bit */ > + > +#define LOCOMO_SPIIS 0x70 /* SPI interrupt status */ > +#define LOCOMO_SPIWE 0x74 /* SPI interrupt status write enable */ > +#define LOCOMO_SPIIE 0x78 /* SPI interrupt enable */ > +#define LOCOMO_SPIIR 0x7c /* SPI interrupt request */ > +#define LOCOMO_SPITD 0x80 /* SPI transfer data write */ > +#define LOCOMO_SPIRD 0x84 /* SPI receive data read */ > +#define LOCOMO_SPITS 0x88 /* SPI transfer data shift */ > +#define LOCOMO_SPIRS 0x8C /* SPI receive data shift */ > + > +/* GPIO */ > +#define LOCOMO_GPD 0x90 /* GPIO direction */ > +#define LOCOMO_GPE 0x94 /* GPIO input enable */ > +#define LOCOMO_GPL 0x98 /* GPIO level */ > +#define LOCOMO_GPO 0x9c /* GPIO out data setting */ > +#define LOCOMO_GRIE 0xa0 /* GPIO rise detection */ > +#define LOCOMO_GFIE 0xa4 /* GPIO fall detection */ > +#define LOCOMO_GIS 0xa8 /* GPIO edge detection status */ > +#define LOCOMO_GWE 0xac /* GPIO status write enable */ > +#define LOCOMO_GIE 0xb0 /* GPIO interrupt enable */ > +#define LOCOMO_GIR 0xb4 /* GPIO interrupt request */ > + > +/* Front light adjustment controller */ > +#define LOCOMO_ALS 0xc8 /* Adjust light cycle */ > +#define LOCOMO_ALS_EN 0x8000 > +#define LOCOMO_ALD 0xcc /* Adjust light duty */ > + > +/* PCM audio interface */ > +#define LOCOMO_PAIF 0xd0 /* PCM audio interface */ > +#define LOCOMO_PAIF_SCINV 0x20 > +#define LOCOMO_PAIF_SCEN 0x10 > +#define LOCOMO_PAIF_LRCRST 0x08 > +#define LOCOMO_PAIF_LRCEVE 0x04 > +#define LOCOMO_PAIF_LRCINV 0x02 > +#define LOCOMO_PAIF_LRCEN 0x01 > + > +/* Long time timer */ > +#define LOCOMO_LTC 0xd8 /* LTC interrupt setting */ > +#define LOCOMO_LTINT 0xdc /* LTC interrupt */ > + > +/* DAC control signal for LCD (COMADJ ) */ > +#define LOCOMO_DAC 0xe0 > +/* DAC control */ > +#define LOCOMO_DAC_SCLOEB 0x08 /* SCL pin output data */ > +#define LOCOMO_DAC_TEST 0x04 /* Test bit */ > +#define LOCOMO_DAC_SDA 0x02 /* SDA pin level (read-only) */ > +#define LOCOMO_DAC_SDAOEB 0x01 /* SDA pin output data */ > + > +/* LED controller */ > +#define LOCOMO_LPT0 0xe8 > +#define LOCOMO_LPT1 0xec > +#define LOCOMO_LPT_TOFH 0x80 > +#define LOCOMO_LPT_TOFL 0x08 > +#define LOCOMO_LPT_TOH(TOH) ((TOH & 0x7) << 4) > +#define LOCOMO_LPT_TOL(TOL) ((TOL & 0x7)) > + > +struct locomo_gpio_platform_data { > + unsigned int gpio_base; > +}; > + > +struct locomo_lcd_platform_data { > + u8 comadj; > +}; > + > +struct locomo_platform_data { > + unsigned int gpio_base; > + u8 comadj; > +}; > + > +#endif
2015-05-27 13:27 GMT+03:00 Lee Jones <lee.jones@linaro.org>: > On Mon, 25 May 2015, Dmitry Eremin-Solenikov wrote: > >> LoCoMo is a GA used on Sharp Zaurus SL-5x00. Current driver does has >> several design issues (special bus instead of platform bus, doesn't use >> mfd-core, etc). >> >> Implement 'core' parts of locomo support as an mfd driver. >> >> Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> >> --- > > These things are much easier to re-review if you keep a change-log > here. > >> drivers/mfd/Kconfig | 10 ++ >> drivers/mfd/Makefile | 1 + >> drivers/mfd/locomo.c | 336 +++++++++++++++++++++++++++++++++++++++++++++ >> include/linux/mfd/locomo.h | 169 +++++++++++++++++++++++ >> 4 files changed, 516 insertions(+) >> create mode 100644 drivers/mfd/locomo.c >> create mode 100644 include/linux/mfd/locomo.h > > Looks good now though: > Acked-by: Lee Jones <lee.jones@linaro.org> > > How do you plan for this to be merged? I'd like for this to be merged either through mfd tree or through the arm-soc (or rmk's ARM) tree. Some of the respective maintainers already gave their blessing for this patchset to be merged not through their subsystem trees. [skipped the patch]
On Thu, May 28, 2015 at 9:07 PM, Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> wrote: > * Linus, can I assume that yours 'Reviewed-by' mean > 'Acked-by' for the GPIO-related parts? Yes. Yours, Linus Walleij