Beispiel #1
0
int close_pclta( struct inode *inode, struct file *file )
{
    struct pclta_device *device = pclta_device_table[MINOR(inode->i_rdev)];

	CALL_MSG("close_pclta()", ++pclta_call_level );
	
    if( device == NULL ) {
		RETURN_MSG("close_pclta() ENXIO", pclta_call_level-- );
    	return -ENXIO; // no such device
	}
    if( device->state == Offline ) {
		RETURN_MSG("close_pclta() already closed", pclta_call_level-- );
    	return 0; // device already closed
	}
// karl removed this for 2.4 kernel 30 July 2001
//    if( file->f_count >1 ) {
//		RETURN_MSG("close_pclta() EBUSY", pclta_call_level-- );
//    	return -EBUSY; // not the last process
//    }
    
    device->state = Offline;
    init_hw( device->base_address, 0x00, device->txcvr_clock );  // turn off interupts
    close_device( device );
    MOD_DEC_USE_COUNT;

	RETURN_MSG("close_pclta()", pclta_call_level-- );
	
    return 0;
}
ssize_t touchkey_update_write(struct file *filp, const char *buf, size_t count,
			      loff_t * f_pos)
{
	unsigned char *pdata;

	disable_irq(IRQ_TOUCH_INT);
	printk("count = %d\n", count);
	pdata = kzalloc(count, GFP_KERNEL);
	if (pdata == NULL) {
		printk("memory allocate fail \n");
		return 0;
	}
	if (copy_from_user(pdata, buf, count)) {
		printk("copy fail \n");
		kfree(pdata);
		return 0;
	}

	mcsdl_download_binary_file((unsigned char *)pdata,
				   (unsigned short)count);
	kfree(pdata);

	init_hw();
	enable_irq(IRQ_TOUCH_INT);
	return count;
}
static void melfas_touchkey_early_resume(struct early_suspend *h)
{
	set_touchkey_debug('R');
	printk(KERN_DEBUG "[TKEY] melfas_touchkey_early_resume\n");
	if (touchkey_enable < 0) {
		printk("[TKEY] %s touchkey_enable: %d\n", __FUNCTION__, touchkey_enable);
		return;
	}

		tkey_vdd_enable(1);
		gpio_request(GPIO_TOUCHKEY_SCL, "TKEY_SCL");
		gpio_direction_input(GPIO_TOUCHKEY_SCL);
		gpio_request(GPIO_TOUCHKEY_SDA, "TKEY_SDA");
		gpio_direction_input(GPIO_TOUCHKEY_SDA);
		init_hw();

if(touchled_cmd_reversed) {
			touchled_cmd_reversed = 0;
			msleep(100);

			if(!touchkey_enable )
				touchkey_enable = 1; 
			i2c_touchkey_write(&touchkey_led_status, 1);
			printk("[TKEY] LED RESERVED !! LED returned on touchkey_led_status = %d\n", touchkey_led_status);
	}
if (get_hw_rev() >=0x02){		
	tkey_led_vdd_enable(1); 	
}	

enable_irq(IRQ_TOUCHKEY_INT);
touchkey_enable = 1;
msleep(50);
touchkey_auto_calibration(1/*on*/); 

}
Beispiel #4
0
int kmain (void){
	init_hw();
  	uart_init();
  	
	/*-- INPUT --*/
	//char buffer[32];
  	//uart_receive_str(buffer, 32);  //read

	/*-- PROCESS --*/
	create_process(funcA, NULL, STACK_SIZE,0);
	create_process(funcB, NULL, STACK_SIZE,0);
	create_process(functC,NULL,STACK_SIZE,1);
	
	/*-- virtual memory --*/
	//init_kern_translation_table();

	//configure_mmu_C();
	//start_mmu_C();

	//uint32_t* pt = (uint32_t*)vMem_Alloc(1);
	//*pt = sizeof(uint32_t);
	//uint32_t* pt = 0x500000;
	
	/*-- start --*/
	start_sched();

	while(1){}
	/* Pas atteignable vues nos 2 fonctions */
	return 0;
  
}
Beispiel #5
0
static ssize_t set_touchkey_update_show(struct device *dev, struct device_attribute *attr, char *buf)
{
	/*TO DO IT */
	int count=0;
	int retry=3;
	touchkey_update_status = 1;

	while (retry--) {
		if (ISSP_main() == 0) {
			printk(KERN_ERR"[TOUCHKEY]Touchkey_update succeeded\n");
			touchkey_update_status = 0;
			count=1;
			break;
		}
		printk(KERN_ERR"touchkey_update failed... retry...\n");
	}
	if (retry <= 0) {
		// disable ldo11
		touchkey_ldo_on(0);
		msleep(300);
		count=0;
		printk(KERN_ERR"[TOUCHKEY]Touchkey_update fail\n");
		touchkey_update_status = -1;
		return count;
	}

	init_hw();	/* after update, re initalize. */

	return count;

}
Beispiel #6
0
int main()
{
    //Assign pins and whatnot
    init_hw();

    //Set up the screen values, but not sure this makes sense
    //because the epic ought to send it the latest values
    init_vals();

    //LCD initialisation incantations
    lcd_init();

    //Performed here, but also redone every time the sensor chip returns a zero
    //on the i2c
    reset_rht();

    //Unpack the QR code into a bit array
    unpack();

    //do the screen 'touch points to calibrate' prompt
    tp_calibrate();

    while(1)
    {
        poll_tp();
        poll_screen();
        rxipoll();
        poll_temps();
        poll_val_uploads();
        rxipoll();
    }

}
Beispiel #7
0
static ssize_t set_touchkey_autocal_testmode(struct device *dev,
				 struct device_attribute *attr, const char *buf,
				 size_t size)
{
	int count = 0;
	u8 set_data;
	int on_off;

	if (sscanf(buf, "%d\n", &on_off) == 1) {
		printk(KERN_ERR "[TouchKey] Test Mode : %d \n", on_off);

		if (on_off == 1) {
			set_data = 0x40;
			count = i2c_touchkey_write(&set_data, 1);
		} else {
			touchkey_ldo_on(0);
			msleep(50);
			touchkey_ldo_on(1);
			msleep(50);
			init_hw();
			msleep(50);
			touchkey_autocalibration();
		}
	} else {
		printk(KERN_ERR "[TouchKey] set_touchkey_autocal_testmode Error\n");
	}

	return count;
}
void touchkey_update_func(struct work_struct *p)
{
	int retry = 10;
#if defined(CONFIG_TARGET_LOCALE_NAATT)
	char data[3];
	i2c_touchkey_read(KEYCODE_REG, data, 3);
	printk(KERN_DEBUG"[%s] F/W version: 0x%x, Module version:0x%x\n", __FUNCTION__, data[1], data[2]);
#endif

	touchkey_update_status = 1;
	printk(KERN_DEBUG "[TouchKey] %s start\n", __func__);
	while (retry--) {
		if (ISSP_main() == 0) {
			touchkey_update_status = 0;
			printk(KERN_DEBUG
			       "[TouchKey] touchkey_update succeeded\n");
			enable_irq(IRQ_TOUCH_INT);
			return;
		}
#if defined(CONFIG_TARGET_LOCALE_NAATT)
		touchkey_ldo_on(0);
		msleep(300);
		init_hw();
#endif
	}

	touchkey_update_status = -1;
	printk(KERN_DEBUG "[TouchKey] touchkey_update failed\n");
	return;
}
Beispiel #9
0
static void melfas_touchkey_early_resume(struct early_suspend *h)
{
	init_hw();
	enable_irq(IRQ_TOUCH_INT);

        if ( set_tsp_for_usb_detect_value  == 1 )
    {
	set_tsp_for_usb_detect(1);
	set_tsp_for_usb_detect_value = 0;
    }
    else if ( set_tsp_for_usb_release_value == 1 )
    {
	set_tsp_for_usb_detect(0);
    	set_tsp_for_usb_release_value = 0;
    }
    else if ( set_tsp_for_ta_detect_value == 1 )
    {
	set_tsp_for_ta_detect(1);		
    	set_tsp_for_ta_detect_value = 0;
    }
    else if ( set_tsp_for_ta_release_value == 1 )
    {
	set_tsp_for_ta_detect(0);		    
    	set_tsp_for_ta_release_value = 0;
    }

}
Beispiel #10
0
int init_all_hw()
{
	int i;
	char name[50];

	LOG("starting init_all_hw %d", init_complete);
	if (init_complete)
		return num_adapters;
	mutex_init(&a_mutex);
	mutex_lock(&a_mutex);
	find_adapters();
	num_adapters = 0;
	init_complete = 1;
	for (i = 0; i < MAX_ADAPTERS; i++)
		if (!a[i]
				|| ((!a[i]->enabled || a[i]->fe <= 0)
						&& ((a[i]->pa >= 0 && a[i]->fn >= 0) || a[i]->sip)))
		{
			if (!init_hw(i))
				num_adapters++;
		}
		else if (a[i]->enabled)
			num_adapters++;
	if (num_adapters == 0)
		init_complete = 0;
	LOG("done init_hw %d", init_complete);
	if (init_complete)
		getAdaptersCount();
	mutex_unlock(&a_mutex);
	return num_adapters;
}
Beispiel #11
0
static int __init touchkey_init(void)
{
	int ret = 0;
	int retry = 3;
#if 0
	//update version "eclair/vendor/samsung/apps/Lcdtest/src/com/sec/android/app/lcdtest/touch_firmware.java"
	//if ((data[1] >= 0xa1) && (data[1] < 0xa9)) {
		//set_touchkey_debug('U');
		while (retry--) {
			if (ISSP_main() == 0) {
				printk("touchkey_update succeeded\n");
				//set_touchkey_debug('C');
				break;
			}
			printk("touchkey_update failed... retry...\n");
			//set_touchkey_debug('f');
		}
		if (retry <= 0) {
			gpio_direction_output(_3_GPIO_TOUCH_EN, 0);
#if !defined(CONFIG_ARIES_NTT)
			gpio_direction_output(_3_GPIO_TOUCH_CE, 0);
#endif
			msleep(300);
		}
		init_hw();	//after update, re initalize.
	//}
#endif
	ret = i2c_add_driver(&touchkey_i2c_driver);
	if (ret)
		pr_err("%s: cypress touch keypad registration failed. (%d)\n",
				__func__, ret);

	return ret;
}
Beispiel #12
0
int main(void)
{
unsigned char IR[12]; // 0 -> avcc=ref

  init_hw();
  while (1) {
    if (i2c_get_received_data(rec_buf)){
      if (rec_buf[0] == SET_COLOR){
            RGB[0] = rec_buf[1];
            RGB[1] = rec_buf[2];
            RGB[2] = rec_buf[3];
      }
      if(rec_buf[0] == READ_IR ){
        out_buf[0]= IR[0]; out_buf[1]= IR[1];
        out_buf[2]= IR[2]; out_buf[3]= IR[3];
        i2c_send_data(out_buf);
      }
    }
    // Update PWMs
    set_color (RED,   RGB[0]);
    set_color (GREEN, RGB[1]);
    set_color (BLUE,  RGB[2]);


    Read_IR((unsigned short*)IR, 0x80);

    _delay_ms(IR_DELAY); 


  }
 return(0); // avoid gcc warning
}
Beispiel #13
0
int main() {
  queue_element qel;
  queue_init(&que);

  init_hw();

  printf_P(PSTR("\n----- EventQueue/Button Tester ver %s -----\n"), VERSION);

  while(1) {
    queue_wait(&que, &qel);

    //printf_P(PSTR("Event received src %d\n"), qel.source);
    switch (qel.source) {
      case EVENT_CMD:       sev_cmd_exec(1);
                            break;
      case EVENT_TIMER0:    printf("Timer 0 event\n"); break;
      case EVENT_TIMER1:    printf("Timer 1 event\n"); break;
      case EVENT_BUT_DOWN:  printf("Button pressed event\n");
                            ARD_LED_TOGGLE();
                            blink = 0;
                            break;
      case EVENT_BUT_UP:    printf("Button released event\n"); break;
      case EVENT_BUT_LONG:  printf("Button hold down event\n");
                            blink = 1;                                // start blinking
                            sev_timer_start_single(&eTimer3, 400);    // start single timeout
                            break;
      case EVENT_1S:        printf_P(PSTR("Software timer 1s\n")); break;
      case EVENT_2S:        printf_P(PSTR("Software timer 2s\n")); break;
      case EVENT_4S:        printf_P(PSTR("Software timer 4s\n"));
                            blink = 0;
                            break;
    }
  }
}
Beispiel #14
0
int main(void) {
	uint8_t app_index = 0;

	init_hw();

	// cycle through apps

	for(;;) {
		reset_hw();

		run_app(&apps[app_index]);

		reset_hw();

		if(app_direction > 0) {
			play_melody(up_mldy, ARRAY_SIZE(up_mldy), 4, 100);

			app_index++;

			if(apps[app_index].run == NULL) {
				app_index = 0;
			}
		} else {
			play_melody(down_mldy, ARRAY_SIZE(down_mldy), 4, 100);

			if(app_index == 0) {
				app_index = MAX_APPS - 1;
				while(apps[app_index].run == NULL) --app_index;
			} else {
				app_index--;
			}
		}
	}
}
Beispiel #15
0
static void melfas_touchkey_early_resume(struct early_suspend *h)
{
	set_touchkey_debug('R');
	printk(KERN_DEBUG "melfas_touchkey_early_resume\n");
	if (touchkey_enable < 0) {
		printk("---%s---touchkey_enable: %d\n", __FUNCTION__,
		       touchkey_enable);
		return;
	}
#ifndef CONFIG_S5PC110_DEMPSEY_BOARD
	gpio_direction_output(_3_GPIO_TOUCH_EN, 1);
#endif
#if !(defined(CONFIG_ARIES_NTT) || defined(CONFIG_S5PC110_DEMPSEY_BOARD))
	gpio_direction_output(_3_GPIO_TOUCH_CE, 1);
#endif
	init_hw();
	msleep(50);

	//clear interrupt
	if (readl(gpio_pend_mask_mem) & (0x1 << 1))
		writel(readl(gpio_pend_mask_mem) | (0x1 << 1),
		       gpio_pend_mask_mem);

	enable_irq(IRQ_TOUCH_INT);
	touchkey_enable = 1;

}
Beispiel #16
0
static ssize_t touch_version_read(struct device *dev,
				  struct device_attribute *attr, char *buf)
{
#if 0
	char data[3] = { 0, };
	int count;

