> On Wed, Nov 10, 2010 at 5:07 PM, dylan cristiani > <d.cristiani@xxxxxxxxxxxx> wrote: > > On Tue, 9 Nov 2010 19:36:13 +0100 > > Marek Vasut <marek.vasut@xxxxxxxxx> wrote: > > > > > On Tuesday 09 November 2010 18:42:20 dylan cristiani wrote: > > > > We heard some month ago, about ucb1400 irq passing, via > > > > ucb1400_platform_data; then you wrote the patch, that is currently > > > > into mainline; i've a little problem, probably due to my infinite > > > > ignorance: i'm writing a sort of my_pm.c driver to check whether > > > > the ac line is plugged or not, check the main battery voltage and > > > > so on (similar to arch/arm/mach-pxa/sharpsl_pm.c and corgi_pm.c if > > > > you know it); the problem is that the battery voltages are tied to > > > > the ucb1400 ADC inputs, and in my_pm.c driver i don't know how to > > > > find the ucb1400_ts structure address to call the functions i need > > > > to read these ADC input i.e.: > > > > > > 1) CC lists > > > > > > 2) Can you post the driver source you have ? > > > > > > without seeing the source, I can't help you > > here it comes but please close your nose before reading....;-) > > > > arch/arm/mach-pxa/nilux_pm.c > > > > /* > > Â* Based on spitz_pm.c and sharp code. > > Â* > > Â* Distributed under term of GPLv2. > > Â* > > Â*/ > > > > #include <linux/module.h> > > #include <linux/stat.h> > > #include <linux/init.h> > > #include <linux/completion.h> > > #include <linux/kernel.h> > > #include <linux/delay.h> > > #include <linux/gpio.h> > > //#include <linux/input.h> > > #include <linux/device.h> > > #include <linux/interrupt.h> > > #include <linux/suspend.h> > > #include <linux/apm-emulation.h> > > #include <linux/platform_device.h> > > #include <linux/ucb1400.h> > > > > #include <asm/irq.h> > > #include <asm/mach-types.h> > > #include <mach/hardware.h> > > > > #include <mach/pm.h> > > #include <mach/pxa2xx-regs.h> > > #include <mach/regs-rtc.h> > > #include <mach/sharpsl_pm.h> > > > > > > #define AC_IN_INT        17 > > #define NYLUX_BATT_VOLT     1 > > #define NYLUX_STATUS_ACIN    4 > > #define NYLUX_BKUPBATT_TEMP   2 > > #define NYLUX_CHARGE_STATUS   3 > > > > > > static struct ucb1400_ts *ucb; > > > > static void nylux_charger_init(void) > > { > > } > > > > static void nylux_charger_exit(void) > > { > > } > > > > unsigned long nylux_read_main_battery(void) > > { > > //   Âstruct ucb1400_ts *ucb; > >    Âunsigned int voltage = 0; > > > >    Âprintk(KERN_INFO "Reading_Main_Battery\n"); > > > >    Âucb1400_adc_enable(ucb->ac97); > > > > //   Âprintk(KERN_INFO "Post adc_enable\n"); > > > >    Âmdelay(1); > >    Âvoltage = ucb1400_adc_read(ucb->ac97, UCB_ADC_INP_AD0, 0); > >    Âprintk(KERN_INFO "\nVVVVVVvoltage %d\n", voltage); > > > >    Âucb1400_adc_disable(ucb->ac97); > > > >    Âreturn voltage; > > } > > > > unsigned long nylux_read_bkup_battery(void) > > { > > //   Âstruct ucb1400_ts *ucb; > >    Âunsigned int voltage; > > > >    Âucb1400_adc_enable(ucb->ac97); > > > >    Âmdelay(1); > >    Âvoltage = ucb1400_adc_read(ucb->ac97, UCB_ADC_INP_AD1, 0); > > > >    Âucb1400_adc_disable(ucb->ac97); > >    Â//printk(KERN_INFO "Battery_bkup value = %d\n", voltage); > > > >    Âreturn voltage; > > } > > > > unsigned long nylux_charge_status(void) > > { > > //   Âstruct ucb1400_ts *ucb; > >    Âunsigned int status; > > > >    Â//printk(KERN_INFO "Charge_status\n"); > >    Âucb1400_adc_enable(ucb->ac97); > >    Âmdelay(1); > >    Âstatus = ucb1400_adc_read(ucb->ac97, UCB_ADC_INP_AD2, 0); > >    Â//printk(KERN_INFO "Charge status= %d\n", status); > >    Âucb1400_adc_disable(ucb->ac97); > > > >    Âreturn status; > > > > } > > > > static unsigned long nylux_read_devdata(int which) > > { > >    Âunsigned long ret = ~0; > > > >    Âswitch (which) { > >    Âcase NYLUX_BATT_VOLT: > >        Âret = nylux_read_main_battery(); > >        Â//printk(KERN_INFO "read_main_battery: %d\n", ret); > >        Âbreak; > >    Â//case NYLUX_BKUPBATT_TEMP: > >        Â//ret = nylux_read_bkup_battery(); > >        Â//break; > >    Â//case NYLUX_CHARGE_STATUS: > >        Â//ret = nylux_charge_status(); > >        Â//break; > >    Âcase NYLUX_STATUS_ACIN: { > >        Âret = GPLR(AC_IN_INT) & GPIO_bit(AC_IN_INT); > >        Â//printk(KERN_INFO "AC_IN = %d\n", ret); > >        Â//ret = read_ac_status(); > >        Â//printk(KERN_INFO "read_ac_status: %d\n", ret); > >        Âbreak; > >    Â} > > > >    Âdefault: > >        Âret = ~0; > >    Â} > > > >    Âreturn ret; > > > > } > > > > //****** > > struct battery_thresh battery_levels[] = { > >    Â{ 550, 100}, > >    Â{ 544, Â97}, > >    Â{ 541, Â93}, > >    Â{ 536, Â88}, > >    Â{ 531, Â83}, > >    Â{ 526, Â78}, > >    Â{ 522, Â73}, > >    Â{ 517, Â68}, > >    Â{ 514, Â63}, > >    Â{ 510, Â58}, > >    Â{ 506, Â53}, > >    Â{ 503, Â48}, > >    Â{ 499, Â43}, > >    Â{ 497, Â38}, > >    Â{ 495, Â33}, > >    Â{ 493, Â28}, > >    Â{ 492, Â23}, > >    Â{ 491, Â18}, > >    Â{ 489, Â13}, > >    Â{ 488,  8}, > >    Â{ 484,  3}, > >    Â{ 478,  0} > > }; > > > > struct sharpsl_charger_machinfo nylux_pm_machinfo = { > >    Â.init       = nylux_charger_init, > >    Â.exit       = nylux_charger_exit, > >    Â.gpio_acin    Â= AC_IN_INT, > >    Â.read_devdata   = nylux_read_devdata, > >    Â.discharge    Â= 0, > >    Â.discharge1    = 0, > >    Â.charge      = 0, > >    Â.measure_temp   = 0, > >    Â.presuspend    = 0, > >    Â.postsuspend   Â= 0, > >    Â.charger_wakeup  = 0, > >    Â.should_wakeup  Â= 0, > >    Â.bat_levels    = 22, > >    Â.bat_levels_noac Â= battery_levels, > >    Â.bat_levels_acin Â= 0, > >    Â.status_high_acin = 510, > >    Â.status_low_acin Â= 490, > >    Â.status_high_noac = 510, > >    Â.status_low_noac Â= 490, > >    Â.charge_on_volt  = 0, > >    Â.charge_on_temp  = 0, > >    Â.charge_acin_high = 0, > >    Â.charge_acin_low Â= 0, > >    Â.fatal_acin_volt Â= 0, > >    Â.fatal_noacin_volt = 0, > > > >    Â.batfull_irq   Â= 1 > > }; > > > > > > /* > > static int __init collie_pm_ucb_add(struct ucb1x00_dev *pdev) > > { > >    Âsharpsl_pm.machinfo = &nylux_pm_machinfo; > >    Âucb = pdev->ucb; > >    Âreturn 0; > > } > > > > static struct ucb1x00_driver collie_pm_ucb_driver = { > >    Â.add      Â= collie_pm_ucb_add, > > }; > > */ > > > > static struct platform_device *nyluxpm_device; > > > > static int __devinit nyluxpm_init(void) > > { > >    Âint ret; > > > >    Ânyluxpm_device = platform_device_alloc("sharpsl-pm", -1); > >    Âif (!nyluxpm_device) > >        Âreturn -ENOMEM; > > > >    Ânyluxpm_device->dev.platform_data = &nylux_pm_machinfo; > >    Âret = platform_device_add(nyluxpm_device); > > > >    Âif (ret) > >        Âplatform_device_put(nyluxpm_device); > > > > //   Âif (!ret) > > //       Âret = ucb1x00_register_driver(&collie_pm_ucb_driver); > > > >    Âreturn ret; > > } > > > > static void nyluxpm_exit(void) > > { > > //   Âucb1x00_unregister_driver(&collie_pm_ucb_driver); > >    Âplatform_device_unregister(nyluxpm_device); > > } > > > > module_init(nyluxpm_init); > > module_exit(nyluxpm_exit); > > > > > > thanks > > dylan > > > > _______________________________________________ > > linux-arm-kernel mailing list > > linux-arm-kernel@xxxxxxxxxxxxxxxxxxx > > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel > > > > You should append your power driver into drivers/power directory. > There's an example of colie_battery.c. It's also based on udc. That's basically what I said a few lines above ;-) btw I think he's also intermixing ucb1x00 (ucb < 1400) and ucb1400 > > Thanks > Haojian -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html