Changeset 0510cfd8 in rtems


Ignore:
Timestamp:
Nov 11, 2014, 11:41:58 AM (5 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
8100e71
Parents:
67ac69fc
git-author:
Sebastian Huber <sebastian.huber@…> (11/11/14 11:41:58)
git-committer:
Sebastian Huber <sebastian.huber@…> (11/20/14 09:30:17)
Message:

Add NXP PCA9548A 8-channel switch I2C driver

Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/dev/Makefile.am

    r67ac69fc r0510cfd8  
    1010include_dev_i2c_HEADERS += include/dev/i2c/gpio-nxp-pca9535.h
    1111include_dev_i2c_HEADERS += include/dev/i2c/i2c.h
     12include_dev_i2c_HEADERS += include/dev/i2c/switch-nxp-pca9548a.h
    1213
    1314include_linuxdir = $(includedir)/linux
     
    2324libdev_a_SOURCES += i2c/i2c-bus.c
    2425libdev_a_SOURCES += i2c/i2c-dev.c
     26libdev_a_SOURCES += i2c/switch-nxp-pca9548a.c
    2527
    2628include $(srcdir)/preinstall.am
  • cpukit/dev/preinstall.am

    r67ac69fc r0510cfd8  
    3636PREINSTALL_FILES += $(PROJECT_INCLUDE)/dev/i2c/i2c.h
    3737
     38$(PROJECT_INCLUDE)/dev/i2c/switch-nxp-pca9548a.h: include/dev/i2c/switch-nxp-pca9548a.h $(PROJECT_INCLUDE)/dev/i2c/$(dirstamp)
     39        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/dev/i2c/switch-nxp-pca9548a.h
     40PREINSTALL_FILES += $(PROJECT_INCLUDE)/dev/i2c/switch-nxp-pca9548a.h
     41
    3842$(PROJECT_INCLUDE)/linux/$(dirstamp):
    3943        @$(MKDIR_P) $(PROJECT_INCLUDE)/linux
  • testsuites/libtests/i2c01/init.c

    r67ac69fc r0510cfd8  
    2020#include <dev/i2c/eeprom.h>
    2121#include <dev/i2c/gpio-nxp-pca9535.h>
     22#include <dev/i2c/switch-nxp-pca9548a.h>
    2223
    2324#include <sys/ioctl.h>
     
    4243
    4344#define DEVICE_GPIO_NXP_PCA9535 (2UL << SPARE_ADDRESS_BITS)
     45
     46#define DEVICE_SWITCH_NXP_PCA9548A (3UL << SPARE_ADDRESS_BITS)
    4447
    4548#define EEPROM_SIZE 512
     
    7477
    7578typedef struct {
     79  test_device base;
     80  uint8_t control;
     81} test_device_switch_nxp_pca9548a;
     82
     83typedef struct {
    7684  i2c_bus base;
    7785  unsigned long clock;
    78   test_device *devices[3];
     86  test_device *devices[4];
    7987  test_device_simple_read_write simple_read_write;
    8088  test_device_gpio_nxp_pca9535 gpio_nxp_pca9535;
    8189  test_device_eeprom eeprom;
     90  test_device_switch_nxp_pca9548a switch_nxp_pca9548a;
    8291} test_bus;
    8392
     
    8796
    8897static const char eeprom_path[] = "/dev/i2c-0.eeprom-0";
     98
     99static const char switch_nxp_pca9548a_path[] =
     100  "/dev/i2c-0.switch-nxp-pca9548a-0";
    89101
    90102static void cyclic_inc(unsigned *val, unsigned cycle)
     
    218230}
    219231
     232static int test_switch_nxp_pca9548a_transfer(
     233  i2c_bus *bus,
     234  i2c_msg *msgs,
     235  uint32_t msg_count,
     236  test_device *base
     237)
     238{
     239  test_device_switch_nxp_pca9548a *dev = (test_device_switch_nxp_pca9548a *) base;
     240  uint32_t i;
     241
     242  for (i = 0; i < msg_count; ++i) {
     243    i2c_msg *msg = &msgs[i];
     244    int j;
     245
     246    if ((msg->flags & I2C_M_RD) != 0) {
     247      for (j = 0; j < msg->len; ++j) {
     248        msg->buf[j] = dev->control;
     249      }
     250    } else {
     251      for (j = 0; j < msg->len; ++j) {
     252        dev->control = msg->buf[j];
     253      }
     254    }
     255  }
     256
     257  return 0;
     258}
     259
    220260static int test_transfer(i2c_bus *base, i2c_msg *msgs, uint32_t msg_count)
    221261{
     
    439479}
    440480
     481static void test_switch_nxp_pca9548a(void)
     482{
     483  int rv;
     484  int fd;
     485  uint8_t val;
     486
     487  rv = i2c_dev_register_switch_nxp_pca9548a(
     488    &bus_path[0],
     489    &switch_nxp_pca9548a_path[0],
     490    DEVICE_SWITCH_NXP_PCA9548A
     491  );
     492  rtems_test_assert(rv == 0);
     493
     494  fd = open(&switch_nxp_pca9548a_path[0], O_RDWR);
     495  rtems_test_assert(fd >= 0);
     496
     497  rv = switch_nxp_pca9548a_get_control(fd, &val);
     498  rtems_test_assert(rv == 0);
     499  rtems_test_assert(val == 0);
     500
     501  rv = switch_nxp_pca9548a_set_control(fd, 0xa5);
     502  rtems_test_assert(rv == 0);
     503
     504  rv = switch_nxp_pca9548a_get_control(fd, &val);
     505  rtems_test_assert(rv == 0);
     506  rtems_test_assert(val == 0xa5);
     507
     508  rv = close(fd);
     509  rtems_test_assert(rv == 0);
     510
     511  rv = unlink(&switch_nxp_pca9548a_path[0]);
     512  rtems_test_assert(rv == 0);
     513}
     514
    441515static void test(void)
    442516{
     
    466540  bus->devices[2] = &bus->gpio_nxp_pca9535.base;
    467541
     542  bus->switch_nxp_pca9548a.base.transfer = test_switch_nxp_pca9548a_transfer;
     543  bus->devices[3] = &bus->switch_nxp_pca9548a.base;
     544
    468545  rv = i2c_bus_register(&bus->base, &bus_path[0]);
    469546  rtems_test_assert(rv == 0);
     
    534611  test_eeprom();
    535612  test_gpio_nxp_pca9535();
     613  test_switch_nxp_pca9548a();
    536614
    537615  rv = close(fd);
Note: See TracChangeset for help on using the changeset viewer.