	init_hw();
	if (get_touchkey_firmware(data) != 0) {
		i2c_touchkey_read(KEYCODE_REG, data, 3);
	}
	count = sprintf(buf, "0x%x\n", data[1]);

	printk(KERN_DEBUG "[TouchKey] touch_version_read 0x%x\n", data[1]);
	return count;
#else
	u8 data[3];
	int ret;

	printk(KERN_DEBUG "called %s \n", __func__);
	ret = i2c_touchkey_read(KEYCODE_REG, data, 3);
	printk(KERN_DEBUG "called %s data[1] =%d,data[2] = %d\n", __func__, data[1], data[2]);

	return sprintf(buf, "0x%x\n", data[1]);
#endif

}
static int __init touchkey_init(void)
{
	int ret = 0;
	int retry=10;
    char FW_VER, MODULE_VER;
	unsigned int bNeedToUpdateFirmware = 0;

		//touchkey_keycode[2] = KEY_ENTER;

	printk("melfas touchkey_init\n");
	
	ret = misc_register(&touchkey_update_device);
	if (ret) {
		printk("%s misc_register fail\n",__FUNCTION__);
	}

	if (device_create_file(touchkey_update_device.this_device, &dev_attr_touch_version) < 0)
	{
		printk("%s device_create_file fail dev_attr_touch_version\n",__FUNCTION__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_touch_version.attr.name);
	}
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_brightness) < 0)
	{
		printk("%s device_create_file fail dev_attr_touch_update\n",__FUNCTION__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_brightness.attr.name);
	}

	if (device_create_file(touchkey_update_device.this_device, &dev_attr_enable_disable) < 0)
	{
		printk("%s device_create_file fail dev_attr_touch_update\n",__FUNCTION__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_enable_disable.attr.name);
	}
	
	init_hw();

