2019-08-16 15:40:59 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* boards/arm/samv7/same70-xplained/src/sam_at24config.c
|
2015-11-18 20:54:57 +01:00
|
|
|
*
|
2021-03-17 18:14:12 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2015-11-18 20:54:57 +01:00
|
|
|
*
|
2021-03-17 18:14:12 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-11-18 20:54:57 +01:00
|
|
|
*
|
2021-03-17 18:14:12 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2015-11-18 20:54:57 +01:00
|
|
|
*
|
2019-08-16 15:40:59 +02:00
|
|
|
****************************************************************************/
|
2015-11-18 20:54:57 +01:00
|
|
|
|
2019-08-16 15:40:59 +02:00
|
|
|
/****************************************************************************
|
2015-11-18 20:54:57 +01:00
|
|
|
* Included Files
|
2019-08-16 15:40:59 +02:00
|
|
|
****************************************************************************/
|
2015-11-18 20:54:57 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2016-07-21 21:34:54 +02:00
|
|
|
#include <nuttx/mtd/configdata.h>
|
2015-11-18 20:54:57 +01:00
|
|
|
#include <nuttx/mtd/mtd.h>
|
|
|
|
#include <nuttx/fs/ioctl.h>
|
|
|
|
|
|
|
|
#include "sam_twihs.h"
|
|
|
|
#include "same70-xplained.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_MTDCONFIG
|
|
|
|
|
2019-08-16 15:40:59 +02:00
|
|
|
/****************************************************************************
|
2015-11-18 20:54:57 +01:00
|
|
|
* Public Functions
|
2019-08-16 15:40:59 +02:00
|
|
|
****************************************************************************/
|
2015-11-18 20:54:57 +01:00
|
|
|
|
2019-08-16 15:40:59 +02:00
|
|
|
/****************************************************************************
|
2015-11-18 20:54:57 +01:00
|
|
|
* Name: sam_at24config
|
|
|
|
*
|
|
|
|
* Description:
|
2019-08-16 15:40:59 +02:00
|
|
|
* Create an AT24xx-based MTD configuration device for storage device
|
|
|
|
* configuration information.
|
2015-11-18 20:54:57 +01:00
|
|
|
*
|
2019-08-16 15:40:59 +02:00
|
|
|
****************************************************************************/
|
2015-11-18 20:54:57 +01:00
|
|
|
|
|
|
|
int sam_at24config(void)
|
|
|
|
{
|
2016-01-30 15:35:50 +01:00
|
|
|
struct i2c_master_s *i2c;
|
2015-11-18 20:54:57 +01:00
|
|
|
struct mtd_dev_s *at24;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Get an instance of the TWI0 interface */
|
|
|
|
|
2016-02-02 19:25:14 +01:00
|
|
|
i2c = sam_i2cbus_initialize(0);
|
2015-11-18 20:54:57 +01:00
|
|
|
if (!i2c)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Failed to initialize TWI0\n");
|
2015-11-18 20:54:57 +01:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the AT24 driver */
|
|
|
|
|
|
|
|
at24 = at24c_initialize(i2c);
|
|
|
|
if (!at24)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Failed to initialize the AT24 driver\n");
|
2020-01-02 17:49:34 +01:00
|
|
|
sam_i2cbus_uninitialize(i2c);
|
2015-11-18 20:54:57 +01:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure that the AT24 is in normal memory access mode */
|
|
|
|
|
|
|
|
ret = at24->ioctl(at24, MTDIOC_EXTENDED, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: AT24 ioctl(MTDIOC_EXTENDED) failed: %d\n", ret);
|
2015-11-18 20:54:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Bind the instance of an MTD device to the /dev/config device. */
|
|
|
|
|
|
|
|
ret = mtdconfig_register(at24);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Failed to bind AT24 driver to the MTD config device\n");
|
2020-01-02 17:49:34 +01:00
|
|
|
sam_i2cbus_uninitialize(i2c);
|
2015-11-18 20:54:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_MTDCONFIG */
|