| | 98 | Limitations |
|---|
| | 99 | ----------- |
|---|
| | 100 | |
|---|
| | 101 | Extending the adapter and algorithm structures in this way is quite safe. |
|---|
| | 102 | They are only allocated on places where the code knows that they are |
|---|
| | 103 | 'special'. Extending the driver or client structures depending on a |
|---|
| | 104 | specific adapter/algorithm type is *very* *dangerous*. A driver/client |
|---|
| | 105 | module would need to be aware of every special adapter/algorithm in |
|---|
| | 106 | order to allocate itself! For the ISA bus, it has to be aware of this |
|---|
| | 107 | anyway, so it is safe to do; on other places, think twice first! |
|---|
| | 108 | |
|---|
| 124 | | |
|---|
| 125 | | sensor.o |
|---|
| 126 | | Main sensors handling |
|---|
| 127 | | Unites SMBus adapters and ISA adapters. |
|---|
| 128 | | |
|---|
| 129 | | isa.o |
|---|
| 130 | | Implements the ISA adapter driver for sensor.o. This may prove to be so |
|---|
| 131 | | closely integrated that it can better be made part of sensor.o |
|---|
| 132 | | |
|---|
| | 132 | We may need a sensor.o module, to act as a central point for sensor |
|---|
| | 133 | modules. At this moment, it seems not really necessary, but this may |
|---|
| | 134 | change. |
|---|
| | 135 | |
|---|
| | 136 | We will need an enhanced i2c-dev.o module, to add SMBus access to I2C |
|---|
| | 137 | /dev entries. |
|---|
| | 138 | |
|---|
| | 139 | |
|---|
| | 140 | isa.o |
|---|
| | 141 | ISA bus handling. |
|---|
| | 142 | Encapsulates ISA bus access within the i2c structures. |
|---|
| | 143 | Unites I2C adapters and the ISA bus. |
|---|
| | 144 | Defines variables isa_algorithm and isa_adapter. |
|---|
| 320 | | There are several other functions, to register things for example, that |
|---|
| 321 | | are less important to us. |
|---|
| | 338 | Administration functions |
|---|
| | 339 | ------------------------ |
|---|
| | 340 | |
|---|
| | 341 | int i2c_add_algorithm(struct i2c_algorithm *); |
|---|
| | 342 | int i2c_del_algorithm(struct i2c_algorithm *); |
|---|
| | 343 | |
|---|
| | 344 | The i2c_{add,del}_algorithm functions must be called whenever a new module |
|---|
| | 345 | is inserted with this driver in it, by the module initialization function. |
|---|
| | 346 | |
|---|
| | 347 | |
|---|
| | 348 | int i2c_add_adapter(struct i2c_adapter *); |
|---|
| | 349 | int i2c_del_adapter(struct i2c_adapter *); |
|---|
| | 350 | |
|---|
| | 351 | The i2c_{add,del}_adapter functions must be called if you have detected |
|---|
| | 352 | a specific bus. It triggers driver->attach_adapter (add, for each driver |
|---|
| | 353 | present) or driver->detach_client (del, for each registered client on |
|---|
| | 354 | this adapter). |
|---|
| | 355 | |
|---|
| | 356 | |
|---|
| | 357 | int i2c_add_driver(struct i2c_driver *); |
|---|
| | 358 | int i2c_del_driver(struct i2c_driver *); |
|---|
| | 359 | |
|---|
| | 360 | The i2c_{add,del}_driver functions must be called whenever a new module is |
|---|
| | 361 | inserted with a chip driver in it, by the module initialization function. |
|---|
| | 362 | |
|---|
| | 363 | |
|---|
| | 364 | int i2c_attach_client(struct i2c_client *); |
|---|
| | 365 | int i2c_detach_client(struct i2c_client *); |
|---|
| | 366 | |
|---|
| | 367 | The i2c_{attach,detach}_client functions must be called if you have detected |
|---|
| | 368 | a single chip. |
|---|
| 401 | | There will be specific SMBus registration functions too, like the i2c |
|---|
| 402 | | ones. |
|---|
| 403 | | |
|---|
| 404 | | |
|---|
| 405 | | Module sensors.o |
|---|
| 406 | | ================ |
|---|
| 407 | | |
|---|
| 408 | | This module acts as a coordinations point between specific sensor modules |
|---|
| 409 | | (which each support a certain kind of sensor). We need this module to unite |
|---|
| 410 | | SMBus access and ISA access. |
|---|
| 411 | | |
|---|
| 412 | | |
|---|
| 413 | | A driver or adapter |
|---|
| 414 | | ------------------- |
|---|
| 415 | | |
|---|
| 416 | | We will not need to extend smbus_driver or smbus_adapter. This means that |
|---|
| 417 | | struct sensor_driver is exactly the same as struct smbus_driver, and struct |
|---|
| 418 | | sensor_adapter is the same as struct smbus_adapter. We *will* define the |
|---|
| 419 | | sensor_* variants, and use them within this module, so it should be easy to |
|---|
| 420 | | extend them after all. |
|---|
| 421 | | |
|---|
| 422 | | Note that a driver can be for a chip on either the ISA bus or the |
|---|
| 423 | | I2C/SMBus. If a specific chip can be on both, you must check variable |
|---|
| 424 | | client->adapter->algorithm->on_isa to determine which bus you need to access. |
|---|
| | 451 | There are specific SMBus registration functions too, like the i2c ones. |
|---|
| | 452 | They are fully compatiable with each other; just substitute 'smbus' for |
|---|
| | 453 | 'i2c' everywhere in the i2c description. |
|---|
| | 454 | |
|---|
| | 455 | int i2c_is_smbus_client(struct i2c_client *); |
|---|
| | 456 | int i2c_is_smbus_adapter(struct i2c_adapter *); |
|---|
| | 457 | |
|---|
| | 458 | Decide whether this client, or adapter, is (on) a non-I2C SMBus. Usually |
|---|
| | 459 | not needed, but it is nice anyway to be able to decide this. |
|---|
| | 460 | |
|---|
| | 461 | |
|---|
| | 462 | Module isa.o |
|---|
| | 463 | ============ |
|---|
| | 464 | |
|---|
| | 465 | This module implements a new algorithm and a specific adapter for the |
|---|
| | 466 | (single) ISA bus in your computer. This makes writing drivers for chips |
|---|
| | 467 | that can be both on ISA and SMBus much easier. |
|---|
| | 468 | |
|---|
| | 469 | Note that this module does *not* in any way depend on smbus.o (previous |
|---|
| | 470 | versions of this document still assumed it would be build upon it; this |
|---|
| | 471 | is no longer true). |
|---|
| | 472 | |
|---|
| | 473 | |
|---|
| | 474 | A driver, adapter or algorithm |
|---|
| | 475 | ------------------------------ |
|---|
| | 476 | |
|---|
| | 477 | We will not need to extend i2c_driver, i2c_adapter or i2c_algorithm. This |
|---|
| | 478 | means that struct isa_driver is exactly the same as struct i2c_driver, |
|---|
| | 479 | struct isa_adapter is the same as struct i2c_adapter and struct isa_algorithm |
|---|
| | 480 | is the same as struct isa_driver. We *will* define the isa_* variants, and |
|---|
| | 481 | use them within this module, so it should be easy to extend them after all. |
|---|
| 447 | | full_address: The full client address. ISA addresses and 10-bit SMBus |
|---|
| 448 | | addresses do not fit in the i2c-compatible addr field, so we needed |
|---|
| 449 | | a new field. |
|---|
| 450 | | |
|---|
| 451 | | |
|---|
| 452 | | |
|---|
| 453 | | An algorithm |
|---|
| 454 | | ------------ |
|---|
| 455 | | |
|---|
| 456 | | struct sensor_algorithm { |
|---|
| 457 | | char name[32]; |
|---|
| 458 | | unsigned int id; |
|---|
| 459 | | int (* master_xfer) (struct sensor_adapter *adap, struct smbus_msg msgs[], |
|---|
| 460 | | int num); |
|---|
| 461 | | int (* slave_send) (struct sensor_adapter *,char *, int); |
|---|
| 462 | | int (* slave_recv) (struct sensor_adapter *,char *, int); |
|---|
| 463 | | int (* algo_control) (struct sensor_adapter *, unsigned int, unsigned long); |
|---|
| 464 | | int (* client_register) (struct sensor_client *); |
|---|
| 465 | | int (* client_unregister) (struct sensor_client *); |
|---|
| 466 | | |
|---|
| 467 | | int (* smbus_access) (struct sensor_adapter *, __u8 addr, char read_write, |
|---|
| 468 | | __u8 command, int size, union smbus_data * data); |
|---|
| 469 | | int isa_bus; |
|---|
| 470 | | } |
|---|
| 471 | | |
|---|
| 472 | | A description of the above struct: |
|---|
| 473 | | isa_bus: 0 if this structure describes SMBus access, 1 if it describes |
|---|
| 474 | | ISA access. |
|---|
| 475 | | |
|---|
| 476 | | In case of the ISA bus, the master_xfer, slave_send, slave_recv and |
|---|
| 477 | | smbus_access hooks will be NULL, because these functions make no sense. |
|---|
| 478 | | It is regrettably not easy to create an access abstraction in which both |
|---|
| 479 | | ISA bus access and SMBus access are united. See below for examples how |
|---|
| 480 | | you can solve this problem. |
|---|
| | 504 | isa_addr: ISA addresses do not fit in the i2c-compatible addr field, so |
|---|
| | 505 | we needed a new field. |
|---|
| 490 | | int is_on_isa (struct sensor_client *); |
|---|
| 491 | | |
|---|
| 492 | | This function tells us whether a specific client is connected to the ISA |
|---|
| 493 | | bus or to the SMBus. This is important, because it determines whether we |
|---|
| 494 | | can use the SMBus access routines. |
|---|
| | 521 | int i2c_is_isa_client(struct i2c_client *); |
|---|
| | 522 | int i2c_is_isa_adapter(struct i2c_adapter *); |
|---|
| | 523 | |
|---|
| | 524 | Decide whether this client, or adapter, is (on) the ISA bus. This is |
|---|
| | 525 | important, because it determines whether we can use the SMBus access |
|---|
| | 526 | routines. |
|---|
| 498 | | u8 lm78_read_value(struct sensor_client *client, u8 register) |
|---|
| | 530 | /* The SMBus locks itself, but ISA access must be locked explicitely! |
|---|
| | 531 | We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks, |
|---|
| | 532 | would slow down the LM78 access and should not be necessary. |
|---|
| | 533 | There are some ugly typecasts here, but the good new is - they should |
|---|
| | 534 | nowhere else be necessary! */ |
|---|
| | 535 | int lm78_read_value(struct i2c_client *client, u8 reg) |
|---|
| 500 | | if (is_on_isa(client)) { |
|---|
| 501 | | /* Ignore the check for LM78_BUSY to keep things simple here; the best |
|---|
| 502 | | place to put this semaphore struct would be in client->data */ |
|---|
| 503 | | outb_p(register,client->address + LM78_ADDR_REG_OFFSET); |
|---|
| 504 | | return inb_p(client->address + LM78_DATA_REG_OFFSET); |
|---|
| 505 | | } else |
|---|
| 506 | | return smbus_read_byte_data(client,register); |
|---|
| 507 | | /* This is a standard function based on smbus_access */ |
|---|
| 508 | | } |
|---|
| 509 | | |
|---|
| 510 | | |
|---|
| | 537 | int res; |
|---|
| | 538 | if (i2c_is_isa_client(client)) { |
|---|
| | 539 | down((struct semaphore *) (client->data)); |
|---|
| | 540 | outb_p(reg,(((struct isa_client *) client)->isa_addr) + |
|---|
| | 541 | LM78_ADDR_REG_OFFSET); |
|---|
| | 542 | res = inb_p((((struct isa_client *) client)->isa_addr) + |
|---|
| | 543 | LM78_DATA_REG_OFFSET); |
|---|
| | 544 | up((struct semaphore *) (client->data)); |
|---|
| | 545 | return res; |
|---|
| | 546 | } else |
|---|
| | 547 | return smbus_read_byte_data(client->adapter,client->addr, reg); |
|---|
| | 548 | } |
|---|