#if 0
	if (request_irq(IRQ_TOUCH_INT, touchkey_interrupt, 0, DEVICE_NAME, NULL)) {
                printk(KERN_ERR "%s Can't allocate irq ..\n", __FUNCTION__);
                return -EBUSY;
        }
#endif

	
	while(retry--)
	{
		if(mcsdl_download_binary_data())
		{
			break;
		}
		printk("%s F/W download fail\n",__FUNCTION__);
	}
	ret = i2c_add_driver(&touchkey_i2c_driver);
	
	if(ret)
	{
		printk("melfas touch keypad registration failed, module not inserted.ret= %d\n",ret);
	}
	return ret;
}
Beispiel #18
0
/**
 * write_i2c() - Write data to I2C client.
 * @dev: private data of I2C Driver
 *
 * This function writes data to I2C client
 */
static int write_i2c(struct nmk_i2c_dev *dev)
{
	u32 status = 0;
	u32 mcr;
	u32 irq_mask = 0;
	int timeout;

	mcr = load_i2c_mcr_reg(dev);

	writel(mcr, dev->virtbase + I2C_MCR);

	/* load the current CR value */
	writel(readl(dev->virtbase + I2C_CR) | DEFAULT_I2C_REG_CR,
			dev->virtbase + I2C_CR);

	/* enable the controller */
	i2c_set_bit(dev->virtbase + I2C_CR , I2C_CR_PE);

	init_completion(&dev->xfer_complete);

	/* enable interrupts by settings the masks */
	irq_mask = (I2C_IT_TXFNE | I2C_IT_TXFOVR |
			I2C_IT_MAL | I2C_IT_BERR);

	/*
	 * check if we want to transfer a single or multiple bytes, if so
	 * set the MTDWS bit (Master Transaction Done Without Stop)
	 * to start repeated start operation
	 */
	if (dev->stop)
		irq_mask |= I2C_IT_MTD;
	else
		irq_mask |= I2C_IT_MTDWS;

	irq_mask = I2C_CLEAR_ALL_INTS & IRQ_MASK(irq_mask);

	writel(readl(dev->virtbase + I2C_IMSCR) | irq_mask,
			dev->virtbase + I2C_IMSCR);

	timeout = wait_for_completion_interruptible_timeout(
		&dev->xfer_complete, msecs_to_jiffies(I2C_TIMEOUT_MS));

	if (timeout < 0) {
		dev_err(&dev->pdev->dev,
			"wait_for_completion_interruptible_timeout"
			"returned %d waiting for event\n", timeout);
		status = timeout;
	}

	if (timeout == 0) {
		/* controler has timedout, re-init the h/w */
		dev_err(&dev->pdev->dev, "controller timed out, re-init h/w\n");
		(void) init_hw(dev);
		status = -ETIMEDOUT;
	}

	return status;
}
Beispiel #19
0
static int __init touchkey_init(void)
{
	int ret = 0;
	int retry=10;

                #if 0
		touchkey_keycode[2] = KEY_ENTER;
                #endif

	printk("melfas touchkey_init\n");
	
	ret = misc_register(&touchkey_update_device);
	if (ret) {
		printk("%s misc_register fail\n",__FUNCTION__);
	}
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_touch_version) < 0)
	{
		printk("%s device_create_file fail dev_attr_touch_version\n",__FUNCTION__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_touch_version.attr.name);
	}
