Автор работы: Пользователь скрыл имя, 17 Января 2012 в 14:29, курсовая работа
В настоящее время только Philips производит более 150 наименований I2C-совместимых устройств, функционально предназначенных работы в электронном оборудовании различного назначения. В их числе ИС памяти, видеопроцессоров и модулей обработки аудио- и видео-сигналов, АЦП и ЦАП, драйверы ЖК-индикаторов, процессоры со встоенным аппаратным контроллером I2C шины и многое другое.
Введение 5
1 Шина управления I2C 10
2 Исследование драйвера 14
Заключение 15
Список использованных источников 16
597 "len=%d\n", ret, msgs[ret].flags & I2C_M_RD ?
598 'R' : 'W', msgs[ret].addr, msgs[ret].len);
599 }
600 #endif
601
602 down(&adap->bus_lock);
603
ret = adap->algo->master_xfer(adap,m
604 up(&adap->bus_lock);
605
606 return ret;
607 } else {
608 dev_dbg(&adap->dev, "I2C level transfers not supported\n");
609 return -ENOSYS;
610 }
611 }
612
613 int i2c_master_send(struct i2c_client *client,const char *buf ,int count)
614 {
615 int ret;
616 struct i2c_adapter *adap=client->adapter;
617 struct i2c_msg msg;
618
619 msg.addr = client->addr;
620 msg.flags = client->flags & I2C_M_TEN;
621 msg.len = count;
622 msg.buf = (char *)buf;
623
624 ret = i2c_transfer(adap, &msg, 1);
625
626 /* If everything went ok (i.e. 1 msg transmitted), return #bytes
627 transmitted, else error code. */
628 return (ret == 1) ? count : ret;
629 }
630
631 int i2c_master_recv(struct i2c_client *client, char *buf ,int count)
632 {
633 struct i2c_adapter *adap=client->adapter;
634 struct i2c_msg msg;
635 int ret;
636
637 msg.addr = client->addr;
638 msg.flags = client->flags & I2C_M_TEN;
639 msg.flags |= I2C_M_RD;
640 msg.len = count;
641 msg.buf = buf;
642
643 ret = i2c_transfer(adap, &msg, 1);
644
645 /* If everything went ok (i.e. 1 msg transmitted), return #bytes
646 transmitted, else error code. */
647 return (ret == 1) ? count : ret;
648 }
649
650
651 int i2c_control(struct i2c_client *client,
652 unsigned int cmd, unsigned long arg)
653 {
654 int ret = 0;
655 struct i2c_adapter *adap = client->adapter;
656
657 dev_dbg(&client->adapter->dev, "i2c ioctl, cmd: 0x%x, arg: %#lx\n", cmd,
658 arg);
659 switch (cmd) {
660 case I2C_RETRIES:
661 adap->retries = arg;
662 break;
663 case I2C_TIMEOUT:
664 adap->timeout = arg;
665 break;
666 default:
667
if (adap->algo->algo_control!=NUL
668
ret = adap->algo->algo_control(adap,
669 }
670 return ret;
671 }
672
673 /* ------------------------------
674 * the i2c address scanning function
675 * Will not work for 10-bit addresses!
676 * ------------------------------
677 */
678 static int i2c_probe_address(struct i2c_adapter *adapter, int addr, int
679 kind,
680 int (*found_proc) (struct i2c_adapter *, int, int))
681 {
682 int err;
683
684 /* Make sure the address is valid */
685 if (addr < 0x03 || addr > 0x77) {
686 dev_warn(&adapter->dev, "Invalid probe address 0x%02x\n",
687 addr);
688 return -EINVAL;
689 }
690
691 /* Skip if already in use */
692 if (i2c_check_addr(adapter, addr))
693 return 0;
694
695 /* Make sure there is something at this address, unless forced */
696 if (kind < 0) {
697 if (i2c_smbus_xfer(adapter, addr, 0, 0, 0,
698 I2C_SMBUS_QUICK, NULL) < 0)
699 return 0;
700
701 /* prevent 24RF08 corruption */
702 if ((addr & ~0x0f) == 0x50)
703 i2c_smbus_xfer(adapter, addr, 0, 0, 0,
704 I2C_SMBUS_QUICK, NULL);
705 }
706
707 /* Finally call the custom detection function */
708 err = found_proc(adapter, addr, kind);
709
710 /* -ENODEV can be returned if there is a chip at the given address
711 but it isn't supported by this chip driver. We catch it here as
712 this isn't an error. */
713 return (err == -ENODEV) ? 0 : err;
714 }
715
716 int i2c_probe(struct i2c_adapter *adapter,
717 struct i2c_client_address_data *address_data,
718 int (*found_proc) (struct i2c_adapter *, int, int))
719 {
720 int i, err;
721 int adap_id = i2c_adapter_id(adapter);
722
723 /* Force entries are done first, and are not affected by ignore
724 entries */
725 if (address_data->forces) {
726 unsigned short **forces = address_data->forces;
727 int kind;
728
729 for (kind = 0; forces[kind]; kind++) {
730 for (i = 0; forces[kind][i] != I2C_CLIENT_END;
731 i += 2) {
732 if (forces[kind][i] == adap_id
733 || forces[kind][i] == ANY_I2C_BUS) {
734 dev_dbg(&adapter->dev, "found force "
735 "parameter for adapter %d, "
736 "addr 0x%02x, kind %d\n",
737 adap_id, forces[kind][i + 1],
738 kind);
739 err = i2c_probe_address(adapter,
740 forces[kind][i + 1],
741 kind, found_proc);
742 if (err)
743 return err;
744 }
745 }
746 }
747 }
748
749 /* Stop here if we can't use SMBUS_QUICK */
Информация о работе Исследование драйвера ядра Linux для шины I2C