//touch_update sys fs removed
#if 0
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_touch_update) < 0)
	{
		printk("%s device_create_file fail dev_attr_touch_update\n",__FUNCTION__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_touch_update.attr.name);
	}
#endif
	if (device_create_file(touchkey_update_device.this_device, &dev_attr_brightness) < 0)
	{
		printk("%s device_create_file fail dev_attr_touch_update\n",__FUNCTION__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_brightness.attr.name);
	}

	if (device_create_file(touchkey_update_device.this_device, &dev_attr_enable_disable) < 0)
	{
		printk("%s device_create_file fail dev_attr_touch_update\n",__FUNCTION__);
		pr_err("Failed to create device file(%s)!\n", dev_attr_enable_disable.attr.name);
	}
	init_hw();
	
	while(retry--)
	{
		if(mcsdl_download_binary_data())
		{
			break;
		}
		printk("%s F/W download fail\n",__FUNCTION__);
	}
	ret = i2c_add_driver(&touchkey_i2c_driver);
	
	if(ret)
	{
		printk("melfas touch keypad registration failed, module not inserted.ret= %d\n",ret);
	}
	return ret;
}
Beispiel #20
0
void run_bootloader(){
	init_hw();

	led_flash_run_bootloader();

	//initialize link and run link update
	dstr("Link Start\n");
	boot_link_update((void*)boot_board_config.link_transport_driver);
}
Beispiel #21
0
 int main (void)
  {
  init_hw();
  LCD_init();
  SR_DAT_IN;
  while (1)
  	{
	uart_sendchar('A');
	uart_sendstr("0123456789abcdef");
 // 	dly_ms(40);
  	if (rcvd_flag)
  		{
  		rcvd_flag=0;
  		uart_sendstr("R:");
  		if (f_gsm_ok)
  			{
  			f_gsm_ok=0;
  			uart_sendstr("G_OK");
  			}
  		if (f_gsm_nc)
  			{
  			f_gsm_nc=0;
  			uart_sendstr("G_NC");
  			}
  		if (f_gsm_cr)
  			{
  			f_gsm_cr=0;
  			uart_sendstr("G_CR");
  			}
  		if (f_gsm_ring)
  			{
  			f_gsm_ring=0;
  			uart_sendstr("G_RI");
  			}
  		uart_sendstr("\r\n");
  		}


  	keys = read_keys();

  	if (keys==0x01) 		update_lcd("K1");
  	else if (keys==0x02) 	update_lcd("K2");
  	else if (keys==0x04) 	update_lcd("K3");
  	else if (keys==0x08) 	update_lcd("K4");
  	else if (keys==0x10) 	update_lcd("K5");
  	else if (keys==0x20) 	update_lcd("K6");
  	else if (keys==0x40) 	update_lcd("K7");
  	else if (keys==0x00) 	update_lcd("0123456789ABCDEF");
  	else update_lcd("Kx");
/*
	if (keys_handling(&key))
		{
		keys = key;
		}
*/
  	}
  }
static void melfas_touchkey_early_resume(struct early_suspend *h)
{

	init_hw();
	 //clear interrupt
    	if(readl(gpio_pend_mask_mem)&(0x1<<1))
        	writel(readl(gpio_pend_mask_mem)|(0x1<<1), gpio_pend_mask_mem);

	enable_irq(IRQ_TOUCH_INT);
}
Beispiel #23
0
void set_led_state (unsigned char state)
{
    if (!ftdi_ok)
        return;
    if (ftdi_write_data (&ctx, &state, 1) < 0) {
        init_hw ();
        if (ftdi_ok)
            ftdi_write_data (&ctx, &state, 1);
    }
}
Beispiel #24
0
//------------------------------------------------------------------------
int kmain ( void )
{
	init_hw();
	create_process(funcB, NULL, STACK_SIZE);
	create_process(funcA, NULL, STACK_SIZE);
	start_sched();
	ctx_switch();
	/* Pas atteignable vu nos 2 fonctions */
	return 0;
}
Beispiel #25
0
int main() {
  // initialize
  init_hw();
  init_layers();
  init_sticky();
  init_timer();

  // never return
  main_key_loop();
  return 0;
}
static ssize_t touch_version_read(struct device *dev, struct device_attribute *attr, char *buf)
{
	char data[3];
	int count;

	init_hw();
	get_touchkey_firmware(data);
	count = sprintf(buf,"%d\n", data[1]);
	
	return count;
}
Beispiel #27
0
void main(void)
{
	init_hw();
	sei();
	
	printf("Ready.\n");
	
	while(1)
	{
	}
}
Beispiel #28
0
static ssize_t touch_update_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t size)
{
	printk("touchkey firmware update \n");
	if(*buf == 'S')
	{
		INIT_WORK(&touch_update_work, touchkey_update_func);
		init_hw();
		queue_work(touchkey_wq, &touch_update_work);
	}
	return size;
}
Beispiel #29
0
/**
 * read_i2c() - Read from I2C client device
 * @dev: private data of I2C Driver
 *
 * This function reads from i2c client device when controller is in
 * master mode. There is a completion timeout. If there is no transfer
 * before timeout error is returned.
 */
static int read_i2c(struct nmk_i2c_dev *dev)
{
	u32 status = 0;
	u32 mcr;
	u32 irq_mask = 0;
	int timeout;

	mcr = load_i2c_mcr_reg(dev);
	writel(mcr, dev->virtbase + I2C_MCR);

	/* load the current CR value */
	writel(readl(dev->virtbase + I2C_CR) | DEFAULT_I2C_REG_CR,
			dev->virtbase + I2C_CR);

	/* enable the controller */
	i2c_set_bit(dev->virtbase + I2C_CR, I2C_CR_PE);

	init_completion(&dev->xfer_complete);

	/* enable interrupts by setting the mask */
	irq_mask = (I2C_IT_RXFNF | I2C_IT_RXFF |
			I2C_IT_MAL | I2C_IT_BERR);

	if (dev->stop)
		irq_mask |= I2C_IT_MTD;
	else
		irq_mask |= I2C_IT_MTDWS;

	irq_mask = I2C_CLEAR_ALL_INTS & IRQ_MASK(irq_mask);

	writel(readl(dev->virtbase + I2C_IMSCR) | irq_mask,
			dev->virtbase + I2C_IMSCR);

	timeout = wait_for_completion_interruptible_timeout(
		&dev->xfer_complete, msecs_to_jiffies(I2C_TIMEOUT_MS));

	if (timeout < 0) {
		dev_err(&dev->pdev->dev,
			"wait_for_completion_interruptible_timeout"
			"returned %d waiting for event\n", timeout);
		status = timeout;
	}

	if (timeout == 0) {
		/* controler has timedout, re-init the h/w */
		dev_err(&dev->pdev->dev, "controller timed out, re-init h/w\n");
		(void) init_hw(dev);
		status = -ETIMEDOUT;
	}

	return status;
}
Beispiel #30
0
/**
 * nmk_i2c_xfer() - I2C transfer function used by kernel framework
 * @i2c_adap: Adapter pointer to the controller
 * @msgs: Pointer to data to be written.
 * @num_msgs: Number of messages to be executed
 *
 * This is the function called by the generic kernel i2c_transfer()
 * or i2c_smbus...() API calls. Note that this code is protected by the
 * semaphore set in the kernel i2c_transfer() function.
 *
 * NOTE:
 * READ TRANSFER : We impose a restriction of the first message to be the
 * 		index message for any read transaction.
 * 		- a no index is coded as '0',
 * 		- 2byte big endian index is coded as '3'
 * 		!!! msg[0].buf holds the actual index.
 * 		This is compatible with generic messages of smbus emulator
 * 		that send a one byte index.
 * 		eg. a I2C transation to read 2 bytes from index 0
 *			idx = 0;
 *			msg[0].addr = client->addr;
 *			msg[0].flags = 0x0;
 *			msg[0].len = 1;
 *			msg[0].buf = &idx;
 *
 *			msg[1].addr = client->addr;
 *			msg[1].flags = I2C_M_RD;
 *			msg[1].len = 2;
 *			msg[1].buf = rd_buff
 *			i2c_transfer(adap, msg, 2);
 *
 * WRITE TRANSFER : The I2C standard interface interprets all data as payload.
 *		If you want to emulate an SMBUS write transaction put the
 *		index as first byte(or first and second) in the payload.
 *		eg. a I2C transation to write 2 bytes from index 1
 *			wr_buff[0] = 0x1;
 *			wr_buff[1] = 0x23;
 *			wr_buff[2] = 0x46;
 *			msg[0].flags = 0x0;
 *			msg[0].len = 3;
 *			msg[0].buf = wr_buff;
 *			i2c_transfer(adap, msg, 1);
 *
 * To read or write a block of data (multiple bytes) using SMBUS emulation
 * please use the i2c_smbus_read_i2c_block_data()
 * or i2c_smbus_write_i2c_block_data() API
 */
static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap,
		struct i2c_msg msgs[], int num_msgs)
{
	int status;
	int i;
	u32 cause;
	struct nmk_i2c_dev *dev = i2c_get_adapdata(i2c_adap);

	status = init_hw(dev);
	if (status)
		return status;

	clk_enable(dev->clk);

	/* setup the i2c controller */
	setup_i2c_controller(dev);

	for (i = 0; i < num_msgs; i++) {
		if (unlikely(msgs[i].flags & I2C_M_TEN)) {
			dev_err(&dev->pdev->dev, "10 bit addressing"
					"not supported\n");
			return -EINVAL;
		}
		dev->cli.slave_adr	= msgs[i].addr;
		dev->cli.buffer		= msgs[i].buf;
		dev->cli.count		= msgs[i].len;
		dev->stop = (i < (num_msgs - 1)) ? 0 : 1;
		dev->result = 0;

		if (msgs[i].flags & I2C_M_RD) {
			/* it is a read operation */
			dev->cli.operation = I2C_READ;
			status = read_i2c(dev);
		} else {
			/* write operation */
			dev->cli.operation = I2C_WRITE;
			status = write_i2c(dev);
		}
		if (status || (dev->result)) {
			/* get the abort cause */
			cause =	(readl(dev->virtbase + I2C_SR) >> 4) & 0x7;
			dev_err(&dev->pdev->dev, "error during I2C"
					"message xfer: %d\n", cause);
			dev_err(&dev->pdev->dev, "%s\n",
				cause >= ARRAY_SIZE(abort_causes)
				? "unknown reason" : abort_causes[cause]);
			clk_disable(dev->clk);
			return status;
		}
		udelay(I2C_DELAY);
	}